Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
22 : #include <config.h>
23 : #endif
24 : #include <com/sun/star/container/XNameAccess.hpp>
25 : #include <com/sun/star/embed/XStorage.hpp>
26 : #include "hsqldb/StorageFileAccess.h"
27 : #include "hsqldb/HStorageMap.hxx"
28 :
29 :
30 :
31 : using namespace ::com::sun::star::container;
32 : using namespace ::com::sun::star::uno;
33 : using namespace ::com::sun::star::embed;
34 : using namespace ::com::sun::star::io;
35 : using namespace ::com::sun::star::lang;
36 : using namespace ::connectivity::hsqldb;
37 :
38 : /*
39 : * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
40 : * Method: isStreamElement
41 : * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
42 : */
43 0 : SAL_JNI_EXPORT jboolean JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement
44 : (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name)
45 : {
46 0 : TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key));
47 0 : if ( aStoragePair.first.first.is() )
48 : {
49 : try
50 : {
51 0 : OUString sName = StorageContainer::jstring2ustring(env,name);
52 : try
53 : {
54 0 : OUString sOldName = StorageContainer::removeOldURLPrefix(sName);
55 0 : if ( aStoragePair.first.first->isStreamElement(sOldName) )
56 : {
57 : try
58 : {
59 0 : aStoragePair.first.first->renameElement(sOldName,StorageContainer::removeURLPrefix(sName,aStoragePair.first.second));
60 : }
61 0 : catch(const Exception&)
62 : {
63 : }
64 0 : }
65 : }
66 0 : catch(const NoSuchElementException&)
67 : {
68 : }
69 0 : catch(const IllegalArgumentException&)
70 : {
71 : }
72 0 : return aStoragePair.first.first->isStreamElement(StorageContainer::removeURLPrefix(sName,aStoragePair.first.second));
73 : }
74 0 : catch(const NoSuchElementException&)
75 : {
76 : }
77 0 : catch(const Exception& e)
78 : {
79 : OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement");
80 0 : if (JNI_FALSE != env->ExceptionCheck())
81 0 : env->ExceptionClear();
82 0 : OString cstr( OUStringToOString(e.Message, RTL_TEXTENCODING_JAVA_UTF8 ) );
83 0 : OSL_TRACE( __FILE__": forwarding Exception: %s", cstr.getStr() );
84 : }
85 : }
86 0 : return JNI_FALSE;
87 : }
88 :
89 :
90 : /*
91 : * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
92 : * Method: removeElement
93 : * Signature: (Ljava/lang/String;Ljava/lang/String;)V
94 : */
95 0 : SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement
96 : (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name)
97 : {
98 : #ifdef HSQLDB_DBG
99 : {
100 : OUString sKey = StorageContainer::jstring2ustring(env,key);
101 : OUString sName = StorageContainer::jstring2ustring(env,name);
102 : }
103 : #endif
104 0 : TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key));
105 0 : if ( aStoragePair.first.first.is() )
106 : {
107 : try
108 : {
109 0 : aStoragePair.first.first->removeElement(StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,name),aStoragePair.first.second));
110 : }
111 0 : catch(const NoSuchElementException&)
112 : {
113 0 : if (JNI_FALSE != env->ExceptionCheck())
114 0 : env->ExceptionClear();
115 : }
116 0 : catch(const Exception& e)
117 : {
118 : OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement");
119 0 : StorageContainer::throwJavaException(e,env);
120 : }
121 0 : }
122 0 : }
123 :
124 :
125 : /*
126 : * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
127 : * Method: renameElement
128 : * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
129 : */
130 0 : SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement
131 : (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring oldname, jstring newname)
132 : {
133 : #ifdef HSQLDB_DBG
134 : {
135 : OUString sKey = StorageContainer::jstring2ustring(env,key);
136 : OUString sNewName = StorageContainer::jstring2ustring(env,newname);
137 : OUString sOldName = StorageContainer::jstring2ustring(env,oldname);
138 : }
139 : #endif
140 0 : TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key));
141 0 : if ( aStoragePair.first.first.is() )
142 : {
143 : try
144 : {
145 0 : aStoragePair.first.first->renameElement(
146 : StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,oldname),aStoragePair.first.second),
147 : StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second)
148 0 : );
149 : #ifdef HSQLDB_DBG
150 : {
151 : OUString sNewName = StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second);
152 : OSL_ENSURE(aStoragePair.first.first->isStreamElement(sNewName),"Stream could not be renamed");
153 : }
154 : #endif
155 : }
156 0 : catch(const NoSuchElementException&)
157 : {
158 : }
159 0 : catch(const Exception& e)
160 : {
161 : OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement");
162 0 : StorageContainer::throwJavaException(e,env);
163 : }
164 0 : }
165 0 : }
166 :
167 :
168 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|