[Libreoffice-commits] core.git: xmloff/inc xmloff/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Wed Nov 4 05:34:58 UTC 2020


 xmloff/inc/XMLEmbeddedObjectImportContext.hxx         |    8 -
 xmloff/source/core/XMLEmbeddedObjectImportContext.cxx |   95 +++++++-----------
 2 files changed, 42 insertions(+), 61 deletions(-)

New commits:
commit 81fe31d2c8977791f9b90ab1da4fbb1a778f87fb
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Tue Nov 3 18:25:10 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Nov 4 06:34:20 2020 +0100

    use fastparser in XMLEmbeddedObjectImportContext
    
    Change-Id: I5fc61239e60a3129b350895293760a345baf3ce5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105260
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/xmloff/inc/XMLEmbeddedObjectImportContext.hxx b/xmloff/inc/XMLEmbeddedObjectImportContext.hxx
index 22f30adad79b..7f2a739e07af 100644
--- a/xmloff/inc/XMLEmbeddedObjectImportContext.hxx
+++ b/xmloff/inc/XMLEmbeddedObjectImportContext.hxx
@@ -20,14 +20,14 @@
 #ifndef INCLUDED_XMLOFF_INC_XMLEMBEDDEDOBJECTIMPORTCONTEXT_HXX
 #define INCLUDED_XMLOFF_INC_XMLEMBEDDEDOBJECTIMPORTCONTEXT_HXX
 
-#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
 #include <xmloff/xmlictxt.hxx>
 
 namespace com::sun::star::lang { class XComponent; }
 
 class XMLEmbeddedObjectImportContext final : public SvXMLImportContext
 {
-    css::uno::Reference<css::xml::sax::XDocumentHandler > xHandler;
+    css::uno::Reference<css::xml::sax::XFastDocumentHandler > mxFastHandler;
     css::uno::Reference<css::lang::XComponent > xComp;
 
     OUString sFilterService;
@@ -48,7 +48,9 @@ public:
                                    const OUString& rLocalName,
                                    const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
 
-    virtual void StartElement( const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
+    virtual void SAL_CALL startFastElement(
+            sal_Int32 nElement,
+            const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
 
     virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
 
diff --git a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx
index 3b763d7eeab6..bfb182edaf3d 100644
--- a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx
+++ b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx
@@ -47,19 +47,21 @@ namespace {
 
 class XMLEmbeddedObjectImportContext_Impl : public SvXMLImportContext
 {
-    css::uno::Reference< css::xml::sax::XDocumentHandler > xHandler;
+    css::uno::Reference< css::xml::sax::XFastDocumentHandler > mxFastHandler;
 
 public:
 
     XMLEmbeddedObjectImportContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
                                     const OUString& rLName,
-    const css::uno::Reference< css::xml::sax::XDocumentHandler >& rHandler );
+                                    const css::uno::Reference< css::xml::sax::XFastDocumentHandler >& rHandler );
 
     virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
                                    const OUString& rLocalName,
                                    const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
 
-    virtual void StartElement( const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
+    virtual void SAL_CALL startFastElement(
+                        sal_Int32 nElement,
+                        const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
 
     virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
 
@@ -71,40 +73,37 @@ public:
 XMLEmbeddedObjectImportContext_Impl::XMLEmbeddedObjectImportContext_Impl(
         SvXMLImport& rImport, sal_uInt16 nPrfx,
         const OUString& rLName,
-        const Reference< XDocumentHandler >& rHandler ) :
+        const Reference< XFastDocumentHandler >& rHandler ) :
     SvXMLImportContext( rImport, nPrfx, rLName ),
-    xHandler( rHandler )
+    mxFastHandler( rHandler )
 {
-    assert(xHandler);
+    assert(mxFastHandler);
 }
 
 SvXMLImportContextRef XMLEmbeddedObjectImportContext_Impl::CreateChildContext(
-        sal_uInt16 nPrefix,
-        const OUString& rLocalName,
+        sal_uInt16 /*nPrefix*/,
+        const OUString& /*rLocalName*/,
         const Reference< XAttributeList >& )
 {
-    return new XMLEmbeddedObjectImportContext_Impl( GetImport(),
-                                                    nPrefix, rLocalName,
-                                                    xHandler );
+    // we carry no state, so just re-use the same instance
+    return this;
 }
 
-void XMLEmbeddedObjectImportContext_Impl::StartElement(
-        const Reference< XAttributeList >& xAttrList )
+void XMLEmbeddedObjectImportContext_Impl::startFastElement(
+        sal_Int32 nElement,
+        const Reference< XFastAttributeList >& xAttrList )
 {
-    xHandler->startElement( GetImport().GetNamespaceMap().GetQNameByKey(
-                                GetPrefix(), GetLocalName() ),
-                            xAttrList );
+    mxFastHandler->startFastElement( nElement, xAttrList );
 }
 
-void XMLEmbeddedObjectImportContext_Impl::endFastElement(sal_Int32 )
+void XMLEmbeddedObjectImportContext_Impl::endFastElement(sal_Int32 nElement)
 {
-    xHandler->endElement( GetImport().GetNamespaceMap().GetQNameByKey(
-                                GetPrefix(), GetLocalName() ) );
+    mxFastHandler->endFastElement( nElement );
 }
 
 void XMLEmbeddedObjectImportContext_Impl::characters( const OUString& rChars )
 {
-    xHandler->characters( rChars );
+    mxFastHandler->characters( rChars );
 }
 
 
@@ -123,12 +122,9 @@ void XMLEmbeddedObjectImportContext::SetComponent( Reference< XComponent > const
     if( !xFilter.is() )
         return;
 
-    if (SvXMLImport *pFastHandler = dynamic_cast<SvXMLImport*>(xFilter.get()))
-        xHandler.set( new SvXMLLegacyToFastDocHandler( pFastHandler ) );
-    else
-        xHandler.set(xFilter, UNO_QUERY);
-
-    assert( xHandler );
+    assert(dynamic_cast<SvXMLImport*>(xFilter.get()));
+    SvXMLImport *pFastHandler = dynamic_cast<SvXMLImport*>(xFilter.get());
+    mxFastHandler = pFastHandler;
 
     try
     {
@@ -139,7 +135,7 @@ void XMLEmbeddedObjectImportContext::SetComponent( Reference< XComponent > const
     {
     }
 
-    Reference < XImporter > xImporter( xHandler, UNO_QUERY );
+    Reference < XImporter > xImporter( mxFastHandler, UNO_QUERY );
     xImporter->setTargetDocument( rComp );
 
     xComp = rComp;  // keep ref to component only if there is a handler
@@ -239,48 +235,31 @@ SvXMLImportContextRef XMLEmbeddedObjectImportContext::CreateChildContext(
         sal_uInt16 nPrefix, const OUString& rLocalName,
         const Reference< XAttributeList >& )
 {
-    if( xHandler.is() )
+    if( mxFastHandler.is() )
         return new XMLEmbeddedObjectImportContext_Impl( GetImport(),
                                                         nPrefix, rLocalName,
-                                                        xHandler );
+                                                        mxFastHandler );
     return nullptr;
 }
 
-void XMLEmbeddedObjectImportContext::StartElement(
-        const Reference< XAttributeList >& rAttrList )
+void XMLEmbeddedObjectImportContext::startFastElement(
+        sal_Int32 nElement,
+        const Reference< XFastAttributeList >& rAttrList )
 {
-    if( !xHandler.is() )
+    if( !mxFastHandler.is() )
         return;
 
-    xHandler->startDocument();
-    // #i34042: copy namepspace declarations
-    SvXMLAttributeList *pAttrList = new SvXMLAttributeList( rAttrList );
-    Reference< XAttributeList > xAttrList( pAttrList );
-    const SvXMLNamespaceMap& rNamespaceMap = GetImport().GetNamespaceMap();
-    sal_uInt16 nPos = rNamespaceMap.GetFirstKey();
-    while( USHRT_MAX != nPos )
-    {
-        OUString aAttrName = "xmlns:" + rNamespaceMap.GetPrefixByKey( nPos );
-        if( xAttrList->getValueByName( aAttrName ).isEmpty() )
-        {
-            pAttrList->AddAttribute( aAttrName,
-                                      rNamespaceMap.GetNameByKey( nPos ) );
-        }
-        nPos = rNamespaceMap.GetNextKey( nPos );
-    }
-    xHandler->startElement( GetImport().GetNamespaceMap().GetQNameByKey(
-                                GetPrefix(), GetLocalName() ),
-                            xAttrList );
+    mxFastHandler->startDocument();
+    mxFastHandler->startFastElement( nElement, rAttrList );
 }
 
-void XMLEmbeddedObjectImportContext::endFastElement(sal_Int32 )
+void XMLEmbeddedObjectImportContext::endFastElement(sal_Int32 nElement)
 {
-    if( !xHandler.is() )
+    if( !mxFastHandler.is() )
         return;
 
-    xHandler->endElement( GetImport().GetNamespaceMap().GetQNameByKey(
-                                GetPrefix(), GetLocalName() ) );
-    xHandler->endDocument();
+    mxFastHandler->endFastElement( nElement );
+    mxFastHandler->endDocument();
 
     try
     {
@@ -295,8 +274,8 @@ void XMLEmbeddedObjectImportContext::endFastElement(sal_Int32 )
 
 void XMLEmbeddedObjectImportContext::characters( const OUString& rChars )
 {
-    if( xHandler.is() )
-        xHandler->characters( rChars );
+    if( mxFastHandler.is() )
+        mxFastHandler->characters( rChars );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list