22#include <com/sun/star/io/XStream.hpp>
23#include <osl/diagnose.h>
24#include <rtl/ustrbuf.hxx>
37void lclSplitFirstElement( OUString& orElement, OUString& orRemainder,
const OUString& _aFullName )
39 OUString aFullName = _aFullName;
40 sal_Int32 nSlashPos = aFullName.indexOf(
'/' );
43 while( nSlashPos == 0 )
45 aFullName = aFullName.copy(1);
46 nSlashPos = aFullName.indexOf(
'/' );
49 if( (0 <= nSlashPos) && (nSlashPos < aFullName.getLength()) )
51 orElement = aFullName.copy( 0, nSlashPos );
52 orRemainder = aFullName.copy( nSlashPos + 1 );
56 orElement = aFullName;
64 mbBaseStreamAccess( bBaseStreamAccess ),
67 OSL_ENSURE(
mxInStream.is(),
"StorageBase::StorageBase - missing base input stream" );
71 mxOutStream( rxOutStream ),
72 mbBaseStreamAccess( bBaseStreamAccess ),
75 OSL_ENSURE( mxOutStream.is(),
"StorageBase::StorageBase - missing base output stream" );
79 maParentPath( rParentStorage.getPath() ),
80 maStorageName(
std::move( aStorageName )),
81 mbBaseStreamAccess( false ),
111 return aBuffer.makeStringAndClear();
116 orElementNames.clear();
123 OSL_ENSURE( !bCreateMissing || !
mbReadOnly,
"StorageBase::openSubStorage - cannot create substorage in read-only mode" );
126 OUString aElement, aRemainder;
127 lclSplitFirstElement( aElement, aRemainder, rStorageName );
128 if( !aElement.isEmpty() )
130 if( xSubStorage && !aRemainder.isEmpty() )
131 xSubStorage = xSubStorage->openSubStorage( aRemainder, bCreateMissing );
138 Reference< XInputStream > xInStream;
139 OUString aElement, aRemainder;
140 lclSplitFirstElement( aElement, aRemainder, rStreamName );
141 if( !aElement.isEmpty() )
143 if( !aRemainder.isEmpty() )
147 xInStream = xSubStorage->openInputStream( aRemainder );
163 Reference< XOutputStream > xOutStream;
164 OSL_ENSURE( !
mbReadOnly,
"StorageBase::openOutputStream - cannot create output stream in read-only mode" );
167 OUString aElement, aRemainder;
168 lclSplitFirstElement( aElement, aRemainder, rStreamName );
169 if( !aElement.isEmpty() )
171 if( !aRemainder.isEmpty() )
175 xOutStream = xSubStorage->openOutputStream( aRemainder );
192 OSL_ENSURE( rDestStrg.
isStorage() && !rDestStrg.
isReadOnly(),
"StorageBase::copyToStorage - invalid destination" );
193 OSL_ENSURE( !rElementName.isEmpty(),
"StorageBase::copyToStorage - invalid element name" );
202 xSubStrg->copyStorageToStorage( *xDestSubStrg );
209 Reference< XOutputStream > xOutStrm = rDestStrg.
openOutputStream( rElementName );
222 OSL_ENSURE( rDestStrg.
isStorage() && !rDestStrg.
isReadOnly(),
"StorageBase::copyToStorage - invalid destination" );
225 ::std::vector< OUString > aElements;
227 for (
auto const& elem : aElements)
234 OSL_ENSURE( !
mbReadOnly,
"StorageBase::commit - cannot commit in read-only mode" );
Wraps a UNO output stream and provides convenient access functions.
Base class for storage access implementations.
virtual css::uno::Reference< css::embed::XStorage > implGetXStorage() const =0
Returns the com.sun.star.embed.XStorage interface of the current storage.
virtual bool implIsStorage() const =0
Returns true, if the object represents a valid storage.
css::uno::Reference< css::embed::XStorage > getXStorage() const
Returns the com.sun.star.embed.XStorage interface of the current storage.
StorageBase(const css::uno::Reference< css::io::XInputStream > &rxInStream, bool bBaseStreamAccess)
OUString getPath() const
Returns the full path of this storage.
bool mbReadOnly
True = storage opened read-only (based on input stream).
css::uno::Reference< css::io::XStream > mxOutStream
Cached base output stream (to keep it alive).
css::uno::Reference< css::io::XInputStream > mxInStream
Cached base input stream (to keep it alive).
bool mbBaseStreamAccess
True = access base streams with empty stream name.
StorageRef getSubStorage(const OUString &rElementName, bool bCreateMissing)
Helper that opens and caches the specified direct substorage.
void getElementNames(::std::vector< OUString > &orElementNames) const
Fills the passed vector with the names of all direct elements of this storage.
void copyToStorage(StorageBase &rDestStrg, const OUString &rElementName)
Copies the specified element from this storage to the passed destination storage.
OUString maStorageName
Name of this storage, if it is a substorage.
css::uno::Reference< css::io::XInputStream > openInputStream(const OUString &rStreamName)
Opens and returns the specified input stream from the storage.
virtual void implCommit() const =0
Commits the current storage.
RefMap< OUString, StorageBase > maSubStorages
Map of direct sub storages.
virtual css::uno::Reference< css::io::XInputStream > implOpenInputStream(const OUString &rElementName)=0
Implementation of opening an input stream element.
void commit()
Commits the changes to the storage and all substorages.
virtual css::uno::Reference< css::io::XOutputStream > implOpenOutputStream(const OUString &rElementName)=0
Implementation of opening an output stream element.
bool isReadOnly() const
Returns true, if the storage operates in read-only mode (based on an input stream).
void copyStorageToStorage(StorageBase &rDestStrg)
Copies all streams of this storage and of all substorages to the passed destination.
virtual StorageRef implOpenSubStorage(const OUString &rElementName, bool bCreate)=0
Implementation of opening a storage element.
bool isStorage() const
Returns true, if the object represents a valid storage.
StorageRef openSubStorage(const OUString &rStorageName, bool bCreateMissing)
Opens and returns the specified sub storage from the storage.
virtual void implGetElementNames(::std::vector< OUString > &orElementNames) const =0
Returns the names of all elements of this storage.
OUString maParentPath
Full path of parent storage.
bool isRootStorage() const
Returns true, if the object represents the root storage.
css::uno::Reference< css::io::XOutputStream > openOutputStream(const OUString &rStreamName)
Opens and returns the specified output stream from the storage.
Reference< XInputStream > mxInStream
std::shared_ptr< StorageBase > StorageRef
std::unique_ptr< char[]> aBuffer