1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: StorageFileAccess.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H
37 #include <com/sun/star/container/XNameAccess.hpp>
38 #include <com/sun/star/embed/XStorage.hpp>
39 #include "hsqldb/StorageFileAccess.h"
40 #include "hsqldb/HStorageMap.hxx"
42 #include <rtl/logfile.hxx>
44 using namespace ::com::sun::star::container
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::embed
;
47 using namespace ::com::sun::star::io
;
48 using namespace ::com::sun::star::lang
;
49 using namespace ::connectivity::hsqldb
;
51 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
52 /*****************************************************************************/
53 /* exception macros */
55 #define ThrowException(env, type, msg) { \
56 env->ThrowNew(env->FindClass(type), msg); }
59 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
60 * Method: isStreamElement
61 * Signature: (Ljava/lang/String;Ljava/lang/String;)Z
63 SAL_DLLPUBLIC_EXPORT jboolean JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement
64 (JNIEnv
* env
, jobject
/*obj_this*/,jstring key
, jstring name
)
66 TStorages::mapped_type aStoragePair
= StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env
,key
));
67 if ( aStoragePair
.first
.first
.is() )
71 ::rtl::OUString sName
= StorageContainer::jstring2ustring(env
,name
);
74 ::rtl::OUString sOldName
= StorageContainer::removeOldURLPrefix(sName
);
75 if ( aStoragePair
.first
.first
->isStreamElement(sOldName
) )
79 aStoragePair
.first
.first
->renameElement(sOldName
,StorageContainer::removeURLPrefix(sName
,aStoragePair
.first
.second
));
86 catch(NoSuchElementException
&)
89 return aStoragePair
.first
.first
->isStreamElement(StorageContainer::removeURLPrefix(sName
,aStoragePair
.first
.second
));
91 catch(NoSuchElementException
&)
96 OSL_ENSURE(0,"Exception catched! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement");
97 if (JNI_FALSE
!= env
->ExceptionCheck())
98 env
->ExceptionClear();
99 ::rtl::OString
cstr( ::rtl::OUStringToOString(e
.Message
, RTL_TEXTENCODING_JAVA_UTF8
) );
100 OSL_TRACE( __FILE__
": forwarding Exception: %s", cstr
.getStr() );
105 // -----------------------------------------------------------------------------
108 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
109 * Method: removeElement
110 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
112 SAL_DLLPUBLIC_EXPORT
void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement
113 (JNIEnv
* env
, jobject
/*obj_this*/,jstring key
, jstring name
)
117 ::rtl::OUString sKey
= StorageContainer::jstring2ustring(env
,key
);
118 ::rtl::OUString sName
= StorageContainer::jstring2ustring(env
,name
);
121 TStorages::mapped_type aStoragePair
= StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env
,key
));
122 if ( aStoragePair
.first
.first
.is() )
126 aStoragePair
.first
.first
->removeElement(StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env
,name
),aStoragePair
.first
.second
));
128 catch(NoSuchElementException
&)
130 if (JNI_FALSE
!= env
->ExceptionCheck())
131 env
->ExceptionClear();
135 OSL_ENSURE(0,"Exception catched! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement");
136 StorageContainer::throwJavaException(e
,env
);
140 // -----------------------------------------------------------------------------
143 * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess
144 * Method: renameElement
145 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
147 SAL_DLLPUBLIC_EXPORT
void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement
148 (JNIEnv
* env
, jobject
/*obj_this*/,jstring key
, jstring oldname
, jstring newname
)
152 ::rtl::OUString sKey
= StorageContainer::jstring2ustring(env
,key
);
153 ::rtl::OUString sNewName
= StorageContainer::jstring2ustring(env
,newname
);
154 ::rtl::OUString sOldName
= StorageContainer::jstring2ustring(env
,oldname
);
157 TStorages::mapped_type aStoragePair
= StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env
,key
));
158 if ( aStoragePair
.first
.first
.is() )
162 aStoragePair
.first
.first
->renameElement(
163 StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env
,oldname
),aStoragePair
.first
.second
),
164 StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env
,newname
),aStoragePair
.first
.second
)
168 ::rtl::OUString sNewName
= StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env
,newname
),aStoragePair
.first
.second
);
169 OSL_ENSURE(aStoragePair
.first
.first
->isStreamElement(sNewName
),"Stream could not be renamed");
173 catch(NoSuchElementException
&)
178 OSL_ENSURE(0,"Exception catched! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement");
179 StorageContainer::throwJavaException(e
,env
);
183 // -----------------------------------------------------------------------------