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/HStorageMap.hxx"
27 : #include <osl/diagnose.h>
28 :
29 :
30 : using namespace ::com::sun::star::container;
31 : using namespace ::com::sun::star::uno;
32 : using namespace ::com::sun::star::embed;
33 : using namespace ::com::sun::star::io;
34 : using namespace ::com::sun::star::lang;
35 : using namespace ::connectivity::hsqldb;
36 :
37 : /*
38 : * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
39 : * Method: isStreamElement
40 : * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
41 : */
42 380 : extern "C" SAL_JNI_EXPORT jboolean JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement
43 : (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name)
44 : {
45 380 : TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key));
46 380 : if ( aStoragePair.first.first.is() )
47 : {
48 : try
49 : {
50 380 : OUString sName = StorageContainer::jstring2ustring(env,name);
51 : try
52 : {
53 380 : OUString sOldName = StorageContainer::removeOldURLPrefix(sName);
54 380 : if ( aStoragePair.first.first->isStreamElement(sOldName) )
55 : {
56 : try
57 : {
58 0 : aStoragePair.first.first->renameElement(sOldName,StorageContainer::removeURLPrefix(sName,aStoragePair.first.second));
59 : }
60 0 : catch(const Exception&)
61 : {
62 : }
63 380 : }
64 : }
65 380 : catch(const NoSuchElementException&)
66 : {
67 : }
68 0 : catch(const IllegalArgumentException&)
69 : {
70 : }
71 561 : return aStoragePair.first.first->isStreamElement(StorageContainer::removeURLPrefix(sName,aStoragePair.first.second));
72 : }
73 181 : catch(const NoSuchElementException&)
74 : {
75 : }
76 0 : catch(const Exception& e)
77 : {
78 : OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement");
79 0 : if (env->ExceptionCheck())
80 0 : env->ExceptionClear();
81 0 : OString cstr( OUStringToOString(e.Message, RTL_TEXTENCODING_JAVA_UTF8 ) );
82 0 : OSL_TRACE( __FILE__": forwarding Exception: %s", cstr.getStr() );
83 : }
84 : }
85 181 : return JNI_FALSE;
86 : }
87 :
88 :
89 : /*
90 : * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
91 : * Method: removeElement
92 : * Signature: (Ljava/lang/String;Ljava/lang/String;)V
93 : */
94 110 : extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement
95 : (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name)
96 : {
97 : #ifdef HSQLDB_DBG
98 : {
99 : OUString sKey = StorageContainer::jstring2ustring(env,key);
100 : OUString sName = StorageContainer::jstring2ustring(env,name);
101 : }
102 : #endif
103 110 : TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key));
104 110 : if ( aStoragePair.first.first.is() )
105 : {
106 : try
107 : {
108 134 : aStoragePair.first.first->removeElement(StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,name),aStoragePair.first.second));
109 : }
110 48 : catch(const NoSuchElementException&)
111 : {
112 24 : if (env->ExceptionCheck())
113 0 : env->ExceptionClear();
114 : }
115 0 : catch(const Exception& e)
116 : {
117 : OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement");
118 0 : StorageContainer::throwJavaException(e,env);
119 : }
120 110 : }
121 110 : }
122 :
123 :
124 : /*
125 : * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
126 : * Method: renameElement
127 : * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
128 : */
129 87 : extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement
130 : (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring oldname, jstring newname)
131 : {
132 : #ifdef HSQLDB_DBG
133 : {
134 : OUString sKey = StorageContainer::jstring2ustring(env,key);
135 : OUString sNewName = StorageContainer::jstring2ustring(env,newname);
136 : OUString sOldName = StorageContainer::jstring2ustring(env,oldname);
137 : }
138 : #endif
139 87 : TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key));
140 87 : if ( aStoragePair.first.first.is() )
141 : {
142 : try
143 : {
144 87 : aStoragePair.first.first->renameElement(
145 : StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,oldname),aStoragePair.first.second),
146 : StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second)
147 87 : );
148 : #ifdef HSQLDB_DBG
149 : {
150 : OUString sNewName = StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second);
151 : OSL_ENSURE(aStoragePair.first.first->isStreamElement(sNewName),"Stream could not be renamed");
152 : }
153 : #endif
154 : }
155 0 : catch(const NoSuchElementException&)
156 : {
157 : }
158 0 : catch(const Exception& e)
159 : {
160 : OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement");
161 0 : StorageContainer::throwJavaException(e,env);
162 : }
163 87 : }
164 87 : }
165 :
166 :
167 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|