From e9a036aca1062fd5512b8dbd93ef7172831b3bc4 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Wed, 15 Jan 2014 14:33:58 +0100 Subject: add BIPU support for zip to WPXSvInputStream Change-Id: I14d6febcff49421b6ee3f2c463e78ff98660aab5 --- writerperfect/source/common/WPXSvStream.cxx | 77 +++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 5 deletions(-) (limited to 'writerperfect') diff --git a/writerperfect/source/common/WPXSvStream.cxx b/writerperfect/source/common/WPXSvStream.cxx index d705ba51fcfd..9bc69849da9c 100644 --- a/writerperfect/source/common/WPXSvStream.cxx +++ b/writerperfect/source/common/WPXSvStream.cxx @@ -9,6 +9,11 @@ #include "WPXSvStream.hxx" +#include +#include + +#include + #include #include #include @@ -23,6 +28,10 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::io; +namespace container = com::sun::star::container; +namespace lang = com::sun::star::lang; +namespace packages = com::sun::star::packages; + namespace { @@ -259,6 +268,8 @@ private: bool isOLE(); void ensureOLEIsInitialized(); + bool isZip(); + WPXInputStream *createWPXStream(const SotStorageStreamRef &rxStorage); private: @@ -266,7 +277,12 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > mxSeekable; ::com::sun::star::uno::Sequence< sal_Int8 > maData; boost::scoped_ptr< OLEStorageImpl > mpOLEStorage; + // TODO: this is not sufficient to implement RVNGInputStream, as + // packages::Package does not support any kind of enumeration of + // its content + ::com::sun::star::uno::Reference< container::XHierarchicalNameAccess > mxZipStorage; bool mbCheckedOLE; + bool mbCheckedZip; public: sal_Int64 mnLength; unsigned char *mpReadBuffer; @@ -279,7 +295,9 @@ WPXSvInputStreamImpl::WPXSvInputStreamImpl( Reference< XInputStream > xStream ) mxSeekable(xStream, UNO_QUERY), maData(0), mpOLEStorage(0), + mxZipStorage(), mbCheckedOLE(false), + mbCheckedZip(false), mnLength(0), mpReadBuffer(0), mnReadBufferLength(0), @@ -373,7 +391,7 @@ bool WPXSvInputStreamImpl::isStructured() PositionHolder pos(mxSeekable); mxSeekable->seek(0); - return isOLE(); + return isOLE() || isZip(); } unsigned WPXSvInputStreamImpl::subStreamCount() @@ -391,6 +409,8 @@ unsigned WPXSvInputStreamImpl::subStreamCount() return mpOLEStorage->maStreams.size(); } + // TODO: zip impl. + return 0; } @@ -412,6 +432,8 @@ const char *WPXSvInputStreamImpl::subStreamName(const unsigned id) return mpOLEStorage->maStreams[id].name.getStr(); } + // TODO: zip impl. + return 0; } @@ -426,14 +448,17 @@ bool WPXSvInputStreamImpl::existsSubStream(const char *const name) PositionHolder pos(mxSeekable); mxSeekable->seek(0); + const rtl::OUString aName(rtl::OStringToOUString(rtl::OString(name), RTL_TEXTENCODING_UTF8)); + if (isOLE()) { ensureOLEIsInitialized(); - - const rtl::OUString aName(rtl::OStringToOUString(rtl::OString(name), RTL_TEXTENCODING_UTF8)); return mpOLEStorage->maNameMap.end() != mpOLEStorage->maNameMap.find(aName); } + if (isZip()) + return mxZipStorage->hasByHierarchicalName(aName); + return false; } @@ -448,14 +473,27 @@ WPXInputStream *WPXSvInputStreamImpl::getSubStreamByName(const char *const name) PositionHolder pos(mxSeekable); mxSeekable->seek(0); + const rtl::OUString aName(rtl::OStringToOUString(rtl::OString(name), RTL_TEXTENCODING_UTF8)); + if (isOLE()) { ensureOLEIsInitialized(); - - const rtl::OUString aName(rtl::OStringToOUString(rtl::OString(name), RTL_TEXTENCODING_UTF8)); return createWPXStream(mpOLEStorage->getStream(aName)); } + if (isZip()) + { + try + { + const Reference xStream(mxZipStorage->getByHierarchicalName(aName), UNO_QUERY_THROW); + return new WPXSvInputStream(xStream->getInputStream()); + } + catch (const Exception &) + { + // nothing needed + } + } + return 0; } @@ -477,6 +515,8 @@ WPXInputStream *WPXSvInputStreamImpl::getSubStreamById(const unsigned id) return createWPXStream(mpOLEStorage->getStream(id)); } + // TODO: zip impl. + return 0; } @@ -516,6 +556,33 @@ bool WPXSvInputStreamImpl::isOLE() return bool(mpOLEStorage); } +bool WPXSvInputStreamImpl::isZip() +{ + if (!mbCheckedZip) + { + assert(0 == mxSeekable->getPosition()); + + try + { + Sequence aArgs(1); + aArgs[0] <<= mxStream; + + const Reference xContext(comphelper::getProcessComponentContext(), UNO_QUERY_THROW); + mxZipStorage.set( + xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.packages.Package", aArgs, xContext), + UNO_QUERY_THROW); + } + catch (const Exception &) + { + // ignore + } + + mbCheckedZip = true; + } + + return mxZipStorage.is(); +} + void WPXSvInputStreamImpl::ensureOLEIsInitialized() { assert(mpOLEStorage); -- cgit