22#include <com/sun/star/embed/ElementModes.hpp>
23#include <com/sun/star/embed/XStorage.hpp>
24#include <com/sun/star/embed/XTransactedObject.hpp>
25#include <com/sun/star/io/XInputStream.hpp>
26#include <com/sun/star/io/XOutputStream.hpp>
27#include <com/sun/star/uno/XComponentContext.hpp>
28#include <osl/diagnose.h>
41ZipStorage::ZipStorage(
const Reference< XComponentContext >& rxContext,
const Reference< XInputStream >& rxInStream ) :
44 OSL_ENSURE( rxContext.is(),
"ZipStorage::ZipStorage - missing component context" );
64 ZIP_STORAGE_FORMAT_STRING, rxInStream, rxContext,
false);
66 catch (Exception
const&)
72ZipStorage::ZipStorage(
const Reference< XComponentContext >& rxContext,
const Reference< XStream >& rxStream ) :
75 OSL_ENSURE( rxContext.is(),
"ZipStorage::ZipStorage - missing component context" );
77 if( rxContext.is() )
try
79 const sal_Int32 nOpenMode = ElementModes::READWRITE | ElementModes::TRUNCATE;
81 OFOPXML_STORAGE_FORMAT_STRING, rxStream, nOpenMode, rxContext,
true);
83 catch (Exception
const&)
89ZipStorage::ZipStorage(
const ZipStorage& rParentStorage,
const Reference< XStorage >& rxStorage,
const OUString& rElementName ) :
90 StorageBase( rParentStorage, rElementName, rParentStorage.isReadOnly() ),
94 " - missing storage" );
97ZipStorage::~ZipStorage()
101bool ZipStorage::implIsStorage()
const
106Reference< XStorage > ZipStorage::implGetXStorage()
const
111void ZipStorage::implGetElementNames( ::std::vector< OUString >& orElementNames )
const
115 const Sequence<OUString> aNames =
mxStorage->getElementNames();
116 if( aNames.hasElements() )
117 orElementNames.insert( orElementNames.end(), aNames.begin(), aNames.end() );
125StorageRef ZipStorage::implOpenSubStorage(
const OUString& rElementName,
bool bCreateMissing )
127 Reference< XStorage > xSubXStorage;
128 bool bMissing =
false;
132 if(
mxStorage->isStorageElement( rElementName ) )
133 xSubXStorage =
mxStorage->openStorageElement(
134 rElementName, css::embed::ElementModes::READ );
136 catch( NoSuchElementException& )
145 if( bMissing && bCreateMissing )
try
147 xSubXStorage =
mxStorage->openStorageElement(
148 rElementName, css::embed::ElementModes::READWRITE );
156 if( xSubXStorage.is() )
157 xSubStorage.reset(
new ZipStorage( *
this, xSubXStorage, rElementName ) );
161Reference< XInputStream > ZipStorage::implOpenInputStream(
const OUString& rElementName )
163 Reference< XInputStream > xInStream;
166 xInStream.set(
mxStorage->openStreamElement( rElementName, css::embed::ElementModes::READ ), UNO_QUERY );
175Reference< XOutputStream > ZipStorage::implOpenOutputStream(
const OUString& rElementName )
177 Reference< XOutputStream > xOutStream;
180 xOutStream.set(
mxStorage->openStreamElement( rElementName, css::embed::ElementModes::READWRITE ), UNO_QUERY );
189void ZipStorage::implCommit()
const
193 Reference< XTransactedObject >(
mxStorage, UNO_QUERY_THROW )->commit();
static css::uno::Reference< css::embed::XStorage > GetStorageOfFormatFromInputStream(const OUString &aFormat, const css::uno::Reference< css::io::XInputStream > &xStream, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >(), bool bRepairStorage=false)
static css::uno::Reference< css::embed::XStorage > GetStorageOfFormatFromStream(const OUString &aFormat, const css::uno::Reference< css::io::XStream > &xStream, sal_Int32 nStorageMode=css::embed::ElementModes::READWRITE, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >(), bool bRepairStorage=false)
Implements stream access for ZIP storages containing XML streams.
ZipStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::io::XInputStream > &rxInStream)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define TOOLS_INFO_EXCEPTION(area, stream)
#define SAL_WARN_IF(condition, area, stream)
std::shared_ptr< StorageBase > StorageRef
Reference< XNameContainer > mxStorage