22#include <com/sun/star/embed/XTransactionBroadcaster.hpp>
23#include <com/sun/star/embed/XTransactedObject.hpp>
24#include <com/sun/star/embed/ElementModes.hpp>
25#include <com/sun/star/lang/DisposedException.hpp>
26#include <osl/diagnose.h>
28#include <uno/mapping.hxx>
64 catch(
const DisposedException&)
69 OSL_FAIL(
"Could not dispose OutputStream");
104 css::uno::Environment
env(css::uno::Environment::getCurrent());
106 throw css::uno::RuntimeException(
"cannot get environments");
113 throw css::uno::RuntimeException(
"cannot get mapping");
115 css::uno::Reference<css::embed::XStorage> mapped;
117 reinterpret_cast<void **
>(&mapped),
storage.get(),
131 static sal_Int32 s_nCount = 0;
132 return OUString::number(s_nCount++);
137 return OUString(_sURL.substr(_sFileURL.size()+1));
142 OUString sRet = _sURL;
144 sal_Int32
nIndex = sRet.lastIndexOf(
'\\');
146 sal_Int32
nIndex = sRet.lastIndexOf(
'/');
150 sRet = _sURL.copy(
nIndex+1);
160 if (
env->ExceptionCheck())
162 env->ExceptionClear();
163 OSL_FAIL(
"ExceptionClear");
168 jboolean bCopy(
true);
169 const jchar*
pChar =
env->GetStringChars(jstr,&bCopy);
170 jsize len =
env->GetStringLength(jstr);
175 env->ReleaseStringChars(jstr,
pChar);
178 if (
env->ExceptionCheck())
180 env->ExceptionClear();
181 OSL_FAIL(
"ExceptionClear");
189 OSL_ENSURE(_xStorage.is(),
"Storage is NULL!");
192 TStorages::const_iterator aFind = std::find_if(rMap.begin(),rMap.end(),
193 [&_xStorage] (
const TStorages::value_type& storage) {
194 return storage.second.mapStorage() == _xStorage;
197 if ( aFind == rMap.end() )
199 aFind = rMap.insert(TStorages::value_type(
lcl_getNextCount(), {_xStorage, css::uno::Environment::getCurrent(), _sURL,
TStreamMap()})).first;
207 TStorages::mapped_type aRet;
209 TStorages::const_iterator aFind = rMap.find(_sKey);
210 OSL_ENSURE(aFind != rMap.end(),
"Storage could not be found in list!");
211 if ( aFind != rMap.end() )
212 aRet = aFind->second;
220 OSL_ENSURE(_xStorage.is(),
"Storage is NULL!");
223 TStorages::const_iterator aFind = std::find_if(rMap.begin(),rMap.end(),
224 [&_xStorage] (
const TStorages::value_type& storage) {
225 return storage.second.mapStorage() == _xStorage;
228 if ( aFind != rMap.end() )
236 TStorages::iterator aFind = rMap.find(_sKey);
237 if ( aFind == rMap.end() )
242 if ( _xListener.is() )
244 Reference<XTransactionBroadcaster> xBroad(aFind->second.mapStorage(),UNO_QUERY);
246 xBroad->removeTransactionListener(_xListener);
247 Reference<XTransactedObject> xTrans(aFind->second.mapStorage(),UNO_QUERY);
260 TStreamMap::mapped_type pHelper;
263 TStorages::iterator aFind = rMap.find(sKey);
264 OSL_ENSURE(aFind != rMap.end(),
"Storage could not be found in list!");
265 if ( aFind != rMap.end() )
268 auto storage = aStoragePair.mapStorage();
269 OSL_ENSURE(storage.is(),
"No Storage available!");
274 TStreamMap::iterator aStreamFind = aFind->second.streams.find(
sName);
275 OSL_ENSURE( aStreamFind == aFind->second.streams.end(),
"A Stream was already registered for this object!");
276 if ( aStreamFind != aFind->second.streams.end() )
278 pHelper = aStreamFind->second;
286 pHelper = std::make_shared<StreamHelper>(storage->openStreamElement(
sName,_nMode));
292 if ( (_nMode & ElementModes::WRITE) != ElementModes::WRITE )
294 bool bIsStream =
true;
297 bIsStream = storage->isStreamElement(sStrippedName);
306 pHelper = std::make_shared<StreamHelper>(storage->openStreamElement( sStrippedName, _nMode ) );
308 aFind->second.streams.emplace(
sName,pHelper);
312 TOOLS_WARN_EXCEPTION(
"connectivity.hsqldb",
"[HSQLDB-SDBC] caught an exception while opening a stream\n"
314 <<
"\nMode: 0x" << ( _nMode < 16 ?
"0" :
"")
315 << std::hex << _nMode );
328 OSL_ENSURE(aFind != rMap.end(),
"Storage could not be found in list!");
329 if ( aFind != rMap.end() )
335 TStreamMap::mapped_type pRet;
338 OSL_ENSURE(aFind != rMap.end(),
"Storage could not be found in list!");
339 if ( aFind != rMap.end() )
342 if ( aStreamFind != aFind->second.streams.end() )
343 pRet = aStreamFind->second;
351 if (
env->ExceptionCheck())
352 env->ExceptionClear();
353 SAL_WARN(
"connectivity.hsqldb",
"forwarding Exception: " << _aException );
354 OString cstr(
OUStringToOString(_aException.Message, RTL_TEXTENCODING_JAVA_UTF8 ) );
355 env->ThrowNew(
env->FindClass(
"java/io/IOException"), cstr.getStr());
static OUString registerStorage(const css::uno::Reference< css::embed::XStorage > &_xStorage, const OUString &_sURL)
static TStreamMap::mapped_type registerStream(JNIEnv *env, jstring name, jstring key, sal_Int32 _nMode)
static void throwJavaException(const css::uno::Exception &_aException, JNIEnv *env)
static void revokeStorage(const OUString &_sKey, const css::uno::Reference< css::embed::XTransactionListener > &_xListener)
static OUString getRegisteredKey(const css::uno::Reference< css::embed::XStorage > &_xStorage)
static OUString jstring2ustring(JNIEnv *env, jstring jstr)
static OUString removeOldURLPrefix(const OUString &_sURL)
static OUString removeURLPrefix(std::u16string_view _sURL, std::u16string_view _sFileURL)
static void revokeStream(JNIEnv *env, jstring name, jstring key)
static TStreamMap::mapped_type getRegisteredStream(JNIEnv *env, jstring name, jstring key)
static TStorages::mapped_type getRegisteredStorage(const OUString &_sKey)
css::uno::Reference< css::io::XOutputStream > m_xOutputStream
css::uno::Reference< css::io::XSeekable > const & getSeek()
css::uno::Reference< css::io::XStream > m_xStream
css::uno::Reference< css::io::XSeekable > m_xSeek
css::uno::Reference< css::io::XInputStream > m_xInputStream
css::uno::Reference< css::io::XInputStream > const & getInputStream()
StreamHelper(const css::uno::Reference< css::io::XStream > &_xStream)
css::uno::Reference< css::io::XOutputStream > const & getOutputStream()
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN(area, stream)
const css::uno::Reference< css::xml::crypto::XSecurityEnvironment > & env
std::map< OUString, StorageData > TStorages
std::map< OUString, std::shared_ptr< StreamHelper > > TStreamMap
static TStorages & lcl_getStorageMap()
static OUString lcl_getNextCount()
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
std::map< OUString, rtl::Reference< Entity > > map
css::uno::Reference< css::embed::XStorage > mapStorage() const
css::uno::Reference< css::embed::XStorage > storage
css::uno::Environment storageEnvironment
Reference< XStream > m_xStream