Kaydet (Commit) c2c09897 authored tarafından Daniel Sikeler's avatar Daniel Sikeler Kaydeden (comit) Matúš Kukan

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 c1e90457
(Also pushing again follow-up c940d4d3
"loplugin:saloverride" and 5f0f3d4e
"Work around -Werror,-Wdeprecated-register")
The commits were reverted in 7ef4457b

Change-Id: I08cd852fa751f98fd0ac6a55dda22f82a869b4d8
üst 55dc40bc
# -*- 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:
...@@ -36,6 +36,7 @@ $(eval $(call gb_Library_set_include,sw,\ ...@@ -36,6 +36,7 @@ $(eval $(call gb_Library_set_include,sw,\
$(eval $(call gb_Library_use_custom_headers,sw,\ $(eval $(call gb_Library_use_custom_headers,sw,\
officecfg/registry \ officecfg/registry \
sw/generated \
)) ))
$(eval $(call gb_Library_use_sdk_api,sw)) $(eval $(call gb_Library_use_sdk_api,sw))
......
...@@ -21,6 +21,7 @@ $(eval $(call gb_Module_Module,sw)) ...@@ -21,6 +21,7 @@ $(eval $(call gb_Module_Module,sw))
$(eval $(call gb_Module_add_targets,sw,\ $(eval $(call gb_Module_add_targets,sw,\
$(call gb_Helper_optional,DESKTOP,Executable_tiledrendering) \ $(call gb_Helper_optional,DESKTOP,Executable_tiledrendering) \
CustomTarget_generated \
Library_msword \ Library_msword \
Library_sw \ Library_sw \
Library_swd \ Library_swd \
......
...@@ -21,6 +21,14 @@ ...@@ -21,6 +21,14 @@
#define INCLUDED_SW_SOURCE_CORE_INC_SWXMLBLOCKIMPORT_HXX #define INCLUDED_SW_SOURCE_CORE_INC_SWXMLBLOCKIMPORT_HXX
#include <xmloff/xmlimp.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 SwXMLTextBlocks;
class SwXMLBlockListImport : public SvXMLImport class SwXMLBlockListImport : public SvXMLImport
...@@ -31,10 +39,8 @@ private: ...@@ -31,10 +39,8 @@ private:
protected: protected:
// This method is called after the namespace map has been updated, but // This method is called after the namespace map has been updated, but
// before a context for the current element has been pushed. // before a context for the current element has been pushed.
virtual SvXMLImportContext *CreateContext( sal_uInt16 nPrefix, virtual SvXMLImportContext* CreateFastContext( sal_Int32 Element,
const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) SAL_OVERRIDE;
const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
public: public:
SwXMLBlockListImport( SwXMLBlockListImport(
...@@ -57,10 +63,8 @@ private: ...@@ -57,10 +63,8 @@ private:
protected: protected:
// This method is called after the namespace map has been updated, but // This method is called after the namespace map has been updated, but
// before a context for the current element has been pushed. // before a context for the current element has been pushed.
virtual SvXMLImportContext *CreateContext( sal_uInt16 nPrefix, virtual SvXMLImportContext* CreateFastContext( sal_Int32 Element,
const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) SAL_OVERRIDE;
const ::com::sun::star::uno::Reference<
::com::sun::star::xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
public: public:
bool bTextOnly; bool bTextOnly;
...@@ -79,6 +83,62 @@ public: ...@@ -79,6 +83,62 @@ public:
throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE; 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 #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
abbreviated-name
block
block-list
list-name
name
package-name
unformatted-text
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include <com/sun/star/xml/sax/InputSource.hpp> #include <com/sun/star/xml/sax/InputSource.hpp>
#include <com/sun/star/io/XActiveDataSource.hpp> #include <com/sun/star/io/XActiveDataSource.hpp>
#include <com/sun/star/xml/sax/Parser.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/xml/sax/Writer.hpp>
#include <com/sun/star/document/XStorageBasedDocument.hpp> #include <com/sun/star/document/XStorageBasedDocument.hpp>
#include <doc.hxx> #include <doc.hxx>
...@@ -35,6 +37,7 @@ ...@@ -35,6 +37,7 @@
#include <SwXMLTextBlocks.hxx> #include <SwXMLTextBlocks.hxx>
#include <SwXMLBlockImport.hxx> #include <SwXMLBlockImport.hxx>
#include <SwXMLBlockExport.hxx> #include <SwXMLBlockExport.hxx>
#include <xmloff/xmlnmspe.hxx>
#include <swevent.hxx> #include <swevent.hxx>
#include <swerror.h> #include <swerror.h>
...@@ -43,6 +46,8 @@ const char XMLN_BLOCKLIST[] = "BlockList.xml"; ...@@ -43,6 +46,8 @@ const char XMLN_BLOCKLIST[] = "BlockList.xml";
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::container; 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_BLOCK_LIST;
using ::xmloff::token::XML_UNFORMATTED_TEXT; using ::xmloff::token::XML_UNFORMATTED_TEXT;
...@@ -101,11 +106,17 @@ sal_uLong SwXMLTextBlocks::GetDoc( sal_uInt16 nIdx ) ...@@ -101,11 +106,17 @@ sal_uLong SwXMLTextBlocks::GetDoc( sal_uInt16 nIdx )
aParserInput.aInputStream = xStream->getInputStream(); aParserInput.aInputStream = xStream->getInputStream();
// get filter // 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 // connect parser and filter
uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(xContext); uno::Reference< xml::sax::XFastParser > xParser = xml::sax::FastParser::create(xContext);
xParser->setDocumentHandler( xFilter ); 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 // parse
try try
...@@ -291,11 +302,16 @@ sal_uLong SwXMLTextBlocks::GetBlockText( const OUString& rShort, OUString& rText ...@@ -291,11 +302,16 @@ sal_uLong SwXMLTextBlocks::GetBlockText( const OUString& rShort, OUString& rText
// get filter // get filter
// #110680# // #110680#
// uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( *this, rText, bTextOnly ); // 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 // connect parser and filter
uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(xContext); uno::Reference< xml::sax::XFastParser > xParser = xml::sax::FastParser::create(xContext);
xParser->setDocumentHandler( xFilter ); 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 // parse
try try
...@@ -418,11 +434,14 @@ void SwXMLTextBlocks::ReadInfo( void ) ...@@ -418,11 +434,14 @@ void SwXMLTextBlocks::ReadInfo( void )
aParserInput.aInputStream = xDocStream->getInputStream(); aParserInput.aInputStream = xDocStream->getInputStream();
// get filter // 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 // connect parser and filter
uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext ); uno::Reference< xml::sax::XFastParser > xParser = xml::sax::FastParser::create(xContext);
xParser->setDocumentHandler( xFilter ); xParser->setFastDocumentHandler( xFilter );
xParser->registerNamespace( "http://openoffice.org/2001/block-list", FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST );
xParser->setTokenHandler( xTokenHandler );
// parse // parse
try try
......
body
text
document
document-content
p
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment