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

Daniel Sikeler d.sikeler94 at gmail.com
Fri Oct 31 01:19:20 PDT 2014


 include/xmloff/xmlictxt.hxx     |   34 +++++++++++++++++
 include/xmloff/xmlimp.hxx       |   38 ++++++++++++++++++-
 xmloff/source/core/xmlictxt.cxx |   47 ++++++++++++++++++++++++
 xmloff/source/core/xmlimp.cxx   |   77 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 192 insertions(+), 4 deletions(-)

New commits:
commit c0a5d390e519603dbc19a38c610d0a114b80cfa1
Author: Daniel Sikeler <d.sikeler94 at gmail.com>
Date:   Fri Oct 24 07:22:31 2014 +0000

    fdo#80403: Import baseclasses implement FastParser interfaces
    
    SvXMLImportContext implements XFastContextHandler
    SvXMLImport implements XFastDocumentHandler
    
    Change-Id: Id400260af112f4a448fe469c9580f0ebacec4ab6

diff --git a/include/xmloff/xmlictxt.hxx b/include/xmloff/xmlictxt.hxx
index bd21e95..35f693d 100644
--- a/include/xmloff/xmlictxt.hxx
+++ b/include/xmloff/xmlictxt.hxx
@@ -24,14 +24,17 @@
 #include <xmloff/dllapi.h>
 #include <sal/types.h>
 #include <com/sun/star/xml/sax/XAttributeList.hpp>
+#include <com/sun/star/xml/sax/XFastContextHandler.hpp>
 #include <tools/ref.hxx>
 #include <rtl/ustring.hxx>
 #include <tools/rtti.hxx>
+#include <cppuhelper/implbase1.hxx>
 
 class SvXMLNamespaceMap;
 class SvXMLImport;
 
-class XMLOFF_DLLPUBLIC SvXMLImportContext : public SvRefBase
+class XMLOFF_DLLPUBLIC SvXMLImportContext : public SvRefBase,
+        public ::cppu::WeakImplHelper1< ::css::xml::sax::XFastContextHandler >
 {
     friend class SvXMLImport;
 
@@ -64,6 +67,8 @@ public:
     SvXMLImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
                         const OUString& rLName );
 
+    SvXMLImportContext( SvXMLImport& rImport );
+
     /** A contexts destructor does anything that is required if an element
      * ends. By default, nothing is done.
      * Note that virtual methods cannot be used inside destructors. Use
@@ -90,6 +95,33 @@ public:
      * current element. The default is to ignore them. */
     virtual void Characters( const OUString& rChars );
 
+    // ::com::sun::star::xml::sax::XFastContextHandler:
+    virtual void SAL_CALL startFastElement (sal_Int32 Element,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+
+    virtual void SAL_CALL startUnknownElement(const OUString & Namespace, const OUString & Name,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+
+    virtual void SAL_CALL endFastElement(sal_Int32 Element)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+
+    virtual void SAL_CALL endUnknownElement(const OUString & Namespace, const OUString & Name)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+
+    virtual css::uno::Reference< XFastContextHandler >  SAL_CALL createFastChildContext(sal_Int32 Element,
+        const css::uno::Reference<css::xml::sax::XFastAttributeList>& Attribs)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+
+    virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(
+        const OUString & Namespace, const OUString & Name,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+
+    virtual void SAL_CALL characters(const OUString & aChars)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+
     // #i124143# allow to copy evtl. useful data from another temporary import context, e.g. used to
     // support multiple images and to rescue evtl. GluePoints imported with one of the
     // to be deprecated contents
diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index 43afbea..4c3e35f 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -48,11 +48,15 @@
 #include <xmloff/shapeimport.hxx>
 #include <xmloff/SchXMLImportHelper.hxx>
 #include <xmloff/ProgressBarHelper.hxx>
-#include <cppuhelper/implbase6.hxx>
+#include <cppuhelper/implbase7.hxx>
 #include <xmloff/formlayerimport.hxx>
 
 #include <com/sun/star/beans/NamedValue.hpp>
 
+#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XFastContextHandler.hpp>
+#include <com/sun/star/xml/sax/XFastAttributeList.hpp>
+
 namespace com { namespace sun { namespace star {
     namespace frame { class XModel; }
     namespace io { class XOutputStream; }
@@ -71,6 +75,8 @@ class XMLErrors;
 class StyleMap;
 
 typedef std::vector<SvXMLImportContext *> SvXMLImportContexts_Impl;
+typedef std::vector< ::css::uno::Reference< ::css::xml::sax::XFastContextHandler>>
+            FastSvXMLImportContexts_Impl;
 
 namespace xmloff {
     class RDFaImportHelper;
@@ -90,8 +96,9 @@ namespace xmloff {
 
 
 
-class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper6<
+class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper7<
              ::com::sun::star::xml::sax::XExtendedDocumentHandler,
+             ::com::sun::star::xml::sax::XFastDocumentHandler,
              ::com::sun::star::lang::XServiceInfo,
              ::com::sun::star::lang::XInitialization,
              ::com::sun::star::document::XImporter,
@@ -131,6 +138,7 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper6<
     SvXMLNamespaceMap           *mpNamespaceMap;
     SvXMLUnitConverter          *mpUnitConv;
     SvXMLImportContexts_Impl    *mpContexts;
+    FastSvXMLImportContexts_Impl    *mpFastContexts;
     SvXMLNumFmtHelper           *mpNumImport;
     ProgressBarHelper           *mpProgressBarHelper;
     XMLEventImportHelper        *mpEventImportHelper;
@@ -156,6 +164,8 @@ protected:
     virtual SvXMLImportContext *CreateContext( sal_uInt16 nPrefix,
                                                const OUString& rLocalName,
                                                const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
+    virtual SvXMLImportContext *CreateFastContext( sal_Int32 Element,
+        const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList );
 
     virtual XMLTextImportHelper* CreateTextImport();
     inline void ClearTextImport() { mxTextImport = 0; }
@@ -205,7 +215,7 @@ public:
               ::com::sun::star::uno::RuntimeException,
               std::exception) SAL_OVERRIDE;
     virtual void SAL_CALL startElement(const OUString& aName,
-                                       const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttribs)
+        const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttribs)
         throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     virtual void SAL_CALL endElement(const OUString& aName)
         throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
@@ -219,6 +229,28 @@ public:
     virtual void SAL_CALL setDocumentLocator(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > & xLocator)
         throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
 
+    // ::css::xml::sax::XFastContextHandler
+    virtual void SAL_CALL startFastElement(sal_Int32 Element,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+    virtual void SAL_CALL startUnknownElement(const OUString & Namespace,
+        const OUString & Name,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+    virtual void SAL_CALL endFastElement(sal_Int32 Element)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+    virtual void SAL_CALL endUnknownElement(const OUString & Namespace,
+        const OUString & Name)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+    virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL
+    createFastChildContext(sal_Int32 Element,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+    virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL
+    createUnknownChildContext(const OUString & Namespace, const OUString & Name,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+
     // ::com::sun::star::xml::sax::XExtendedDocumentHandler
     virtual void SAL_CALL startCDATA(void) throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     virtual void SAL_CALL endCDATA(void) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
diff --git a/xmloff/source/core/xmlictxt.cxx b/xmloff/source/core/xmlictxt.cxx
index 6b7f257..8340a07 100644
--- a/xmloff/source/core/xmlictxt.cxx
+++ b/xmloff/source/core/xmlictxt.cxx
@@ -39,6 +39,12 @@ SvXMLImportContext::SvXMLImportContext( SvXMLImport& rImp, sal_uInt16 nPrfx,
 {
 }
 
+SvXMLImportContext::SvXMLImportContext( SvXMLImport& rImp ) :
+    mrImport( rImp ),
+    mpRewindMap( 0 )
+{
+}
+
 SvXMLImportContext::~SvXMLImportContext()
 {
 }
@@ -62,6 +68,47 @@ void SvXMLImportContext::Characters( const OUString& )
 {
 }
 
+// ::com::sun::star::xml::sax::XFastContextHandler:
+void SAL_CALL SvXMLImportContext::startFastElement(sal_Int32, const uno::Reference< xml::sax::XFastAttributeList > &)
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+}
+
+void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString &, const OUString &,
+    const uno::Reference< xml::sax::XFastAttributeList > &)
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+}
+
+void SAL_CALL SvXMLImportContext::endFastElement(sal_Int32)
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+}
+
+void SAL_CALL SvXMLImportContext::endUnknownElement (const OUString & , const OUString & )
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+}
+
+uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::createFastChildContext
+    (sal_Int32 Element, const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+    return mrImport.CreateFastContext( Element, Attribs );
+}
+
+uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::createUnknownChildContext
+    (const OUString &, const OUString &, const uno::Reference< xml::sax::XFastAttributeList > &)
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+    return 0;
+}
+
+void SAL_CALL SvXMLImportContext::characters(const OUString &)
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+}
+
 void SvXMLImportContext::onDemandRescueUsefulDataFromTemporary( const SvXMLImportContext& )
 {
 }
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 97df9ab..d688e8f 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -346,6 +346,12 @@ SvXMLImportContext *SvXMLImport::CreateContext( sal_uInt16 nPrefix,
     return new SvXMLImportContext( *this, nPrefix, rLocalName );
 }
 
+SvXMLImportContext *SvXMLImport::CreateFastContext( sal_Int32 /*Element*/,
+        const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
+{
+    return new SvXMLImportContext( *this );
+}
+
 void SvXMLImport::_InitCtor()
 {
     if( mnImportFlags != 0 )
@@ -415,6 +421,7 @@ SvXMLImport::SvXMLImport(
                 util::MeasureUnit::MM_100TH, util::MeasureUnit::MM_100TH) ),
 
     mpContexts( new SvXMLImportContexts_Impl ),
+    mpFastContexts( new FastSvXMLImportContexts_Impl ),
     mpNumImport( NULL ),
     mpProgressBarHelper( NULL ),
     mpEventImportHelper( NULL ),
@@ -780,6 +787,10 @@ void SAL_CALL SvXMLImport::characters( const OUString& rChars )
     {
         mpContexts->back()->Characters( rChars );
     }
+    else if ( !mpFastContexts->empty() )
+    {
+        mpFastContexts->back()->characters( rChars );
+    }
 }
 
 void SAL_CALL SvXMLImport::ignorableWhitespace( const OUString& )
@@ -799,6 +810,72 @@ void SAL_CALL SvXMLImport::setDocumentLocator( const uno::Reference< xml::sax::X
     mxLocator = rLocator;
 }
 
+// XFastContextHandler
+void SAL_CALL SvXMLImport::startFastElement (sal_Int32 Element,
+    const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+    //Namespace handling is unnecessary. It is done by the fastparser itself.
+    uno::Reference<XFastContextHandler> xContext;
+    sal_uInt16 nCount = mpFastContexts->size();
+    if( nCount > 0 )
+    {
+        uno::Reference< XFastContextHandler > pHandler = (*mpFastContexts)[nCount - 1];
+        xContext = pHandler->createFastChildContext( Element, Attribs );
+    }
+    else
+        xContext.set( CreateFastContext( Element, Attribs ) );
+
+    if ( !xContext.is() )
+        xContext.set( new SvXMLImportContext( *this ) );
+
+    // Call a startElement at the new context.
+    xContext->startFastElement( Element, Attribs );
+
+    // Push context on stack.
+    mpFastContexts->push_back( xContext );
+}
+
+void SAL_CALL SvXMLImport::startUnknownElement (const OUString &, const OUString &,
+    const uno::Reference< xml::sax::XFastAttributeList > &)
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+}
+
+void SAL_CALL SvXMLImport::endFastElement (sal_Int32 Element)
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+    sal_uInt16 nCount = mpFastContexts->size();
+    if( nCount > 0 )
+    {
+        uno::Reference< XFastContextHandler > xContext = mpFastContexts->back();
+        mpFastContexts->pop_back();
+        xContext->endFastElement( Element );
+        xContext = 0;
+    }
+}
+
+void SAL_CALL SvXMLImport::endUnknownElement (const OUString &, const OUString &)
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+}
+
+uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
+    SvXMLImport::createFastChildContext (sal_Int32,
+    const uno::Reference< xml::sax::XFastAttributeList > &)
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+    return this;
+}
+
+uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
+    SvXMLImport::createUnknownChildContext (const OUString &, const OUString &,
+    const uno::Reference< xml::sax::XFastAttributeList > &)
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
+{
+    return this;
+}
+
 // XExtendedDocumentHandler
 void SAL_CALL SvXMLImport::startCDATA( void ) throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
 {


More information about the Libreoffice-commits mailing list