include/xmloff/xmlimp.hxx       |    6 +++-
 include/xmloff/xmltkmap.hxx     |    2 -
 xmloff/source/core/xmlictxt.cxx |   60 ++++++++++++++++++++++++----------------
 xmloff/source/core/xmlimp.cxx   |   47 ++++++++++++++++++++++++++-----
 4 files changed, 82 insertions(+), 33 deletions(-)

New commits:
commit 67ef208b2b586603e205105a384231645d7f6712
Author: Mohammed Abdul Azeem <azeemmys...@gmail.com>
Date:   Fri Sep 2 01:18:53 2016 +0530

    Fixes for migrating SvXMLImport to use FastParser:
    
    These are necessary for implementing fast interfaces
    for the contexts.
    
    Change-Id: I37655c85c76b42782a49eeea3140490213047341
    Reviewed-on: https://gerrit.libreoffice.org/28641
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>

diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index c673dfc..415ca40 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -61,7 +61,7 @@
 #include <o3tl/typed_flags_set.hxx>
 #include <memory>
 
-#define NAMESPACE_TOKEN( prefixToken ) ( ( prefixToken + 1 ) << NMSP_SHIFT )
+#define NAMESPACE_TOKEN( prefixToken ) ( ( sal_Int32( prefixToken + 1 ) ) << 
NMSP_SHIFT )
 
 const size_t NMSP_SHIFT = 16;
 const sal_Int32 TOKEN_MASK = 0xffff;
@@ -191,6 +191,7 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public 
::cppu::WeakImplHelper8<
     SvXMLImportFlags  mnImportFlags;
     SvXMLErrorFlags  mnErrorFlags;
     std::set< OUString > embeddedFontUrlsKnown;
+    bool isFastContext;
     css::uno::Reference< css::xml::sax::XFastParser > mxParser;
     rtl::Reference< SvXMLImportFastNamespaceHandler > maNamespaceHandler;
     css::uno::Reference< css::xml::sax::XFastTokenHandler > mxTokenHandler;
@@ -199,6 +200,9 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public 
::cppu::WeakImplHelper8<
     const OUString getNamespacePrefixFromToken( sal_Int32 nToken );
     void registerNamespaces();
     void registerNSHelper(sal_Int32 nToken, sal_Int32 nPrefix, sal_Int32 
nNamespace );
+    void processNSAttributes( const css::uno::Reference< 
css::xml::sax::XAttributeList >& xAttrList,
+                            SvXMLNamespaceMap *pRewindMap );
+    void Characters(const OUString& aChars);
 
 protected:
 
diff --git a/include/xmloff/xmltkmap.hxx b/include/xmloff/xmltkmap.hxx
index 89cfd65..c9f0bee 100644
--- a/include/xmloff/xmltkmap.hxx
+++ b/include/xmloff/xmltkmap.hxx
@@ -44,7 +44,7 @@ struct SvXMLTokenMapEntry
         nPrefixKey( nPrefix ),
         eLocalName( eName ),
         nToken( nTok ),
-        nFastToken( sal_uInt32( nPrefixKey + 1 ) << 16 | eLocalName )
+        nFastToken( ( sal_Int32( nPrefixKey + 1 ) ) << 16 | eLocalName )
     {
         if ( nFastTok )     // alternative value for duplicate/dummy tokens
             nFastToken = nFastTok;
diff --git a/xmloff/source/core/xmlictxt.cxx b/xmloff/source/core/xmlictxt.cxx
index f3e27e5..2fb80c5 100644
--- a/xmloff/source/core/xmlictxt.cxx
+++ b/xmloff/source/core/xmlictxt.cxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/xml/sax/XLocator.hpp>
 #include <xmloff/xmlimp.hxx>
 #include <xmloff/xmlictxt.hxx>
+#include <sax/fastattribs.hxx>
 
 using namespace ::com::sun::star;
 
@@ -69,6 +70,7 @@ void SvXMLImportContext::Characters( const OUString& )
 void SAL_CALL SvXMLImportContext::startFastElement(sal_Int32 nElement, const 
uno::Reference< xml::sax::XFastAttributeList > & Attribs)
     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
 {
+    mrImport.isFastContext = false;
     startUnknownElement( mrImport.getNamespacePrefixFromToken( nElement ),
                          mrImport.getNameFromToken( nElement ), Attribs );
 }
@@ -85,38 +87,47 @@ void SAL_CALL SvXMLImportContext::startUnknownElement(const 
OUString & rPrefix,
     else
         elementName = rLocalName;
 
-    uno::Sequence< xml::FastAttribute > fastAttribs = 
Attribs->getFastAttributes();
-    sal_uInt16 len = fastAttribs.getLength();
-    for (sal_uInt16 i = 0; i < len; i++)
+    if ( Attribs.is() )
     {
-        OUString& rAttrValue = fastAttribs[i].Value;
-        sal_Int32 nToken = fastAttribs[i].Token;
-        const OUString& rAttrNamespacePrefix = 
mrImport.getNamespacePrefixFromToken( nToken );
-        OUString sAttrName = mrImport.getNameFromToken( nToken );
-        if ( !rAttrNamespacePrefix.isEmpty() )
-            sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
-
-        rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
+        sax_fastparser::FastAttributeList *pAttribList;
+        assert( dynamic_cast< sax_fastparser::FastAttributeList *>( 
Attribs.get() ) != nullptr );
+        pAttribList = static_cast< sax_fastparser::FastAttributeList *>( 
Attribs.get() );
+
+        const std::vector< sal_Int32 >& rAttrTokenList = 
pAttribList->getFastAttributeTokens();
+        for ( size_t i = 0; i < rAttrTokenList.size(); i++ )
+        {
+            const OUString& rAttrValue = 
OUString(pAttribList->getFastAttributeValue(i),
+                                            
pAttribList->AttributeValueLength(i), RTL_TEXTENCODING_UTF8);
+            sal_Int32 nToken = rAttrTokenList[ i ];
+            const OUString& rAttrNamespacePrefix = 
mrImport.getNamespacePrefixFromToken( nToken );
+            OUString sAttrName = mrImport.getNameFromToken( nToken );
+            if ( !rAttrNamespacePrefix.isEmpty() )
+                sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
+
+            rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
+        }
+
+        uno::Sequence< xml::Attribute > unknownAttribs = 
Attribs->getUnknownAttributes();
+        sal_Int32 len = unknownAttribs.getLength();
+        for ( sal_Int32 i = 0; i < len; i++ )
+        {
+            const OUString& rAttrValue = unknownAttribs[i].Value;
+            OUString sAttrName = unknownAttribs[i].Name;
+            const OUString& rAttrNamespacePrefix = 
unknownAttribs[i].NamespaceURL;
+            if ( !rAttrNamespacePrefix.isEmpty() )
+                sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
+
+            rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
+        }
     }
 
-    uno::Sequence< xml::Attribute > unknownAttribs = 
Attribs->getUnknownAttributes();
-    len = unknownAttribs.getLength();
-    for ( sal_uInt16 i = 0; i < len; i++ )
-    {
-        OUString& rAttrValue = unknownAttribs[i].Value;
-        OUString sAttrName = unknownAttribs[i].Name;
-        OUString& rAttrNamespacePrefix = unknownAttribs[i].NamespaceURL;
-        if ( !rAttrNamespacePrefix.isEmpty() )
-            sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
-
-        rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
-    }
     mrImport.startElement( elementName, rAttrList.get() );
 }
 
 void SAL_CALL SvXMLImportContext::endFastElement(sal_Int32 nElement)
     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
 {
+    mrImport.isFastContext = false;
     endUnknownElement( mrImport.getNamespacePrefixFromToken( nElement ),
                        mrImport.getNameFromToken( nElement ) );
 }
@@ -146,9 +157,10 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL 
SvXMLImportContext::cre
     return this;
 }
 
-void SAL_CALL SvXMLImportContext::characters(const OUString &)
+void SAL_CALL SvXMLImportContext::characters(const OUString &rChars)
     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
 {
+    mrImport.Characters( rChars );
 }
 
 void SvXMLImportContext::onDemandRescueUsefulDataFromTemporary( const 
SvXMLImportContext& )
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index f234cee..7a1fd79 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -435,6 +435,7 @@ SvXMLImport::SvXMLImport(
     mpXMLErrors( nullptr ),
     mnImportFlags( nImportFlags ),
     mnErrorFlags(SvXMLErrorFlags::NO),
+    isFastContext( false ),
     maNamespaceHandler( new SvXMLImportFastNamespaceHandler() ),
     mxTokenHandler( new FastTokenHandler() ),
     mbIsFormsSupported( true ),
@@ -691,14 +692,9 @@ void SAL_CALL SvXMLImport::endDocument()
     }
 }
 
-void SAL_CALL SvXMLImport::startElement( const OUString& rName,
-                                         const uno::Reference< 
xml::sax::XAttributeList >& xAttrList )
-    throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
+void SvXMLImport::processNSAttributes( const uno::Reference< 
xml::sax::XAttributeList >& xAttrList,
+                                        SvXMLNamespaceMap *pRewindMap )
 {
-    SvXMLNamespaceMap *pRewindMap = nullptr;
-    //    SAL_INFO("svg", "startElement " << rName);
-    // Process namespace attributes. This must happen before creating the
-    // context, because namespace decaration apply to the element name itself.
     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     for( sal_Int16 i=0; i < nAttrCount; i++ )
     {
@@ -746,6 +742,17 @@ void SAL_CALL SvXMLImport::startElement( const OUString& 
rName,
 
         }
     }
+}
+
+void SAL_CALL SvXMLImport::startElement( const OUString& rName,
+                                         const uno::Reference< 
xml::sax::XAttributeList >& xAttrList )
+    throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
+{
+    SvXMLNamespaceMap *pRewindMap = nullptr;
+    //    SAL_INFO("svg", "startElement " << rName);
+    // Process namespace attributes. This must happen before creating the
+    // context, because namespace decaration apply to the element name itself.
+    processNSAttributes( xAttrList, pRewindMap );
 
     // Get element's namespace and local name.
     OUString aLocalName;
@@ -852,6 +859,14 @@ void SAL_CALL SvXMLImport::characters( const OUString& 
rChars )
     }
 }
 
+void SvXMLImport::Characters( const OUString& rChars )
+{
+    if( !mpContexts->empty() )
+    {
+        mpContexts->back()->Characters( rChars );
+    }
+}
+
 void SAL_CALL SvXMLImport::ignorableWhitespace( const OUString& )
     throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
 {
@@ -888,9 +903,23 @@ void SAL_CALL SvXMLImport::startFastElement (sal_Int32 
Element,
     if ( !xContext.is() )
         xContext.set( new SvXMLImportContext( *this ) );
 
+    isFastContext = true;
+
     // Call a startElement at the new context.
     xContext->startFastElement( Element, Attribs );
 
+    if ( isFastContext )
+    {
+        rtl::Reference < comphelper::AttributeList > rAttrList = new 
comphelper::AttributeList;
+        maNamespaceHandler->addNSDeclAttributes( rAttrList );
+        SvXMLNamespaceMap *pRewindMap = nullptr;
+        processNSAttributes( rAttrList.get(), pRewindMap );
+        SvXMLImportContext *pContext = dynamic_cast<SvXMLImportContext*>( 
xContext.get() );
+        if( pContext && pRewindMap )
+            pContext->PutRewindMap( pRewindMap );
+        mpContexts->push_back( pContext );
+    }
+
     // Push context on stack.
     mpFastContexts->push_back( xContext );
 }
@@ -924,7 +953,11 @@ void SAL_CALL SvXMLImport::endFastElement (sal_Int32 
Element)
     {
         uno::Reference< XFastContextHandler > xContext = 
mpFastContexts->back();
         mpFastContexts->pop_back();
+        isFastContext = true;
         xContext->endFastElement( Element );
+        if ( isFastContext )
+            mpContexts->pop_back();
+
         xContext = nullptr;
     }
 }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to