Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Hi guys,

        I've not worked out where these odd ZIP container inconsistencies are
coming from, but ... since people appear to see them, presumably it's
worth being more accepting:

        Not 100% confident about this, the more I read SfxMedium & friends, the
more convinced I am we need some root+branch stream re-work, but hey.

        I'd love someone expert in writerfilter to review it, and (IMHO) we
need to do the same work for PPTX / XLSX to ensure that we can prompt
and enter the Repair mode. Then I think we need to undo the hack that is
the fix for bug#54609 :-)

        Thoughts appreciated.

                Michael.

-- 
michael.meeks@suse.com  <><, Pseudo Engineer, itinerant idiot
From ff300e59e74ee88aa6a4981b57a51af416c9e991 Mon Sep 17 00:00:00 2001
From: Michael Meeks <michael.meeks@suse.com>
Date: Fri, 21 Sep 2012 21:32:11 +0100
Subject: [PATCH] fdo#49819 - allow slightly inconsistent docx files to be
 repaired

---
 sfx2/source/doc/objstor.cxx                        |    8 +++++++-
 writerfilter/inc/dmapper/DomainMapper.hxx          |    3 ++-
 writerfilter/inc/ooxml/OOXMLDocument.hxx           |    1 +
 writerfilter/source/dmapper/DomainMapper.cxx       |    6 +++---
 writerfilter/source/filter/ImportFilter.cxx        |    7 +++----
 writerfilter/source/filter/RtfFilter.cxx           |    3 ++-
 writerfilter/source/ooxml/OOXMLStreamImpl.cxx      |    9 ++++++---
 writerfilter/source/ooxml/OOXMLStreamImpl.hxx      |    2 +-
 .../debugservices/ooxml/OOXMLAnalyzeService.cxx    |    2 +-
 .../debugservices/ooxml/OOXMLTestService.cxx       |    2 +-
 10 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index cf8d0c2..9e7407a 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -33,6 +33,7 @@
 #include <com/sun/star/document/XExporter.hpp>
 #include <com/sun/star/document/FilterOptionsRequest.hpp>
 #include <com/sun/star/document/XInteractionFilterOptions.hpp>
+#include <com/sun/star/packages/zip/ZipIOException.hpp>
 #include <com/sun/star/task/XInteractionHandler.hpp>
 #include <com/sun/star/task/XInteractionAskLater.hpp>
 #include <com/sun/star/task/FutureDocumentVersionProductUpdateRequest.hpp>
@@ -2219,7 +2220,12 @@ sal_Bool SfxObjectShell::ImportFrom( SfxMedium& rMedium, bool bInsert )
         }
 
         return xLoader->filter( aArgs );
-        }catch(...)
+        }
+        catch (const packages::zip::ZipIOException&)
+        {
+            SetError( ERRCODE_IO_BROKENPACKAGE, "Badness in the underlying package format." );
+        }
+        catch(...)
         {}
     }
 
diff --git a/writerfilter/inc/dmapper/DomainMapper.hxx b/writerfilter/inc/dmapper/DomainMapper.hxx
index 4dbbe87..1d9b2f0 100644
--- a/writerfilter/inc/dmapper/DomainMapper.hxx
+++ b/writerfilter/inc/dmapper/DomainMapper.hxx
@@ -80,7 +80,8 @@ public:
     DomainMapper(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext 
& xContext,
                                 ::com::sun::star::uno::Reference< 
::com::sun::star::io::XInputStream > xInputStream,
                                 ::com::sun::star::uno::Reference< 
::com::sun::star::lang::XComponent > xModel,
-                                SourceDocumentType eDocumentType );
+                                bool bRepairStorage,
+                                SourceDocumentType eDocumentType);
     virtual ~DomainMapper();
 
     // Stream
diff --git a/writerfilter/inc/ooxml/OOXMLDocument.hxx b/writerfilter/inc/ooxml/OOXMLDocument.hxx
index f3365db..c97e2b2 100644
--- a/writerfilter/inc/ooxml/OOXMLDocument.hxx
+++ b/writerfilter/inc/ooxml/OOXMLDocument.hxx
@@ -248,6 +248,7 @@ public:
     static OOXMLStream::Pointer_t
     createStream(uno::Reference<uno::XComponentContext> rContext,
                  uno::Reference<io::XInputStream> rStream,
+                 bool bRepairStorage,
                  OOXMLStream::StreamType_t nStreamType = OOXMLStream::DOCUMENT);
 
     static OOXMLStream::Pointer_t
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx 
b/writerfilter/source/dmapper/DomainMapper.cxx
index 38a9961..cd4a17c 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -88,7 +88,8 @@ struct _PageSz
 DomainMapper::DomainMapper( const uno::Reference< uno::XComponentContext >& xContext,
                             uno::Reference< io::XInputStream > xInputStream,
                             uno::Reference< lang::XComponent > xModel,
-                            SourceDocumentType eDocumentType) :
+                            bool bRepairStorage,
+                            SourceDocumentType eDocumentType ) :
 LoggedProperties(dmapper_logger, "DomainMapper"),
 LoggedTable(dmapper_logger, "DomainMapper"),
 LoggedStream(dmapper_logger, "DomainMapper"),
@@ -101,12 +102,11 @@ LoggedStream(dmapper_logger, "DomainMapper"),
         uno::makeAny( false ) );
 
     //import document properties
-
     try
     {
         uno::Reference< lang::XMultiServiceFactory > xFactory(xContext->getServiceManager(), 
uno::UNO_QUERY_THROW);
         uno::Reference< embed::XStorage > xDocumentStorage =
-            
(comphelper::OStorageHelper::GetStorageOfFormatFromInputStream(OFOPXML_STORAGE_FORMAT_STRING, 
xInputStream));
+            
(comphelper::OStorageHelper::GetStorageOfFormatFromInputStream(OFOPXML_STORAGE_FORMAT_STRING, 
xInputStream, xFactory, bRepairStorage ));
 
         uno::Reference< uno::XInterface > xTemp = 
xContext->getServiceManager()->createInstanceWithContext(
                                 "com.sun.star.document.OOXMLDocumentPropertiesImporter",
diff --git a/writerfilter/source/filter/ImportFilter.cxx 
b/writerfilter/source/filter/ImportFilter.cxx
index 2eef1c1..207342a 100644
--- a/writerfilter/source/filter/ImportFilter.cxx
+++ b/writerfilter/source/filter/ImportFilter.cxx
@@ -63,6 +63,7 @@ sal_Bool WriterFilter::filter( const uno::Sequence< beans::PropertyValue >& aDes
     else if (m_xDstDoc.is())
     {
         MediaDescriptor aMediaDesc( aDescriptor );
+        bool bRepairStorage = aMediaDesc.getUnpackedValueOrDefault( "RepairPackage", false );
         OUString sFilterName = aMediaDesc.getUnpackedValueOrDefault( 
MediaDescriptor::PROP_FILTERNAME(), OUString() );
 
         uno::Reference< io::XInputStream > xInputStream;
@@ -77,9 +78,7 @@ sal_Bool WriterFilter::filter( const uno::Sequence< beans::PropertyValue >& aDes
         }
 
         if ( !xInputStream.is() )
-        {
             return sal_False;
-        }
 
 #ifdef DEBUG_IMPORT
         OUString sURL = aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_URL(), 
OUString() );
@@ -101,11 +100,11 @@ sal_Bool WriterFilter::filter( const uno::Sequence< beans::PropertyValue >& 
aDes
          m_sFilterName == "writer_OOXML" || m_sFilterName == "writer_OOXML_Text_Template" ) ?
             writerfilter::dmapper::DOCUMENT_OOXML : writerfilter::dmapper::DOCUMENT_DOC;
 
-    writerfilter::Stream::Pointer_t pStream(new writerfilter::dmapper::DomainMapper(m_xContext, 
xInputStream, m_xDstDoc, eType));
+    writerfilter::Stream::Pointer_t pStream(new writerfilter::dmapper::DomainMapper(m_xContext, 
xInputStream, m_xDstDoc, bRepairStorage, eType));
     //create the tokenizer and domain mapper
     if( eType == writerfilter::dmapper::DOCUMENT_OOXML )
     {
-        writerfilter::ooxml::OOXMLStream::Pointer_t pDocStream = 
writerfilter::ooxml::OOXMLDocumentFactory::createStream(m_xContext, xInputStream);
+        writerfilter::ooxml::OOXMLStream::Pointer_t pDocStream = 
writerfilter::ooxml::OOXMLDocumentFactory::createStream(m_xContext, xInputStream, bRepairStorage);
         writerfilter::ooxml::OOXMLDocument::Pointer_t 
pDocument(writerfilter::ooxml::OOXMLDocumentFactory::createDocument(pDocStream));
 
         uno::Reference<frame::XModel> xModel(m_xDstDoc, uno::UNO_QUERY_THROW);
diff --git a/writerfilter/source/filter/RtfFilter.cxx b/writerfilter/source/filter/RtfFilter.cxx
index b071449..080f8ad 100644
--- a/writerfilter/source/filter/RtfFilter.cxx
+++ b/writerfilter/source/filter/RtfFilter.cxx
@@ -66,6 +66,7 @@ sal_Bool RtfFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescri
     try
     {
         MediaDescriptor aMediaDesc( aDescriptor );
+        bool bRepairStorage = aMediaDesc.getUnpackedValueOrDefault( "RepairPackage", false );
 #ifdef DEBUG_IMPORT
         OUString sURL = aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_URL(), 
OUString() );
         ::std::string sURLc = OUStringToOString(sURL, RTL_TEXTENCODING_ASCII_US).getStr();
@@ -87,7 +88,7 @@ sal_Bool RtfFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescri
                 uno::Reference<task::XStatusIndicator>());
 
         writerfilter::Stream::Pointer_t pStream(
-                new writerfilter::dmapper::DomainMapper(m_xContext, xInputStream, m_xDstDoc, 
writerfilter::dmapper::DOCUMENT_RTF));
+                new writerfilter::dmapper::DomainMapper(m_xContext, xInputStream, m_xDstDoc, 
bRepairStorage, writerfilter::dmapper::DOCUMENT_RTF));
         writerfilter::rtftok::RTFDocument::Pointer_t const pDocument(
                 writerfilter::rtftok::RTFDocumentFactory::createDocument(m_xContext, xInputStream, 
m_xDstDoc, xFrame, xStatusIndicator));
         pDocument->resolve(*pStream);
diff --git a/writerfilter/source/ooxml/OOXMLStreamImpl.cxx 
b/writerfilter/source/ooxml/OOXMLStreamImpl.cxx
index 9874740..3ece742 100644
--- a/writerfilter/source/ooxml/OOXMLStreamImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLStreamImpl.cxx
@@ -35,12 +35,14 @@ using namespace ::std;
 
 OOXMLStreamImpl::OOXMLStreamImpl
 (uno::Reference<uno::XComponentContext> xContext,
- uno::Reference<io::XInputStream> xStorageStream, StreamType_t nType)
+ uno::Reference<io::XInputStream> xStorageStream,
+ StreamType_t nType, bool bRepairStorage)
 : mxContext(xContext), mxStorageStream(xStorageStream), mnStreamType(nType)
 {
+    uno::Reference< lang::XMultiServiceFactory > xFactory(xContext->getServiceManager(), 
uno::UNO_QUERY_THROW);
     mxStorage.set
         (comphelper::OStorageHelper::GetStorageOfFormatFromInputStream
-         (OFOPXML_STORAGE_FORMAT_STRING, mxStorageStream));
+         (OFOPXML_STORAGE_FORMAT_STRING, mxStorageStream, xFactory, bRepairStorage));
     mxRelationshipAccess.set(mxStorage, uno::UNO_QUERY_THROW);
 
     init();
@@ -297,10 +299,11 @@ OOXMLStream::Pointer_t
 OOXMLDocumentFactory::createStream
 (uno::Reference<uno::XComponentContext> xContext,
  uno::Reference<io::XInputStream> rStream,
+ bool bRepairStorage,
  OOXMLStream::StreamType_t nStreamType)
 {
     OOXMLStreamImpl * pStream = new OOXMLStreamImpl(xContext, rStream,
-                                                    nStreamType);
+                                                    nStreamType, bRepairStorage);
     return OOXMLStream::Pointer_t(pStream);
 }
 
diff --git a/writerfilter/source/ooxml/OOXMLStreamImpl.hxx 
b/writerfilter/source/ooxml/OOXMLStreamImpl.hxx
index e5d3f33..80065f6 100644
--- a/writerfilter/source/ooxml/OOXMLStreamImpl.hxx
+++ b/writerfilter/source/ooxml/OOXMLStreamImpl.hxx
@@ -61,7 +61,7 @@ public:
     OOXMLStreamImpl
     (uno::Reference<uno::XComponentContext> xContext,
      uno::Reference<io::XInputStream> xStorageStream,
-     StreamType_t nType);
+     StreamType_t nType, bool bRepairStorage);
     OOXMLStreamImpl(OOXMLStreamImpl & rStream, const OUString & rId);
 
     virtual ~OOXMLStreamImpl();
diff --git a/writerfilter/unocomponent/debugservices/ooxml/OOXMLAnalyzeService.cxx 
b/writerfilter/unocomponent/debugservices/ooxml/OOXMLAnalyzeService.cxx
index 7abb841..b8fd242 100644
--- a/writerfilter/unocomponent/debugservices/ooxml/OOXMLAnalyzeService.cxx
+++ b/writerfilter/unocomponent/debugservices/ooxml/OOXMLAnalyzeService.cxx
@@ -173,7 +173,7 @@ sal_Int32 SAL_CALL AnalyzeService::run
             {
                 ooxml::OOXMLStream::Pointer_t pDocStream =
                     ooxml::OOXMLDocumentFactory::createStream
-                    (xContext, xInputStream);
+                    (xContext, xInputStream, false);
 
                 if (pDocStream.get() != NULL)
                 {
diff --git a/writerfilter/unocomponent/debugservices/ooxml/OOXMLTestService.cxx 
b/writerfilter/unocomponent/debugservices/ooxml/OOXMLTestService.cxx
index b6423f0..4d1335b 100644
--- a/writerfilter/unocomponent/debugservices/ooxml/OOXMLTestService.cxx
+++ b/writerfilter/unocomponent/debugservices/ooxml/OOXMLTestService.cxx
@@ -88,7 +88,7 @@ sal_Int32 SAL_CALL ScannerTestService::run( const uno::Sequence< OUString >& aAr
     uno::Reference<io::XInputStream> xInputStream =
         xFileAccess->openFileRead(absFileUrl);
     ooxml::OOXMLStream::Pointer_t pDocStream =
-        ooxml::OOXMLDocumentFactory::createStream(xContext, xInputStream);
+        ooxml::OOXMLDocumentFactory::createStream(xContext, xInputStream, false);
 
     ooxml::OOXMLDocument::Pointer_t pDocument
         (ooxml::OOXMLDocumentFactory::createDocument(pDocStream));
-- 
1.7.7


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.