[Libreoffice-commits] core.git: writerfilter/source

Oliver-Rainer Wittmann orw at apache.org
Mon Jun 10 11:05:27 PDT 2013


 writerfilter/source/ooxml/OOXMLDocumentImpl.cxx        |   12 +--
 writerfilter/source/ooxml/OOXMLFastContextHandler.cxx  |    3 
 writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx |   62 +++++++++--------
 writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx |   11 +--
 writerfilter/source/ooxml/OOXMLParserState.cxx         |    3 
 5 files changed, 43 insertions(+), 48 deletions(-)

New commits:
commit d94bda0c1fd3c618b98a63f76d71e129ad06d942
Author: Oliver-Rainer Wittmann <orw at apache.org>
Date:   Mon Jun 10 16:51:54 2013 +0100

    Correct the XML document handler...
    
    which is used to parse Microsoft Word OOXML documents in case of unknown XML
    elements
    
    (cherry picked from commit 22e334845346f4e3189c72e706d744385953af19)
    
    Conflicts:
    	writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
    	writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx
    	writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx
    
    Change-Id: Ibcd3e808abfb35291bb04aa10190a7800f0837fa

diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
index 29c64ad..09ded15 100644
--- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
@@ -66,10 +66,8 @@ void OOXMLDocumentImpl::resolveFastSubStream(Stream & rStreamHandler,
     {
         uno::Reference<uno::XComponentContext> xContext(mpStream->getContext());
         OOXMLFastDocumentHandler * pDocHandler =
-            new OOXMLFastDocumentHandler(xContext);
-        pDocHandler->setStream(&rStreamHandler);
-        pDocHandler->setDocument(this);
-        pDocHandler->setXNoteId(mnXNoteId);
+            new OOXMLFastDocumentHandler(
+                xContext, &rStreamHandler, this, mnXNoteId );
 
         uno::Reference < xml::sax::XFastDocumentHandler > xDocumentHandler
             (pDocHandler);
@@ -317,10 +315,8 @@ void OOXMLDocumentImpl::resolve(Stream & rStream)
         uno::Reference<uno::XComponentContext> xContext(mpStream->getContext());
 
         OOXMLFastDocumentHandler * pDocHandler =
-            new OOXMLFastDocumentHandler(xContext);
-        pDocHandler->setStream(&rStream);
-        pDocHandler->setDocument(this);
-        pDocHandler->setXNoteId(mnXNoteId);
+            new OOXMLFastDocumentHandler(
+                xContext, &rStream, this, mnXNoteId );
         pDocHandler->setIsSubstream( mbIsSubstream );
         uno::Reference < xml::sax::XFastDocumentHandler > xDocumentHandler
             (pDocHandler);
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index fc6eb3e..3adc48b 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -1340,9 +1340,6 @@ void OOXMLFastContextHandlerProperties::lcl_endFastElement
     {
         if (isForwardEvents())
         {
-            SAL_WARN_IF(!mpStream, "writerfilter", "no stream to set properties on");
-            if (!mpStream)
-                return;
             mpStream->props(mpPropertySet);
         }
     }
diff --git a/writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx b/writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx
index f6f6b60..893ed74 100644
--- a/writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx
@@ -35,10 +35,28 @@ using namespace ::com::sun::star;
 using namespace ::std;
 
 
-OOXMLFastDocumentHandler::OOXMLFastDocumentHandler
-(uno::Reference< uno::XComponentContext > const & context)
-: m_xContext(context), mpStream(0), mpDocument(0)
-{}
+OOXMLFastDocumentHandler::OOXMLFastDocumentHandler(
+    uno::Reference< uno::XComponentContext > const & context,
+    Stream* pStream,
+    OOXMLDocument* pDocument,
+    sal_Int32 nXNoteId )
+    : m_xContext(context)
+    , mpStream( pStream )
+#ifdef DEBUG_ELEMENT
+    , mpTmpStream()
+#endif
+    , mpDocument( pDocument )
+    , mnXNoteId( nXNoteId )
+    , mpContextHandler()
+{
+#ifdef DEBUG_PROTOCOL
+    if ( pStream )
+    {
+        mpTmpStream.reset( new StreamProtocol( pStream, debug_logger ) );
+        mpStream = mpTmpStream.get();
+    }
+#endif
+}
 
 // ::com::sun::star::xml::sax::XFastContextHandler:
 void SAL_CALL OOXMLFastDocumentHandler::startFastElement
@@ -141,6 +159,13 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
          << endl;
 #endif
 
+    if ( mpStream == 0 && mpDocument == 0 )
+    {
+        // document handler has been created as unknown child - see <OOXMLFastDocumentHandler::createUnknownChildContext(..)>
+        // --> do not provide a child context
+        return NULL;
+    }
+
     return OOXMLFactory::getInstance()->createFastChildContextFromStart(getContextHandler().get(), Element);
 }
 
@@ -167,13 +192,12 @@ Name
 #endif
 
     return uno::Reference< xml::sax::XFastContextHandler >
-        (new OOXMLFastDocumentHandler(m_xContext));
+        ( new OOXMLFastDocumentHandler( m_xContext, 0, 0, 0 ) );
 }
 
 void SAL_CALL OOXMLFastDocumentHandler::characters(const OUString & /*aChars*/)
     throw (uno::RuntimeException, xml::sax::SAXException)
 {
-    // TODO: Insert your implementation for "characters" here.
 }
 
 // ::com::sun::star::xml::sax::XFastDocumentHandler:
@@ -191,32 +215,14 @@ void SAL_CALL OOXMLFastDocumentHandler::setDocumentLocator
 (const uno::Reference< xml::sax::XLocator > & /*xLocator*/)
     throw (uno::RuntimeException, xml::sax::SAXException)
 {
-    // TODO: Insert your implementation for "setDocumentLocator" here.
-}
-
-void OOXMLFastDocumentHandler::setStream(Stream * pStream)
-{
-#ifdef DEBUG_PROTOCOL
-    mpTmpStream.reset(new StreamProtocol(pStream, debug_logger));
-    mpStream = mpTmpStream.get();
-#else
-    mpStream = pStream;
-#endif
-}
-
-void OOXMLFastDocumentHandler::setDocument(OOXMLDocument * pDocument)
-{
-    mpDocument = pDocument;
-}
-
-void OOXMLFastDocumentHandler::setXNoteId(const sal_Int32 nXNoteId)
-{
-    mnXNoteId = nXNoteId;
 }
 
 void OOXMLFastDocumentHandler::setIsSubstream( bool bSubstream )
 {
-    getContextHandler( )->getParserState( )->setInSectionGroup( bSubstream );
+    if ( mpStream != 0 && mpDocument != 0 )
+    {
+        getContextHandler( )->getParserState( )->setInSectionGroup( bSubstream );
+    }
 }
 
 }}
diff --git a/writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx b/writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx
index 50f0632..9272318 100644
--- a/writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx
@@ -40,8 +40,11 @@ class OOXMLFastDocumentHandler:
         xml::sax::XFastDocumentHandler>
 {
 public:
-    OOXMLFastDocumentHandler
-    (uno::Reference< uno::XComponentContext > const & context);
+    OOXMLFastDocumentHandler(
+        uno::Reference< uno::XComponentContext > const & context,
+        Stream* pStream,
+        OOXMLDocument* pDocument,
+        sal_Int32 nXNoteId );
     virtual ~OOXMLFastDocumentHandler() {}
 
     // ::com::sun::star::xml::sax::XFastDocumentHandler:
@@ -83,10 +86,6 @@ public:
     virtual void SAL_CALL characters(const OUString & aChars)
         throw (uno::RuntimeException, xml::sax::SAXException);
 
-    void setStream(Stream * pStream);
-    void setDocument(OOXMLDocument * pDocument);
-    void setXNoteId(const sal_Int32 nXNoteId);
-
     void setIsSubstream( bool bSubstream );
 
 private:
diff --git a/writerfilter/source/ooxml/OOXMLParserState.cxx b/writerfilter/source/ooxml/OOXMLParserState.cxx
index 1b9b426..d8b562b 100644
--- a/writerfilter/source/ooxml/OOXMLParserState.cxx
+++ b/writerfilter/source/ooxml/OOXMLParserState.cxx
@@ -125,9 +125,6 @@ OOXMLDocument * OOXMLParserState::getDocument() const
 
 void OOXMLParserState::setXNoteId(const sal_Int32 nId)
 {
-    SAL_WARN_IF(!mpDocument, "writerfilter", "no document to set note id on");
-    if (!mpDocument)
-        return;
     mpDocument->setXNoteId(nId);
 }
 


More information about the Libreoffice-commits mailing list