22#include <com/sun/star/embed/OLESimpleStorage.hpp>
23#include <com/sun/star/lang/DisposedException.hpp>
24#include <com/sun/star/lang/NoSupportException.hpp>
25#include <com/sun/star/io/IOException.hpp>
26#include <com/sun/star/io/XStream.hpp>
27#include <com/sun/star/io/XInputStream.hpp>
28#include <com/sun/star/io/XSeekable.hpp>
29#include <com/sun/star/io/XTruncate.hpp>
30#include <com/sun/star/io/TempFile.hpp>
46 css::uno::Reference<css::uno::XComponentContext> xContext,
47 css::uno::Sequence<css::uno::Any>
const &aArguments)
50, m_bNoTemporaryCopy( false )
53 if ( nArgNum < 1 || nArgNum > 2 )
54 throw lang::IllegalArgumentException();
56 uno::Reference< io::XStream >
xStream;
57 uno::Reference< io::XInputStream > xInputStream;
59 throw lang::IllegalArgumentException();
64 throw lang::IllegalArgumentException();
72 if ( xInputStream.is() )
75 uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW );
81 uno::Reference< io::XSeekable > xSeek(
xStream, uno::UNO_QUERY_THROW );
85 throw lang::IllegalArgumentException();
89 uno::Reference < io::XStream > xTempFile( io::TempFile::create(
m_xContext),
90 uno::UNO_QUERY_THROW );
91 uno::Reference < io::XSeekable > xTempSeek( xTempFile, uno::UNO_QUERY_THROW );
92 uno::Reference< io::XOutputStream > xTempOut = xTempFile->getOutputStream();
94 throw uno::RuntimeException();
96 if ( xInputStream.is() )
100 uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW );
103 catch( uno::Exception& )
107 xTempOut->closeOutput();
108 xTempSeek->seek( 0 );
109 uno::Reference< io::XInputStream > xTempInput = xTempFile->getInputStream();
118 uno::Reference< io::XSeekable > xSeek(
xStream, uno::UNO_QUERY_THROW );
120 uno::Reference< io::XInputStream > xInpStream =
xStream->getInputStream();
121 if ( !xInpStream.is() || !
xStream->getOutputStream().is() )
122 throw uno::RuntimeException();
126 xTempSeek->seek( 0 );
131 throw lang::IllegalArgumentException();
135 throw io::IOException();
145 }
catch( uno::Exception& )
154 uno::Reference< io::XSeekable > xSeek(
m_xStream, uno::UNO_QUERY_THROW );
157 uno::Reference< io::XSeekable > xTempSeek(
m_xTempStream, uno::UNO_QUERY_THROW );
158 sal_Int64
nPos = xTempSeek->getPosition();
159 xTempSeek->seek( 0 );
161 uno::Reference< io::XInputStream > xTempInp =
m_xTempStream->getInputStream();
162 uno::Reference< io::XOutputStream > xOutputStream =
m_xStream->getOutputStream();
163 if ( !xTempInp.is() || !xOutputStream.is() )
164 throw uno::RuntimeException();
166 uno::Reference< io::XTruncate > xTrunc( xOutputStream, uno::UNO_QUERY_THROW );
170 xOutputStream->flush();
171 xTempSeek->seek(
nPos );
177 if ( !pStorage ||
aName.isEmpty() || !xInputStream.is() )
178 throw uno::RuntimeException();
181 throw container::ElementExistException();
183 std::unique_ptr<BaseStorageStream> pNewStream(pStorage->
OpenStream(
aName ));
184 if ( !pNewStream || pNewStream->GetError() || pStorage->
GetError() )
188 throw io::IOException();
199 sal_Int32 nWritten = pNewStream->Write(
aData.getConstArray(), nRead );
200 if ( nWritten < nRead )
201 throw io::IOException();
204 catch( uno::Exception& )
216 if ( !pStorage ||
aName.isEmpty() || !xNameAccess.is() )
217 throw uno::RuntimeException();
220 throw container::ElementExistException();
223 if ( !pNewStorage || pNewStorage->GetError() || pStorage->
GetError() )
227 throw io::IOException();
232 const uno::Sequence< OUString > aElements = xNameAccess->getElementNames();
233 for (
const auto& rElement : aElements )
235 uno::Reference< io::XInputStream > xInputStream;
236 uno::Reference< container::XNameAccess > xSubNameAccess;
237 uno::Any aAny = xNameAccess->getByName( rElement );
238 if ( aAny >>= xInputStream )
240 else if ( aAny >>= xSubNameAccess )
244 catch( uno::Exception& )
259 std::unique_lock aGuard(
m_aMutex );
262 throw lang::DisposedException();
265 throw uno::RuntimeException();
267 uno::Reference< io::XStream >
xStream;
268 uno::Reference< io::XInputStream > xInputStream;
269 uno::Reference< container::XNameAccess > xNameAccess;
274 throw io::IOException();
277 xInputStream =
xStream->getInputStream();
278 else if ( !( aElement >>= xInputStream ) && !( aElement >>= xNameAccess ) )
279 throw lang::IllegalArgumentException();
281 if ( xInputStream.is() )
283 else if ( xNameAccess.is() )
286 throw uno::RuntimeException();
288 catch( uno::RuntimeException& )
292 catch( container::ElementExistException& )
296 catch(
const uno::Exception& )
299 throw lang::WrappedTargetException(
"Insert has failed!",
300 uno::Reference< uno::XInterface >(),
308 std::unique_lock aGuard(
m_aMutex );
311 throw lang::DisposedException();
314 throw uno::RuntimeException();
317 throw lang::WrappedTargetException();
320 throw container::NoSuchElementException();
327 throw lang::WrappedTargetException();
334 std::unique_lock aGuard(
m_aMutex );
337 throw lang::DisposedException();
345 catch( container::ElementExistException& )
347 uno::Any aCaught( ::cppu::getCaughtException() );
349 throw lang::WrappedTargetException(
"Can't copy raw stream",
350 uno::Reference< uno::XInterface >(),
358 std::unique_lock aGuard(
m_aMutex );
361 throw lang::DisposedException();
364 throw uno::RuntimeException();
367 throw container::NoSuchElementException();
371 uno::Reference< io::XStream > xTempFile = io::TempFile::create(
m_xContext);
372 uno::Reference< io::XSeekable > xSeekable( xTempFile, uno::UNO_QUERY_THROW );
373 uno::Reference< io::XOutputStream > xOutputStream = xTempFile->getOutputStream();
374 uno::Reference< io::XInputStream > xInputStream = xTempFile->getInputStream();
375 if ( !xOutputStream.is() || !xInputStream.is() )
376 throw uno::RuntimeException();
383 throw lang::WrappedTargetException();
387 throw uno::RuntimeException();
389 std::unique_ptr<BaseStorage> pNewStor(
new Storage( *pStream,
false ));
390 bool bSuccess = ( pStrg->CopyTo( pNewStor.get() ) && pNewStor->Commit() &&
391 !pNewStor->GetError() && !pStrg->GetError() );
398 throw uno::RuntimeException();
400 uno::Reference< container::XNameContainer > xResultNameContainer(
401 css::embed::OLESimpleStorage::createFromInputStream(
m_xContext, xInputStream,
true),
402 uno::UNO_QUERY_THROW );
404 aResult <<= xResultNameContainer;
408 std::unique_ptr<BaseStorageStream> pStream(
m_pStorage->OpenStream(
aName, StreamMode::READ | StreamMode::SHARE_DENYALL | StreamMode::NOCREATE ));
411 if ( !pStream || pStream->GetError() ||
m_pStorage->GetError() )
414 throw io::IOException();
420 while( 0 != ( nRead = pStream->Read(
aData.getArray(), nSize ) ) )
425 aData.realloc( nSize );
428 xOutputStream->writeBytes(
aData );
431 if ( pStream->GetError() )
432 throw io::IOException();
434 xOutputStream->closeOutput();
435 xSeekable->seek( 0 );
437 catch (
const uno::RuntimeException&)
441 catch (
const uno::Exception&
ex)
444 throw css::lang::WrappedTargetException(
ex.Message,
450 aResult <<= xInputStream;
459 std::unique_lock aGuard(
m_aMutex );
462 throw lang::DisposedException();
465 throw uno::RuntimeException();
473 throw uno::RuntimeException();
476 uno::Sequence< OUString >
aSeq( aList.size() );
477 auto aSeqRange = asNonConstRange(
aSeq);
478 for (
size_t nInd = 0; nInd < aList.size(); nInd++ )
479 aSeqRange[nInd] = aList[nInd].
GetName();
487 std::unique_lock aGuard(
m_aMutex );
490 throw lang::DisposedException();
493 throw uno::RuntimeException();
500 throw uno::RuntimeException();
509 std::unique_lock aGuard(
m_aMutex );
512 throw lang::DisposedException();
520 std::unique_lock aGuard(
m_aMutex );
523 throw lang::DisposedException();
526 throw uno::RuntimeException();
534 throw uno::RuntimeException();
537 return !aList.empty();
546 std::unique_lock aGuard(
m_aMutex );
553 lang::EventObject aSource( getXWeak() );
568 const uno::Reference< lang::XEventListener >& xListener )
570 std::unique_lock aGuard(
m_aMutex );
573 throw lang::DisposedException();
580 const uno::Reference< lang::XEventListener >& xListener )
582 std::unique_lock aGuard(
m_aMutex );
585 throw lang::DisposedException();
596 std::unique_lock aGuard(
m_aMutex );
599 throw lang::DisposedException();
602 throw uno::RuntimeException();
605 throw io::IOException();
610 throw io::IOException();
619 std::unique_lock aGuard(
m_aMutex );
622 throw lang::DisposedException();
625 throw uno::RuntimeException();
628 throw io::IOException();
633 throw io::IOException();
645 std::unique_lock aGuard(
m_aMutex );
648 throw lang::DisposedException();
651 throw uno::RuntimeException();
653 return m_pStorage->GetClassName().GetByteSequence();
664 throw lang::NoSupportException();
670 return "com.sun.star.comp.embed.OLESimpleStorage";
680 return {
"com.sun.star.embed.OLESimpleStorage" };
683extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
685 css::uno::XComponentContext *context,
686 css::uno::Sequence<css::uno::Any>
const &arguments)
Reference< XComponentContext > m_xContext
virtual void Remove(const OUString &rEleName)=0
virtual BaseStorage * OpenStorage(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE, bool bDirect=false)=0
virtual BaseStorageStream * OpenStream(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE, bool bDirect=true)=0
virtual bool IsContained(const OUString &rEleName) const =0
virtual void SAL_CALL commit() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Type SAL_CALL getElementType() override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual OUString SAL_CALL getClassName() override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual void SAL_CALL setClassInfo(const css::uno::Sequence< ::sal_Int8 > &aClassID, const OUString &sClassName) override
static void InsertNameAccessToStorage_Impl(BaseStorage *pStorage, const OUString &aName, const css::uno::Reference< css::container::XNameAccess > &xNameAccess)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL dispose() final override
OLESimpleStorage(css::uno::Reference< css::uno::XComponentContext > xContext, css::uno::Sequence< css::uno::Any > const &arguments)
virtual void SAL_CALL revert() override
virtual void SAL_CALL insertByName(const OUString &aName, const css::uno::Any &aElement) override
virtual void SAL_CALL replaceByName(const OUString &aName, const css::uno::Any &aElement) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
std::unique_ptr< BaseStorage > m_pStorage
virtual css::uno::Sequence< ::sal_Int8 > SAL_CALL getClassID() override
css::uno::Reference< css::io::XStream > m_xStream
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
virtual void SAL_CALL removeByName(const OUString &Name) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
::comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > m_aListenersContainer
virtual ~OLESimpleStorage() override
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
static void InsertInputStreamToStorage_Impl(BaseStorage *pStorage, const OUString &aName, const css::uno::Reference< css::io::XInputStream > &xInputStream)
css::uno::Reference< css::io::XStream > m_xTempStream
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL hasElements() override
std::unique_ptr< SvStream > m_pStream
void UpdateOriginal_Impl()
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
sal_Int32 getLength(std::unique_lock< std::mutex > &rGuard) const
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
static void CopyInputToOutput(const css::uno::Reference< css::io::XInputStream > &xInput, const css::uno::Reference< css::io::XOutputStream > &xOutput)
css::uno::Type const & get()
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
virtual OUString GetName() const override
Sequence< PropertyValue > aArguments
Sequence< sal_Int8 > aSeq
constexpr OUStringLiteral aData
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Any SAL_CALL getCaughtException()
std::vector< SvStorageInfo > SvStorageInfoList
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_embed_OLESimpleStorage(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &arguments)
const sal_Int32 nBytesCount