package/inc/ZipPackage.hxx | 14 ---- package/inc/zipfileaccess.hxx | 1 package/source/zippackage/ZipPackage.cxx | 25 ------- package/source/zippackage/zipfileaccess.cxx | 4 - writerperfect/source/common/WPXSvStream.cxx | 90 +++++++++++----------------- 5 files changed, 44 insertions(+), 90 deletions(-)
New commits: commit c20db8735e3f30cf61940e8c1da739efcb00ae22 Author: David Tardon <dtar...@redhat.com> Date: Thu Jan 16 16:37:57 2014 +0100 Revert "impl. enumeration for ZipPackage" This reverts commit 5b2cca80eeb2c8ee210820cc8ed95e5d69214807. Also reverts commit 86a5053df0d755d10121d65c533f3d327340a0fd. diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx index 1a0bb30..3631799 100644 --- a/package/inc/ZipPackage.hxx +++ b/package/inc/ZipPackage.hxx @@ -19,9 +19,8 @@ #ifndef _ZIP_PACKAGE_HXX #define _ZIP_PACKAGE_HXX -#include <cppuhelper/implbase8.hxx> +#include <cppuhelper/implbase7.hxx> #include <com/sun/star/lang/XInitialization.hpp> -#include <com/sun/star/container/XEnumerationAccess.hpp> #include <com/sun/star/container/XHierarchicalNameAccess.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/util/XChangesBatch.hpp> @@ -64,13 +63,12 @@ enum InitialisationMode e_IMode_XStream }; -class ZipPackage : public cppu::WeakImplHelper8 +class ZipPackage : public cppu::WeakImplHelper7 < com::sun::star::lang::XInitialization, com::sun::star::lang::XSingleServiceFactory, com::sun::star::lang::XUnoTunnel, com::sun::star::lang::XServiceInfo, - com::sun::star::container::XEnumerationAccess, com::sun::star::container::XHierarchicalNameAccess, com::sun::star::util::XChangesBatch, com::sun::star::beans::XPropertySet @@ -143,14 +141,6 @@ public: // XInitialization virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - // XEnumerationAccess - virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration() - throw(::com::sun::star::uno::RuntimeException); - // XElementType - virtual ::com::sun::star::uno::Type SAL_CALL getElementType() - throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL hasElements() - throw(::com::sun::star::uno::RuntimeException); // XHierarchicalNameAccess virtual ::com::sun::star::uno::Any SAL_CALL getByHierarchicalName( const OUString& aName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index bf0e026..f20b1f0 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -66,7 +66,6 @@ #include <osl/time.h> #include "com/sun/star/io/XAsyncOutputMonitor.hpp" -#include <cassert> #include <cstring> #include <memory> #include <vector> @@ -778,30 +777,6 @@ void SAL_CALL ZipPackage::initialize( const uno::Sequence< Any >& aArguments ) } } -::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL ZipPackage::createEnumeration() - throw( RuntimeException ) -{ - assert(m_pRootFolder); - - return m_pRootFolder->createEnumeration(); -} - -::com::sun::star::uno::Type SAL_CALL ZipPackage::getElementType() - throw( RuntimeException ) -{ - assert(m_pRootFolder); - - return m_pRootFolder->getElementType(); -} - -sal_Bool SAL_CALL ZipPackage::hasElements() - throw( RuntimeException ) -{ - assert(m_pRootFolder); - - return m_pRootFolder->hasElements(); -} - Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName ) throw( NoSuchElementException, RuntimeException ) { commit 04a9214fbf6da2ec9fa36fca4bb949d8f712c982 Author: David Tardon <dtar...@redhat.com> Date: Thu Jan 16 13:22:26 2014 +0100 css::packages::Packages is a wrong choice Change-Id: I7d27e7f320633c176fb9fb0a5f64e891fff6c4d7 diff --git a/writerperfect/source/common/WPXSvStream.cxx b/writerperfect/source/common/WPXSvStream.cxx index 0084ec3..6bb14d2 100644 --- a/writerperfect/source/common/WPXSvStream.cxx +++ b/writerperfect/source/common/WPXSvStream.cxx @@ -9,13 +9,11 @@ #include "WPXSvStream.hxx" -#include <com/sun/star/container/XEnumerationAccess.hpp> -#include <com/sun/star/container/XHierarchicalNameAccess.hpp> -#include <com/sun/star/container/XNamed.hpp> -#include <com/sun/star/io/XActiveDataSink.hpp> +#include <com/sun/star/packages/zip/XZipFileAccess2.hpp> #include <com/sun/star/uno/Any.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/seekableinput.hxx> #include <rtl/string.hxx> #include <tools/stream.hxx> @@ -263,8 +261,6 @@ struct ZipStreamData rtl::OString aName; }; -typedef boost::unordered_map<rtl::OUString, Reference<XInputStream>, rtl::OUStringHash> ZipStorageMap_t; - /** Representation of a Zip storage. * * This is quite similar to OLEStorageImpl, except that we do not need @@ -272,7 +268,7 @@ typedef boost::unordered_map<rtl::OUString, Reference<XInputStream>, rtl::OUStri */ struct ZipStorageImpl { - ZipStorageImpl(const Reference<container::XHierarchicalNameAccess> &rxRoot); + ZipStorageImpl(const Reference<container::XNameAccess> &rxContainer); /** Initialize for access. * @@ -286,12 +282,12 @@ struct ZipStorageImpl Reference<XInputStream> getStream(std::size_t nId); private: - void traverse(const Reference<container::XEnumeration> &rxEnum, const rtl::OUString &rPath); + void traverse(const Reference<container::XNameAccess> &rxEnum); Reference<XInputStream> createStream(const rtl::OUString &rPath); public: - Reference<container::XHierarchicalNameAccess> mxRoot; //< root of the Zip + Reference<container::XNameAccess> mxContainer; //< root of the Zip ::std::vector< ZipStreamData > maStreams; //< list of streams and their names NameMap_t maNameMap; //< map of stream names to indexes (into @c maStreams) bool mbInitialized; @@ -303,21 +299,18 @@ ZipStreamData::ZipStreamData(const rtl::OString &rName) { } -ZipStorageImpl::ZipStorageImpl(const Reference<container::XHierarchicalNameAccess> &rxRoot) - : mxRoot(rxRoot) +ZipStorageImpl::ZipStorageImpl(const Reference<container::XNameAccess> &rxContainer) + : mxContainer(rxContainer) , maStreams() , maNameMap() , mbInitialized(false) { - assert(mxRoot.is()); + assert(mxContainer.is()); } void ZipStorageImpl::initialize() { - const Reference<container::XEnumerationAccess> xEnum(mxRoot, UNO_QUERY); - - if (xEnum.is()) - traverse(xEnum->createEnumeration(), ""); + traverse(mxContainer); mbInitialized = true; } @@ -346,39 +339,18 @@ Reference<XInputStream> ZipStorageImpl::getStream(const std::size_t nId) return maStreams[nId].xStream; } -void ZipStorageImpl::traverse(const Reference<container::XEnumeration> &rxEnum, const rtl::OUString &rPath) +void ZipStorageImpl::traverse(const Reference<container::XNameAccess> &rxContainer) { - while (rxEnum->hasMoreElements()) - { - Any aItem; - try - { - aItem = rxEnum->nextElement(); - } - catch (const Exception &) - { - continue; - } - - const Reference<container::XNamed> xNamed(aItem, UNO_QUERY); - const Reference<XActiveDataSink> xSink(aItem, UNO_QUERY); - const Reference<container::XEnumerationAccess> xEnum(aItem, UNO_QUERY); + const Sequence<rtl::OUString> lNames = rxContainer->getElementNames(); - if (xSink.is() && xNamed.is()) - { - maStreams.push_back(ZipStreamData(rtl::OUStringToOString(xNamed->getName(), RTL_TEXTENCODING_UTF8))); - maNameMap[concatPath(rPath, xNamed->getName())] = maStreams.size() - 1; - } - else if (xEnum.is() && xNamed.is()) - { - const rtl::OUString aPath = concatPath(rPath, xNamed->getName()); + maStreams.reserve(lNames.getLength()); - // deep-first traversal - traverse(xEnum->createEnumeration(), aPath); - } - else + for (sal_Int32 n = 0; n < lNames.getLength(); ++n) + { + if (!lNames[n].endsWithAsciiL("/", 1)) // skip dirs { - assert(0); + maStreams.push_back(ZipStreamData(rtl::OUStringToOString(lNames[n], RTL_TEXTENCODING_UTF8))); + maNameMap[lNames[n]] = maStreams.size() - 1; } } } @@ -389,8 +361,13 @@ Reference<XInputStream> ZipStorageImpl::createStream(const rtl::OUString &rPath) try { - const Reference<XActiveDataSink> xSink(mxRoot->getByHierarchicalName(rPath), UNO_QUERY_THROW); - xStream.set(xSink->getInputStream(), UNO_QUERY_THROW); + const Reference<XInputStream> xInputStream(mxContainer->getByName(rPath), UNO_QUERY_THROW); + const Reference<XSeekable> xSeekable(xInputStream, UNO_QUERY); + + if (xSeekable.is()) + xStream = xInputStream; + else + xStream.set(new comphelper::OSeekableInputWrapper(xInputStream, comphelper::getProcessComponentContext())); } catch (const Exception &) { @@ -431,6 +408,7 @@ private: void ensureZipIsInitialized(); WPXInputStream *createWPXStream(const SotStorageStreamRef &rxStorage); + WPXInputStream *createWPXStream(const Reference<XInputStream> &rxStream); private: ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > mxStream; @@ -673,7 +651,7 @@ WPXInputStream *WPXSvInputStreamImpl::getSubStreamByName(const char *const name) try { - return new WPXSvInputStream(mpZipStorage->getStream(aName)); + return createWPXStream(mpZipStorage->getStream(aName)); } catch (const Exception &) { @@ -713,7 +691,7 @@ WPXInputStream *WPXSvInputStreamImpl::getSubStreamById(const unsigned id) try { - return new WPXSvInputStream(mpZipStorage->getStream(id)); + return createWPXStream(mpZipStorage->getStream(id)); } catch (const Exception &) { @@ -743,6 +721,14 @@ WPXInputStream *WPXSvInputStreamImpl::createWPXStream(const SotStorageStreamRef return 0; } +WPXInputStream *WPXSvInputStreamImpl::createWPXStream(const Reference<XInputStream> &rxStream) +{ + if (rxStream.is()) + return new WPXSvInputStream( rxStream ); + else + return 0; +} + bool WPXSvInputStreamImpl::isOLE() { if (!mbCheckedOLE) @@ -771,10 +757,10 @@ bool WPXSvInputStreamImpl::isZip() aArgs[0] <<= mxStream; const Reference<XComponentContext> xContext(comphelper::getProcessComponentContext(), UNO_QUERY_THROW); - const Reference<container::XHierarchicalNameAccess> xZipStorage( - xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.packages.Package", aArgs, xContext), + const Reference<packages::zip::XZipFileAccess2> xZip( + xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.packages.zip.ZipFileAccess", aArgs, xContext), UNO_QUERY_THROW); - mpZipStorage.reset(new ZipStorageImpl(xZipStorage)); + mpZipStorage.reset(new ZipStorageImpl(xZip)); } catch (const Exception &) { commit 28619201e92aea86a938dd57ed7f79c22d14d89c Author: David Tardon <dtar...@redhat.com> Date: Thu Jan 16 16:15:10 2014 +0100 do not close input, unless it was us who opened it Change-Id: I6ffedd1e64e48b4fc4bd6f5eb63e96b49f1a8508 diff --git a/package/inc/zipfileaccess.hxx b/package/inc/zipfileaccess.hxx index 59d2acc..6b1c1cdc 100644 --- a/package/inc/zipfileaccess.hxx +++ b/package/inc/zipfileaccess.hxx @@ -51,6 +51,7 @@ class OZipFileAccess : public ::cppu::WeakImplHelper4< ::cppu::OInterfaceContainerHelper* m_pListenersContainer; sal_Bool m_bDisposed; + bool m_bOwnContent; public: OZipFileAccess( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ); diff --git a/package/source/zippackage/zipfileaccess.cxx b/package/source/zippackage/zipfileaccess.cxx index 17c5cf2..3139c10 100644 --- a/package/source/zippackage/zipfileaccess.cxx +++ b/package/source/zippackage/zipfileaccess.cxx @@ -43,6 +43,7 @@ OZipFileAccess::OZipFileAccess( const uno::Reference< uno::XComponentContext >& , m_pZipFile( NULL ) , m_pListenersContainer( NULL ) , m_bDisposed( sal_False ) +, m_bOwnContent( false ) { if ( !rxContext.is() ) throw uno::RuntimeException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() ); @@ -188,6 +189,7 @@ void SAL_CALL OZipFileAccess::initialize( const uno::Sequence< uno::Any >& aArgu if ( aContent.openStream ( xSink ) ) { m_xContentStream = xSink->getInputStream(); + m_bOwnContent = true; xSeekable = uno::Reference< io::XSeekable >( m_xContentStream, uno::UNO_QUERY ); } } @@ -385,7 +387,7 @@ void SAL_CALL OZipFileAccess::dispose() m_pZipFile = NULL; } - if ( m_xContentStream.is() ) + if ( m_xContentStream.is() && m_bOwnContent ) try { m_xContentStream->closeInput(); } catch( uno::Exception& ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits