[Libreoffice-commits] core.git: sw/CustomTarget_generated.mk sw/Library_sw.mk sw/Module_sw.mk sw/source

Daniel Sikeler d.sikeler94 at gmail.com
Wed Dec 10 10:33:01 PST 2014


 sw/CustomTarget_generated.mk            |   34 ++
 sw/Library_sw.mk                        |    1 
 sw/Module_sw.mk                         |    1 
 sw/source/core/inc/SwXMLBlockImport.hxx |   76 +++++-
 sw/source/core/swg/BlockListTokens.txt  |    7 
 sw/source/core/swg/SwXMLBlockImport.cxx |  404 +++++++++++++++-----------------
 sw/source/core/swg/SwXMLTextBlocks1.cxx |   37 ++
 sw/source/core/swg/TextBlockTokens.txt  |    5 
 8 files changed, 340 insertions(+), 225 deletions(-)

New commits:
commit c2c0989794d5a4724da8b8880559764bffd059ec
Author: Daniel Sikeler <d.sikeler94 at gmail.com>
Date:   Mon Nov 10 12:23:12 2014 +0000

    fdo#80403: Writer specific AutoCorr use FastParser
    
    Contextclasses implement XFastContextHandler
    Importclasses implement XFastDocumentHandler
    Tokens for BlockList.xml are defined in BlockListTokens.txt
    Tokens for content.xml are defined in TextBlockTokens.txt
    A perfect hash table is generated with gperf and used by the tokenhandlers
    
    This is corrected version of c1e90457d2ecc6e1171b7a296ab8bd05821e39e6
    (Also pushing again follow-up c940d4d30673dc02ea34b5e60a4a8140648a0dba
    "loplugin:saloverride" and 5f0f3d4e91e9eb1d1f60b0cd073e7bbd8ea38c29
    "Work around -Werror,-Wdeprecated-register")
    The commits were reverted in 7ef4457b9fc06b5c25c607d7e0149f45c7015b10
    
    Change-Id: I08cd852fa751f98fd0ac6a55dda22f82a869b4d8

diff --git a/sw/CustomTarget_generated.mk b/sw/CustomTarget_generated.mk
new file mode 100644
index 0000000..f8244d2
--- /dev/null
+++ b/sw/CustomTarget_generated.mk
@@ -0,0 +1,34 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CustomTarget_CustomTarget,sw/generated))
+
+sw_SRC := $(SRCDIR)/sw/source/core/swg
+sw_PL := $(SRCDIR)/solenv/bin/gentoken.pl
+sw_INC := $(call gb_CustomTarget_get_workdir,sw/generated)
+
+$(sw_INC)/TextBlockTokens.gperf : $(sw_SRC)/TextBlockTokens.txt $(sw_PL)
+	mkdir -p $(sw_INC)
+	$(PERL) $(sw_PL) $(sw_SRC)/TextBlockTokens.txt $(sw_INC)/TextBlockTokens.gperf
+
+$(sw_INC)/BlockListTokens.gperf : $(sw_SRC)/BlockListTokens.txt $(sw_PL)
+	mkdir -p $(sw_INC)
+	$(PERL) $(sw_PL) $(sw_SRC)/BlockListTokens.txt $(sw_INC)/BlockListTokens.gperf
+
+$(sw_INC)/tokens.cxx : $(sw_INC)/TextBlockTokens.gperf $(sw_INC)/BlockListTokens.gperf
+	$(GPERF) --compare-strncmp --readonly-tables --output-file=$(sw_INC)/tokens.cxx \
+	--class-name=TextBlockTokens --word-array-name=textBlockList --enum $(sw_INC)/TextBlockTokens.gperf
+	$(GPERF) --compare-strncmp --readonly-tables -T $(sw_INC)/BlockListTokens.gperf \
+	--class-name=BlockListTokens --word-array-name=blockListList >> $(sw_INC)/tokens.cxx
+	sed -i -e "s/(char\*)0/(char\*)0, XML_TOKEN_INVALID/g" $(sw_INC)/tokens.cxx
+	sed -i -e "/^#line/d" $(sw_INC)/tokens.cxx
+
+$(call gb_CustomTarget_get_target,sw/generated) : $(sw_INC)/tokens.cxx
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 1b16def..f9a4e03 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -36,6 +36,7 @@ $(eval $(call gb_Library_set_include,sw,\
 
 $(eval $(call gb_Library_use_custom_headers,sw,\
 	officecfg/registry \
+	sw/generated \
 ))
 
 $(eval $(call gb_Library_use_sdk_api,sw))
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index a7a31ef..bf110be 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -21,6 +21,7 @@ $(eval $(call gb_Module_Module,sw))
 
 $(eval $(call gb_Module_add_targets,sw,\
 	$(call gb_Helper_optional,DESKTOP,Executable_tiledrendering) \
+        CustomTarget_generated \
 	Library_msword \
 	Library_sw \
 	Library_swd \
diff --git a/sw/source/core/inc/SwXMLBlockImport.hxx b/sw/source/core/inc/SwXMLBlockImport.hxx
index ac166fd..9c4e77c 100644
--- a/sw/source/core/inc/SwXMLBlockImport.hxx
+++ b/sw/source/core/inc/SwXMLBlockImport.hxx
@@ -21,6 +21,14 @@
 #define INCLUDED_SW_SOURCE_CORE_INC_SWXMLBLOCKIMPORT_HXX
 
 #include <xmloff/xmlimp.hxx>
+#include <xmloff/nmspmap.hxx>
+#include <xmloff/xmlnmspe.hxx>
+#include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
+#include <com/sun/star/xml/sax/FastToken.hpp>
+#include <sax/fastattribs.hxx>
+
+using namespace css::xml::sax;
+using namespace xmloff::token;
 
 class SwXMLTextBlocks;
 class SwXMLBlockListImport : public SvXMLImport
@@ -31,10 +39,8 @@ private:
 protected:
     // This method is called after the namespace map has been updated, but
     // before a context for the current element has been pushed.
-    virtual SvXMLImportContext *CreateContext( sal_uInt16 nPrefix,
-                  const OUString& rLocalName,
-                  const ::com::sun::star::uno::Reference<
-                    ::com::sun::star::xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
+    virtual SvXMLImportContext* CreateFastContext( sal_Int32 Element,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) SAL_OVERRIDE;
 
 public:
     SwXMLBlockListImport(
@@ -57,10 +63,8 @@ private:
 protected:
     // This method is called after the namespace map has been updated, but
     // before a context for the current element has been pushed.
-    virtual SvXMLImportContext *CreateContext( sal_uInt16 nPrefix,
-                  const OUString& rLocalName,
-                  const ::com::sun::star::uno::Reference<
-                    ::com::sun::star::xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
+    virtual SvXMLImportContext* CreateFastContext( sal_Int32 Element,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) SAL_OVERRIDE;
 
 public:
     bool bTextOnly;
@@ -79,6 +83,62 @@ public:
         throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
 };
 
+enum SwXMLTextBlockToken : sal_Int32
+{
+    OFFICE_BODY = FastToken::NAMESPACE | XML_NAMESPACE_OFFICE | XML_BODY,
+    OFFICE_TEXT = FastToken::NAMESPACE | XML_NAMESPACE_OFFICE | XML_TEXT,
+    OFFICE_DOCUMENT = FastToken::NAMESPACE | XML_NAMESPACE_OFFICE | XML_DOCUMENT,
+    OFFICE_DOCUMENT_CONTENT = FastToken::NAMESPACE | XML_NAMESPACE_OFFICE | XML_DOCUMENT_CONTENT,
+    TEXT_P = FastToken::NAMESPACE | XML_NAMESPACE_TEXT | XML_P
+};
+
+class SwXMLTextBlockTokenHandler : public
+        cppu::WeakImplHelper1< css::xml::sax::XFastTokenHandler >,
+        public sax_fastparser::FastTokenHandlerBase
+{
+public:
+    SwXMLTextBlockTokenHandler();
+    virtual ~SwXMLTextBlockTokenHandler();
+
+    //XFastTokenHandler
+    sal_Int32 SAL_CALL getTokenFromUTF8( const css::uno::Sequence< sal_Int8 >& Identifier )
+        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+    css::uno::Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( sal_Int32 Token )
+        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+
+    //Much fast direct C++ shortcut to the method that matters
+    virtual sal_Int32 getTokenDirect( const char *pTag, sal_Int32 nLength ) const SAL_OVERRIDE;
+};
+
+enum SwXMLBlockListToken : sal_Int32
+{
+    ABBREVIATED_NAME = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_ABBREVIATED_NAME,
+    BLOCK = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_BLOCK,
+    BLOCK_LIST = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_BLOCK_LIST,
+    LIST_NAME = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_LIST_NAME,
+    NAME = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_NAME,
+    PACKAGE_NAME = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_PACKAGE_NAME,
+    UNFORMATTED_TEXT = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_UNFORMATTED_TEXT
+};
+
+class SwXMLBlockListTokenHandler : public
+        cppu::WeakImplHelper1< css::xml::sax::XFastTokenHandler >,
+        public sax_fastparser::FastTokenHandlerBase
+{
+public:
+    SwXMLBlockListTokenHandler();
+    virtual ~SwXMLBlockListTokenHandler();
+
+    //XFastTokenHandler
+    sal_Int32 SAL_CALL getTokenFromUTF8( const css::uno::Sequence< sal_Int8 >& Identifier )
+        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+    css::uno::Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( sal_Int32 Token )
+        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+
+    //Much fast direct C++ shortcut to the method that matters
+    virtual sal_Int32 getTokenDirect( const char *pTag, sal_Int32 nLength ) const SAL_OVERRIDE;
+};
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/swg/BlockListTokens.txt b/sw/source/core/swg/BlockListTokens.txt
new file mode 100644
index 0000000..0b5a646
--- /dev/null
+++ b/sw/source/core/swg/BlockListTokens.txt
@@ -0,0 +1,7 @@
+abbreviated-name
+block
+block-list
+list-name
+name
+package-name
+unformatted-text
diff --git a/sw/source/core/swg/SwXMLBlockImport.cxx b/sw/source/core/swg/SwXMLBlockImport.cxx
index 5d5355b..dcc6909 100644
--- a/sw/source/core/swg/SwXMLBlockImport.cxx
+++ b/sw/source/core/swg/SwXMLBlockImport.cxx
@@ -18,16 +18,27 @@
  */
 
 #include <SwXMLBlockImport.hxx>
-#include <xmloff/nmspmap.hxx>
-#include <xmloff/xmlnmspe.hxx>
 #include <SwXMLTextBlocks.hxx>
 #include <xmloff/xmlictxt.hxx>
 #include <unotools/charclass.hxx>
 #include <swtypes.hxx>
 
+#if defined __clang__
+#if __has_warning("-Wdeprecated-register")
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-register"
+#endif
+#endif
+#include <tokens.cxx>
+#if defined __clang__
+#if __has_warning("-Wdeprecated-register")
+#pragma GCC diagnostic pop
+#endif
+#endif
+
+using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star;
-using namespace ::xmloff::token;
-
+using namespace css::xml::sax;
 
 class SwXMLBlockListImport;
 class SwXMLTextBlockImport;
@@ -38,24 +49,20 @@ private:
     SwXMLBlockListImport & rLocalRef;
 
 public:
-    SwXMLBlockListContext( SwXMLBlockListImport& rImport,
-                           sal_uInt16 nPrefix,
-                           const OUString& rLocalName,
-                           const uno::Reference<xml::sax::XAttributeList> & xAttrList);
+    SwXMLBlockListContext( SwXMLBlockListImport& rImport, sal_Int32 Element,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
     virtual ~SwXMLBlockListContext ( void );
-    virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
-                           const OUString& rLocalName,
-                           const uno::Reference<xml::sax::XAttributeList> & xAttrList) SAL_OVERRIDE;
 
+    virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+        sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
 };
 
 class SwXMLBlockContext : public SvXMLImportContext
 {
 public:
-    SwXMLBlockContext(     SwXMLBlockListImport& rImport,
-                           sal_uInt16 nPrefix,
-                           const OUString& rLocalName,
-                           const uno::Reference<xml::sax::XAttributeList> & xAttrList);
+    SwXMLBlockContext( SwXMLBlockListImport& rImport, sal_Int32 Element,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
     virtual ~SwXMLBlockContext ( void );
 };
 
@@ -65,13 +72,13 @@ private:
     SwXMLTextBlockImport & rLocalRef;
 
 public:
-    SwXMLTextBlockDocumentContext(     SwXMLTextBlockImport& rImport,
-                           sal_uInt16 nPrefix,
-                           const OUString& rLocalName,
-                           const uno::Reference<xml::sax::XAttributeList> & xAttrList);
-    virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
-                           const OUString& rLocalName,
-                           const uno::Reference<xml::sax::XAttributeList> & xAttrList) SAL_OVERRIDE;
+    SwXMLTextBlockDocumentContext( SwXMLTextBlockImport& rImport, sal_Int32 Element,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
+
+    virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+        sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+
     virtual ~SwXMLTextBlockDocumentContext ( void );
 };
 
@@ -81,13 +88,13 @@ private:
     SwXMLTextBlockImport & rLocalRef;
 
 public:
-    SwXMLTextBlockBodyContext(     SwXMLTextBlockImport& rImport,
-                           sal_uInt16 nPrefix,
-                           const OUString& rLocalName,
-                           const uno::Reference<xml::sax::XAttributeList > & xAttrList);
-    virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
-                           const OUString& rLocalName,
-                           const uno::Reference<xml::sax::XAttributeList> & xAttrList) SAL_OVERRIDE;
+    SwXMLTextBlockBodyContext( SwXMLTextBlockImport& rImport, sal_Int32 Element,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
+
+    virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+        sal_Int32, const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+
     virtual ~SwXMLTextBlockBodyContext ( void );
 };
 
@@ -97,15 +104,14 @@ private:
     SwXMLTextBlockImport & rLocalRef;
 
 public:
-    SwXMLTextBlockTextContext(     SwXMLTextBlockImport& rImport,
-                           sal_uInt16 nPrefix,
-                           const OUString& rLocalName,
-                           const uno::Reference<
-                           xml::sax::XAttributeList > & xAttrList );
-    virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
-                           const OUString& rLocalName,
-                           const uno::Reference<
-                           xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
+    SwXMLTextBlockTextContext( SwXMLTextBlockImport& rImport, sal_Int32 Element,
+                const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
+
+    virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+        sal_Int32 Element,
+        const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+
     virtual ~SwXMLTextBlockTextContext ( void );
 };
 
@@ -115,101 +121,119 @@ private:
     SwXMLTextBlockImport & rLocalRef;
 
 public:
-    SwXMLTextBlockParContext(     SwXMLTextBlockImport& rImport,
-                           sal_uInt16 nPrefix,
-                           const OUString& rLocalName,
-                           const uno::Reference<
-                           xml::sax::XAttributeList > & xAttrList );
-    virtual void Characters( const OUString& rChars ) SAL_OVERRIDE;
+    SwXMLTextBlockParContext( SwXMLTextBlockImport & rImport, sal_Int32 Element,
+            const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
+
+    virtual void SAL_CALL characters( const OUString & aChars )
+        throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
+
     virtual ~SwXMLTextBlockParContext ( void );
 };
 
+SwXMLTextBlockTokenHandler::SwXMLTextBlockTokenHandler()
+{
+}
+
+SwXMLTextBlockTokenHandler::~SwXMLTextBlockTokenHandler()
+{
+}
+
+sal_Int32 SAL_CALL SwXMLTextBlockTokenHandler::getTokenFromUTF8( const Sequence< sal_Int8 >& Identifier )
+    throw (css::uno::RuntimeException, std::exception)
+{
+    return getTokenDirect( reinterpret_cast< const char* >( Identifier.getConstArray() ), Identifier.getLength() );
+}
+
+Sequence< sal_Int8 > SAL_CALL SwXMLTextBlockTokenHandler::getUTF8Identifier( sal_Int32 )
+    throw (css::uno::RuntimeException, std::exception)
+{
+    return Sequence< sal_Int8 >();
+}
+
+sal_Int32 SwXMLTextBlockTokenHandler::getTokenDirect( const char *pTag, sal_Int32 nLength ) const
+{
+    if( !nLength )
+        nLength = strlen( pTag );
+    const struct xmltoken* pToken = TextBlockTokens::in_word_set( pTag, nLength );
+    return pToken ? pToken->nToken : XML_TOKEN_INVALID;
+}
+
+SwXMLBlockListTokenHandler::SwXMLBlockListTokenHandler()
+{
+}
+
+SwXMLBlockListTokenHandler::~SwXMLBlockListTokenHandler()
+{
+}
+
+sal_Int32 SAL_CALL SwXMLBlockListTokenHandler::getTokenFromUTF8( const Sequence< sal_Int8 >& Identifier )
+    throw (css::uno::RuntimeException, std::exception)
+{
+    return getTokenDirect( reinterpret_cast< const char* >( Identifier.getConstArray() ), Identifier.getLength() );
+}
+
+Sequence< sal_Int8 > SAL_CALL SwXMLBlockListTokenHandler::getUTF8Identifier( sal_Int32 )
+    throw (css::uno::RuntimeException, std::exception)
+{
+    return Sequence< sal_Int8 >();
+}
+
+sal_Int32 SwXMLBlockListTokenHandler::getTokenDirect( const char *pTag, sal_Int32 nLength ) const
+{
+    if( !nLength )
+        nLength = strlen( pTag );
+    const struct xmltoken* pToken = BlockListTokens::in_word_set( pTag, nLength );
+    return pToken ? pToken->nToken : XML_TOKEN_INVALID;
+}
 
 SwXMLBlockListContext::SwXMLBlockListContext(
-   SwXMLBlockListImport& rImport,
-   sal_uInt16 nPrefix,
-   const OUString& rLocalName,
-   const uno::Reference<
-   xml::sax::XAttributeList > & xAttrList ) :
-    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
-    rLocalRef (rImport)
-{
-    sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
-    for (sal_Int16 i=0; i < nAttrCount; i++)
-    {
-        const OUString& rAttrName = xAttrList->getNameByIndex( i );
-        OUString aLocalName;
-        sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
-        const OUString& rAttrValue = xAttrList->getValueByIndex( i );
-        if ( XML_NAMESPACE_BLOCKLIST == nPrefx )
-        {
-            if ( IsXMLToken ( aLocalName, XML_LIST_NAME ) )
-            {
-                rImport.getBlockList().SetName(rAttrValue);
-                break;
-            }
-        }
-    }
+    SwXMLBlockListImport& rImport,
+    sal_Int32 /*Element*/,
+    const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ) :
+    SvXMLImportContext( rImport ),
+    rLocalRef( rImport )
+{
+    if( xAttrList.is() && xAttrList->hasAttribute( SwXMLBlockListToken::LIST_NAME ) )
+        rImport.getBlockList().SetName( xAttrList->getValue( SwXMLBlockListToken::LIST_NAME ) );
 }
 
 SwXMLBlockListContext::~SwXMLBlockListContext ( void )
 {
 }
 
-SvXMLImportContext *SwXMLBlockListContext::CreateChildContext(
-    sal_uInt16 nPrefix,
-    const OUString& rLocalName,
-    const uno::Reference< xml::sax::XAttributeList > & xAttrList )
+uno::Reference< ::xml::sax::XFastContextHandler > SAL_CALL
+SwXMLBlockListContext::createFastChildContext( sal_Int32 Element,
+    const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
 {
-    SvXMLImportContext *pContext = 0;
-    if (nPrefix == XML_NAMESPACE_BLOCKLIST &&
-        IsXMLToken ( rLocalName, XML_BLOCK ) )
-        pContext = new SwXMLBlockContext (rLocalRef, nPrefix, rLocalName, xAttrList);
+    if ( Element == SwXMLBlockListToken::BLOCK )
+        return new SwXMLBlockContext( rLocalRef, Element, xAttrList );
     else
-        pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
-    return pContext;
+        return new SvXMLImportContext( rLocalRef );
 }
 
 SwXMLBlockContext::SwXMLBlockContext(
-   SwXMLBlockListImport& rImport,
-   sal_uInt16 nPrefix,
-   const OUString& rLocalName,
-   const uno::Reference<
-   xml::sax::XAttributeList > & xAttrList ) :
-    SvXMLImportContext ( rImport, nPrefix, rLocalName )
+    SwXMLBlockListImport& rImport,
+    sal_Int32 /*Element*/,
+    const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ) :
+    SvXMLImportContext( rImport )
 {
     static const CharClass & rCC = GetAppCharClass();
-    OUString aShort;
-    OUString aLong;
-    OUString aPackageName;
+    OUString aShort, aLong, aPackageName;
     bool bTextOnly = false;
-
-    sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
-    for (sal_Int16 i=0; i < nAttrCount; i++)
+    if( xAttrList.is() )
     {
-        const OUString& rAttrName = xAttrList->getNameByIndex( i );
-        OUString aLocalName;
-        sal_uInt16 nPrefx = rImport.GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName);
-        const OUString& rAttrValue = xAttrList->getValueByIndex( i );
-        if (XML_NAMESPACE_BLOCKLIST == nPrefx)
+        if( xAttrList->hasAttribute( SwXMLBlockListToken::ABBREVIATED_NAME ) )
+            aShort = rCC.uppercase( xAttrList->getValue( SwXMLBlockListToken::ABBREVIATED_NAME ) );
+        if( xAttrList->hasAttribute( SwXMLBlockListToken::NAME ) )
+            aLong = xAttrList->getValue( SwXMLBlockListToken::NAME );
+        if( xAttrList->hasAttribute( SwXMLBlockListToken::PACKAGE_NAME ) )
+            aPackageName = xAttrList->getValue( SwXMLBlockListToken::PACKAGE_NAME );
+        if( xAttrList->hasAttribute( SwXMLBlockListToken::UNFORMATTED_TEXT ) )
         {
-            if ( IsXMLToken ( aLocalName, XML_ABBREVIATED_NAME ) )
-            {
-                aShort = rCC.uppercase(rAttrValue);
-            }
-            else if ( IsXMLToken ( aLocalName, XML_NAME ) )
-            {
-                aLong = rAttrValue;
-            }
-            else if ( IsXMLToken ( aLocalName, XML_PACKAGE_NAME ) )
-            {
-                aPackageName = rAttrValue;
-            }
-            else if ( IsXMLToken ( aLocalName, XML_UNFORMATTED_TEXT ) )
-            {
-                if ( IsXMLToken ( rAttrValue, XML_TRUE ) )
-                    bTextOnly = true;
-            }
+            OUString rAttrValue( xAttrList->getValue( SwXMLBlockListToken::UNFORMATTED_TEXT ) );
+            if( IsXMLToken( rAttrValue, XML_TRUE ) )
+                bTextOnly = true;
         }
     }
     if (aShort.isEmpty() || aLong.isEmpty() || aPackageName.isEmpty())
@@ -222,56 +246,47 @@ SwXMLBlockContext::~SwXMLBlockContext ( void )
 }
 
 SwXMLTextBlockDocumentContext::SwXMLTextBlockDocumentContext(
-   SwXMLTextBlockImport& rImport,
-   sal_uInt16 nPrefix,
-   const OUString& rLocalName,
-   const uno::Reference<
-   xml::sax::XAttributeList > & ) :
-    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
+    SwXMLTextBlockImport& rImport,
+    sal_Int32 /*Element*/,
+    const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ ) :
+    SvXMLImportContext( rImport ),
     rLocalRef(rImport)
 {
 }
 
-SvXMLImportContext *SwXMLTextBlockDocumentContext::CreateChildContext(
-    sal_uInt16 nPrefix,
-    const OUString& rLocalName,
-    const uno::Reference< xml::sax::XAttributeList > & xAttrList )
+uno::Reference< ::xml::sax::XFastContextHandler > SAL_CALL
+SwXMLTextBlockDocumentContext::createFastChildContext( sal_Int32 Element,
+    const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
 {
-    SvXMLImportContext *pContext = 0;
-    if (nPrefix == XML_NAMESPACE_OFFICE &&
-        IsXMLToken ( rLocalName, XML_BODY ) )
-        pContext = new SwXMLTextBlockBodyContext (rLocalRef, nPrefix, rLocalName, xAttrList);
+    if ( Element == SwXMLTextBlockToken::OFFICE_BODY )
+        return new SwXMLTextBlockBodyContext( rLocalRef, Element, xAttrList );
     else
-        pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
-    return pContext;
+        return new SvXMLImportContext( rLocalRef );
 }
+
 SwXMLTextBlockDocumentContext::~SwXMLTextBlockDocumentContext ( void )
 {
 }
 
 SwXMLTextBlockTextContext::SwXMLTextBlockTextContext(
-   SwXMLTextBlockImport& rImport,
-   sal_uInt16 nPrefix,
-   const OUString& rLocalName,
-   const uno::Reference<
-   xml::sax::XAttributeList > & ) :
-    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
-    rLocalRef(rImport)
+    SwXMLTextBlockImport& rImport,
+    sal_Int32 /*Element*/,
+    const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList */) :
+    SvXMLImportContext ( rImport ),
+    rLocalRef( rImport )
 {
 }
 
-SvXMLImportContext *SwXMLTextBlockTextContext::CreateChildContext(
-    sal_uInt16 nPrefix,
-    const OUString& rLocalName,
-    const uno::Reference< xml::sax::XAttributeList > & xAttrList )
+uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
+SwXMLTextBlockTextContext::createFastChildContext( sal_Int32 Element,
+    const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
 {
-    SvXMLImportContext *pContext = 0;
-    if (nPrefix == XML_NAMESPACE_TEXT &&
-        IsXMLToken ( rLocalName, XML_P ) )
-        pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
+    if ( Element == SwXMLTextBlockToken::TEXT_P )
+        return new SwXMLTextBlockParContext( rLocalRef, Element, xAttrList );
     else
-        pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
-    return pContext;
+        return new SvXMLImportContext( rLocalRef );
 }
 
 SwXMLTextBlockTextContext::~SwXMLTextBlockTextContext ( void )
@@ -279,50 +294,46 @@ SwXMLTextBlockTextContext::~SwXMLTextBlockTextContext ( void )
 }
 
 SwXMLTextBlockBodyContext::SwXMLTextBlockBodyContext(
-   SwXMLTextBlockImport& rImport,
-   sal_uInt16 nPrefix,
-   const OUString& rLocalName,
-   const uno::Reference<
-   xml::sax::XAttributeList > & ) :
-    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
+    SwXMLTextBlockImport& rImport,
+    sal_Int32 /*Element*/,
+    const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ ) :
+    SvXMLImportContext( rImport ),
     rLocalRef(rImport)
 {
 }
 
-SvXMLImportContext *SwXMLTextBlockBodyContext::CreateChildContext(
-    sal_uInt16 nPrefix,
-    const OUString& rLocalName,
-    const uno::Reference< xml::sax::XAttributeList > & xAttrList )
+uno::Reference < xml::sax::XFastContextHandler > SAL_CALL
+SwXMLTextBlockBodyContext::createFastChildContext( sal_Int32 Element,
+    const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
 {
-    SvXMLImportContext *pContext = 0;
-    if (nPrefix == XML_NAMESPACE_OFFICE &&
-        IsXMLToken ( rLocalName, XML_TEXT ) )
-        pContext = new SwXMLTextBlockTextContext (rLocalRef, nPrefix, rLocalName, xAttrList);
-    else if (nPrefix == XML_NAMESPACE_TEXT &&
-        IsXMLToken ( rLocalName, XML_P ) )
-        pContext = new SwXMLTextBlockParContext (rLocalRef, nPrefix, rLocalName, xAttrList);
+    if( Element == SwXMLTextBlockToken::OFFICE_TEXT )
+        return new SwXMLTextBlockTextContext( rLocalRef, Element, xAttrList );
+    else if( Element == SwXMLTextBlockToken::TEXT_P )
+        return new SwXMLTextBlockParContext( rLocalRef, Element, xAttrList );
     else
-        pContext = new SvXMLImportContext( rLocalRef, nPrefix, rLocalName);
-    return pContext;
+        return new SvXMLImportContext( rLocalRef );
 }
+
 SwXMLTextBlockBodyContext::~SwXMLTextBlockBodyContext ( void )
 {
 }
+
 SwXMLTextBlockParContext::SwXMLTextBlockParContext(
-   SwXMLTextBlockImport& rImport,
-   sal_uInt16 nPrefix,
-   const OUString& rLocalName,
-   const uno::Reference<
-   xml::sax::XAttributeList > & ) :
-    SvXMLImportContext ( rImport, nPrefix, rLocalName ),
-    rLocalRef(rImport)
+    SwXMLTextBlockImport& rImport,
+    sal_Int32 /*Element*/,
+    const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ ) :
+    SvXMLImportContext( rImport ),
+    rLocalRef( rImport )
 {
 }
 
-void SwXMLTextBlockParContext::Characters( const OUString& rChars )
+void SAL_CALL SwXMLTextBlockParContext::characters( const OUString & aChars )
+    throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
 {
-    rLocalRef.m_rText += rChars;
+    rLocalRef.m_rText += aChars;
 }
+
 SwXMLTextBlockParContext::~SwXMLTextBlockParContext ( void )
 {
     if (rLocalRef.bTextOnly)
@@ -335,20 +346,12 @@ SwXMLTextBlockParContext::~SwXMLTextBlockParContext ( void )
 }
 
 // SwXMLBlockListImport //////////////////////////////
-
-sal_Char const sXML_np__block_list[] = "_block-list";
-sal_Char const sXML_np__office[] = "_ooffice";
-sal_Char const sXML_np__text[] = "_otext";
-
 SwXMLBlockListImport::SwXMLBlockListImport(
     const uno::Reference< uno::XComponentContext > xContext,
     SwXMLTextBlocks &rBlocks )
 :   SvXMLImport( xContext, "", 0 ),
     rBlockList (rBlocks)
 {
-    GetNamespaceMap().Add( OUString ( sXML_np__block_list ),
-                           GetXMLToken ( XML_N_BLOCK_LIST ),
-                           XML_NAMESPACE_BLOCKLIST );
 }
 
 SwXMLBlockListImport::~SwXMLBlockListImport ( void )
@@ -356,19 +359,13 @@ SwXMLBlockListImport::~SwXMLBlockListImport ( void )
 {
 }
 
-SvXMLImportContext *SwXMLBlockListImport::CreateContext(
-        sal_uInt16 nPrefix,
-        const OUString& rLocalName,
-        const uno::Reference< xml::sax::XAttributeList > & xAttrList )
+SvXMLImportContext* SwXMLBlockListImport::CreateFastContext( sal_Int32 Element,
+    const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
 {
-    SvXMLImportContext *pContext = 0;
-    if ( XML_NAMESPACE_BLOCKLIST == nPrefix &&
-         IsXMLToken ( rLocalName, XML_BLOCK_LIST ) )
-        pContext = new SwXMLBlockListContext( *this, nPrefix, rLocalName,
-                                              xAttrList );
+    if( Element == SwXMLBlockListToken::BLOCK_LIST )
+        return new SwXMLBlockListContext( *this, Element, xAttrList );
     else
-        pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
-    return pContext;
+        return SvXMLImport::CreateFastContext( Element, xAttrList );
 }
 
 SwXMLTextBlockImport::SwXMLTextBlockImport(
@@ -381,12 +378,6 @@ SwXMLTextBlockImport::SwXMLTextBlockImport(
     bTextOnly ( bNewTextOnly ),
     m_rText ( rNewText )
 {
-    GetNamespaceMap().Add( OUString( sXML_np__office ),
-                            GetXMLToken(XML_N_OFFICE_OOO),
-                            XML_NAMESPACE_OFFICE );
-    GetNamespaceMap().Add( OUString( sXML_np__text ),
-                            GetXMLToken(XML_N_TEXT_OOO),
-                            XML_NAMESPACE_TEXT );
 }
 
 SwXMLTextBlockImport::~SwXMLTextBlockImport ( void )
@@ -394,19 +385,16 @@ SwXMLTextBlockImport::~SwXMLTextBlockImport ( void )
 {
 }
 
-SvXMLImportContext *SwXMLTextBlockImport::CreateContext(
-        sal_uInt16 nPrefix,
-        const OUString& rLocalName,
-        const uno::Reference< xml::sax::XAttributeList > & xAttrList )
+SvXMLImportContext* SwXMLTextBlockImport::CreateFastContext( sal_Int32 Element,
+    const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
 {
-    SvXMLImportContext *pContext = 0;
-    if( XML_NAMESPACE_OFFICE == nPrefix &&
-        IsXMLToken ( rLocalName, bTextOnly ? XML_DOCUMENT : XML_DOCUMENT_CONTENT ) )
-        pContext = new SwXMLTextBlockDocumentContext( *this, nPrefix, rLocalName, xAttrList );
+    if( Element == SwXMLTextBlockToken::OFFICE_DOCUMENT ||
+        Element == SwXMLTextBlockToken::OFFICE_DOCUMENT_CONTENT )
+        return new SwXMLTextBlockDocumentContext( *this, Element, xAttrList );
     else
-        pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
-    return pContext;
+        return SvXMLImport::CreateFastContext( Element, xAttrList );
 }
+
 void SAL_CALL SwXMLTextBlockImport::endDocument(void)
         throw( xml::sax::SAXException, uno::RuntimeException, std::exception )
 {
diff --git a/sw/source/core/swg/SwXMLTextBlocks1.cxx b/sw/source/core/swg/SwXMLTextBlocks1.cxx
index bbae940..0f0ce4a 100644
--- a/sw/source/core/swg/SwXMLTextBlocks1.cxx
+++ b/sw/source/core/swg/SwXMLTextBlocks1.cxx
@@ -27,6 +27,8 @@
 #include <com/sun/star/xml/sax/InputSource.hpp>
 #include <com/sun/star/io/XActiveDataSource.hpp>
 #include <com/sun/star/xml/sax/Parser.hpp>
+#include <com/sun/star/xml/sax/FastParser.hpp>
+#include <com/sun/star/xml/sax/FastToken.hpp>
 #include <com/sun/star/xml/sax/Writer.hpp>
 #include <com/sun/star/document/XStorageBasedDocument.hpp>
 #include <doc.hxx>
@@ -35,6 +37,7 @@
 #include <SwXMLTextBlocks.hxx>
 #include <SwXMLBlockImport.hxx>
 #include <SwXMLBlockExport.hxx>
+#include <xmloff/xmlnmspe.hxx>
 #include <swevent.hxx>
 #include <swerror.h>
 
@@ -43,6 +46,8 @@ const char XMLN_BLOCKLIST[] = "BlockList.xml";
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::container;
+using namespace css::xml::sax;
+using namespace xmloff::token;
 
 using ::xmloff::token::XML_BLOCK_LIST;
 using ::xmloff::token::XML_UNFORMATTED_TEXT;
@@ -101,11 +106,17 @@ sal_uLong SwXMLTextBlocks::GetDoc( sal_uInt16 nIdx )
             aParserInput.aInputStream = xStream->getInputStream();
 
             // get filter
-            uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( xContext, *this, aCur, true );
+            // uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( *this, aCur, sal_True );
+            uno::Reference< xml::sax::XFastDocumentHandler > xFilter = new SwXMLTextBlockImport( xContext, *this, aCur, true );
+            uno::Reference< xml::sax::XFastTokenHandler > xTokenHandler = new SwXMLTextBlockTokenHandler();
 
             // connect parser and filter
-            uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(xContext);
-            xParser->setDocumentHandler( xFilter );
+            uno::Reference< xml::sax::XFastParser > xParser = xml::sax::FastParser::create(xContext);
+            xParser->setFastDocumentHandler( xFilter );
+            xParser->setTokenHandler( xTokenHandler );
+
+            xParser->registerNamespace( "http://openoffice.org/2000/text", FastToken::NAMESPACE | XML_NAMESPACE_TEXT );
+            xParser->registerNamespace( "http://openoffice.org/2000/office", FastToken::NAMESPACE | XML_NAMESPACE_OFFICE );
 
             // parse
             try
@@ -291,11 +302,16 @@ sal_uLong SwXMLTextBlocks::GetBlockText( const OUString& rShort, OUString& rText
         // get filter
         // #110680#
         // uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( *this, rText, bTextOnly );
-        uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( xContext, *this, rText, bTextOnly );
+        uno::Reference< xml::sax::XFastDocumentHandler > xFilter = new SwXMLTextBlockImport( xContext, *this, rText, bTextOnly );
+        uno::Reference< xml::sax::XFastTokenHandler > xTokenHandler = new SwXMLTextBlockTokenHandler();
 
         // connect parser and filter
-        uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(xContext);
-        xParser->setDocumentHandler( xFilter );
+        uno::Reference< xml::sax::XFastParser > xParser = xml::sax::FastParser::create(xContext);
+        xParser->setFastDocumentHandler( xFilter );
+        xParser->setTokenHandler( xTokenHandler );
+
+        xParser->registerNamespace( "urn:oasis:names:tc:opendocument:xmlns:office:1.0", FastToken::NAMESPACE | XML_NAMESPACE_OFFICE );
+        xParser->registerNamespace( "urn:oasis:names:tc:opendocument:xmlns:text:1.0", FastToken::NAMESPACE | XML_NAMESPACE_TEXT );
 
         // parse
         try
@@ -418,11 +434,14 @@ void SwXMLTextBlocks::ReadInfo( void )
         aParserInput.aInputStream = xDocStream->getInputStream();
 
         // get filter
-        uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLBlockListImport( xContext, *this );
+        uno::Reference< xml::sax::XFastDocumentHandler > xFilter = new SwXMLBlockListImport( xContext, *this );
+        uno::Reference< xml::sax::XFastTokenHandler > xTokenHandler = new SwXMLBlockListTokenHandler();
 
         // connect parser and filter
-        uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
-        xParser->setDocumentHandler( xFilter );
+        uno::Reference< xml::sax::XFastParser > xParser = xml::sax::FastParser::create(xContext);
+        xParser->setFastDocumentHandler( xFilter );
+        xParser->registerNamespace( "http://openoffice.org/2001/block-list", FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST );
+        xParser->setTokenHandler( xTokenHandler );
 
         // parse
         try
diff --git a/sw/source/core/swg/TextBlockTokens.txt b/sw/source/core/swg/TextBlockTokens.txt
new file mode 100644
index 0000000..8698704
--- /dev/null
+++ b/sw/source/core/swg/TextBlockTokens.txt
@@ -0,0 +1,5 @@
+body
+text
+document
+document-content
+p


More information about the Libreoffice-commits mailing list