22#include <com/sun/star/io/XStream.hpp>
23#include <osl/diagnose.h>
24#include <rtl/ustrbuf.hxx>
36void lclSplitFirstElement( OUString& orElement, OUString& orRemainder,
const OUString& _aFullName )
38 OUString aFullName = _aFullName;
39 sal_Int32 nSlashPos = aFullName.indexOf(
'/' );
42 while( nSlashPos == 0 )
44 aFullName = aFullName.copy(1);
45 nSlashPos = aFullName.indexOf(
'/' );
48 if( (0 <= nSlashPos) && (nSlashPos < aFullName.getLength()) )
50 orElement = aFullName.copy( 0, nSlashPos );
51 orRemainder = aFullName.copy( nSlashPos + 1 );
55 orElement = aFullName;
63 mbBaseStreamAccess( bBaseStreamAccess ),
66 OSL_ENSURE(
mxInStream.is(),
"StorageBase::StorageBase - missing base input stream" );
70 mxOutStream( rxOutStream ),
71 mbBaseStreamAccess( bBaseStreamAccess ),
74 OSL_ENSURE( mxOutStream.is(),
"StorageBase::StorageBase - missing base output stream" );
78 maParentPath( rParentStorage.getPath() ),
79 maStorageName( rStorageName ),
80 mbBaseStreamAccess( false ),
110 return aBuffer.makeStringAndClear();
115 orElementNames.clear();
122 OSL_ENSURE( !bCreateMissing || !
mbReadOnly,
"StorageBase::openSubStorage - cannot create substorage in read-only mode" );
125 OUString aElement, aRemainder;
126 lclSplitFirstElement( aElement, aRemainder, rStorageName );
127 if( !aElement.isEmpty() )
129 if( xSubStorage && !aRemainder.isEmpty() )
130 xSubStorage = xSubStorage->openSubStorage( aRemainder, bCreateMissing );
137 Reference< XInputStream > xInStream;
138 OUString aElement, aRemainder;
139 lclSplitFirstElement( aElement, aRemainder, rStreamName );
140 if( !aElement.isEmpty() )
142 if( !aRemainder.isEmpty() )
146 xInStream = xSubStorage->openInputStream( aRemainder );
162 Reference< XOutputStream > xOutStream;
163 OSL_ENSURE( !
mbReadOnly,
"StorageBase::openOutputStream - cannot create output stream in read-only mode" );
166 OUString aElement, aRemainder;
167 lclSplitFirstElement( aElement, aRemainder, rStreamName );
168 if( !aElement.isEmpty() )
170 if( !aRemainder.isEmpty() )
174 xOutStream = xSubStorage->openOutputStream( aRemainder );
191 OSL_ENSURE( rDestStrg.
isStorage() && !rDestStrg.
isReadOnly(),
"StorageBase::copyToStorage - invalid destination" );
192 OSL_ENSURE( !rElementName.isEmpty(),
"StorageBase::copyToStorage - invalid element name" );
201 xSubStrg->copyStorageToStorage( *xDestSubStrg );
208 Reference< XOutputStream > xOutStrm = rDestStrg.
openOutputStream( rElementName );
221 OSL_ENSURE( rDestStrg.
isStorage() && !rDestStrg.
isReadOnly(),
"StorageBase::copyToStorage - invalid destination" );
224 ::std::vector< OUString > aElements;
226 for (
auto const& elem : aElements)
233 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