1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H 32*cdf0e10cSrcweir #include <config.h> 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp> 36*cdf0e10cSrcweir #include "hsqldb/StorageFileAccess.h" 37*cdf0e10cSrcweir #include "hsqldb/HStorageMap.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <rtl/logfile.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using namespace ::com::sun::star::container; 42*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43*cdf0e10cSrcweir using namespace ::com::sun::star::embed; 44*cdf0e10cSrcweir using namespace ::com::sun::star::io; 45*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 46*cdf0e10cSrcweir using namespace ::connectivity::hsqldb; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) 49*cdf0e10cSrcweir /*****************************************************************************/ 50*cdf0e10cSrcweir /* exception macros */ 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #define ThrowException(env, type, msg) { \ 53*cdf0e10cSrcweir env->ThrowNew(env->FindClass(type), msg); } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir /* 56*cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess 57*cdf0e10cSrcweir * Method: isStreamElement 58*cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;)Z 59*cdf0e10cSrcweir */ 60*cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT jboolean JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement 61*cdf0e10cSrcweir (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); 64*cdf0e10cSrcweir if ( aStoragePair.first.first.is() ) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir try 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir ::rtl::OUString sName = StorageContainer::jstring2ustring(env,name); 69*cdf0e10cSrcweir try 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir ::rtl::OUString sOldName = StorageContainer::removeOldURLPrefix(sName); 72*cdf0e10cSrcweir if ( aStoragePair.first.first->isStreamElement(sOldName) ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir try 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir aStoragePair.first.first->renameElement(sOldName,StorageContainer::removeURLPrefix(sName,aStoragePair.first.second)); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir catch(Exception&) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir catch(NoSuchElementException&) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir return aStoragePair.first.first->isStreamElement(StorageContainer::removeURLPrefix(sName,aStoragePair.first.second)); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir catch(NoSuchElementException&) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir catch(Exception& e) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir OSL_ENSURE(0,"Exception catched! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement"); 94*cdf0e10cSrcweir if (JNI_FALSE != env->ExceptionCheck()) 95*cdf0e10cSrcweir env->ExceptionClear(); 96*cdf0e10cSrcweir ::rtl::OString cstr( ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_JAVA_UTF8 ) ); 97*cdf0e10cSrcweir OSL_TRACE( __FILE__": forwarding Exception: %s", cstr.getStr() ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir return JNI_FALSE; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir /* 105*cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess 106*cdf0e10cSrcweir * Method: removeElement 107*cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;)V 108*cdf0e10cSrcweir */ 109*cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement 110*cdf0e10cSrcweir (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir #ifdef HSQLDB_DBG 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir ::rtl::OUString sKey = StorageContainer::jstring2ustring(env,key); 115*cdf0e10cSrcweir ::rtl::OUString sName = StorageContainer::jstring2ustring(env,name); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir #endif 118*cdf0e10cSrcweir TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); 119*cdf0e10cSrcweir if ( aStoragePair.first.first.is() ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir try 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir aStoragePair.first.first->removeElement(StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,name),aStoragePair.first.second)); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir catch(NoSuchElementException&) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir if (JNI_FALSE != env->ExceptionCheck()) 128*cdf0e10cSrcweir env->ExceptionClear(); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir catch(Exception& e) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir OSL_ENSURE(0,"Exception catched! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement"); 133*cdf0e10cSrcweir StorageContainer::throwJavaException(e,env); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir /* 140*cdf0e10cSrcweir * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess 141*cdf0e10cSrcweir * Method: renameElement 142*cdf0e10cSrcweir * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V 143*cdf0e10cSrcweir */ 144*cdf0e10cSrcweir SAL_DLLPUBLIC_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement 145*cdf0e10cSrcweir (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring oldname, jstring newname) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir #ifdef HSQLDB_DBG 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir ::rtl::OUString sKey = StorageContainer::jstring2ustring(env,key); 150*cdf0e10cSrcweir ::rtl::OUString sNewName = StorageContainer::jstring2ustring(env,newname); 151*cdf0e10cSrcweir ::rtl::OUString sOldName = StorageContainer::jstring2ustring(env,oldname); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir #endif 154*cdf0e10cSrcweir TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); 155*cdf0e10cSrcweir if ( aStoragePair.first.first.is() ) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir try 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir aStoragePair.first.first->renameElement( 160*cdf0e10cSrcweir StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,oldname),aStoragePair.first.second), 161*cdf0e10cSrcweir StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second) 162*cdf0e10cSrcweir ); 163*cdf0e10cSrcweir #ifdef HSQLDB_DBG 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir ::rtl::OUString sNewName = StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second); 166*cdf0e10cSrcweir OSL_ENSURE(aStoragePair.first.first->isStreamElement(sNewName),"Stream could not be renamed"); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir #endif 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir catch(NoSuchElementException&) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir catch(Exception& e) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir OSL_ENSURE(0,"Exception catched! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement"); 176*cdf0e10cSrcweir StorageContainer::throwJavaException(e,env); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 181