diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-12-02 18:32:42 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-12-02 19:32:28 -0500 |
commit | 2130fd9d610bf12b09fe29bafd46a673b21e064d (patch) | |
tree | 5ddd7b4ccbda733cc06b2fa356ee2ff9834bbf91 | |
parent | 8ef9d651770ef8423651b9163007975d16449fd3 (diff) |
Move this header out into a public place.
Change-Id: I356b26947d1018276d8a9ff6012fdad3ca2c0fd8
-rw-r--r-- | include/oox/core/fastparser.hxx | 6 | ||||
-rw-r--r-- | include/sax/fastparser.hxx (renamed from sax/source/fastparser/fastparser.hxx) | 74 | ||||
-rw-r--r-- | sax/Library_fastsax.mk | 1 | ||||
-rw-r--r-- | sax/source/fastparser/facreg.cxx | 81 | ||||
-rw-r--r-- | sax/source/fastparser/fastparser.cxx | 104 |
5 files changed, 118 insertions, 148 deletions
diff --git a/include/oox/core/fastparser.hxx b/include/oox/core/fastparser.hxx index b454caffd4b8..fd982413329c 100644 --- a/include/oox/core/fastparser.hxx +++ b/include/oox/core/fastparser.hxx @@ -28,6 +28,10 @@ namespace oox { class StorageBase; } +namespace sax_fastparser { + class FastSaxParser; +} + namespace oox { namespace core { @@ -85,6 +89,8 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxTokenHandler; const NamespaceMap& mrNamespaceMap; + + sax_fastparser::FastSaxParser* mpParser; }; // ============================================================================ diff --git a/sax/source/fastparser/fastparser.hxx b/include/sax/fastparser.hxx index 2943509e8ff2..3a8ae5302073 100644 --- a/sax/source/fastparser/fastparser.hxx +++ b/include/sax/fastparser.hxx @@ -17,8 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef _SAX_FASTPARSER_HXX_ -#define _SAX_FASTPARSER_HXX_ +#ifndef INCLUDED_SAX_FASTPARSER_HXX +#define INCLUDED_SAX_FASTPARSER_HXX #include <queue> #include <vector> @@ -36,25 +36,23 @@ #include <cppuhelper/implbase2.hxx> #include <expat.h> -#include "xml2utf.hxx" +#include "saxdllapi.h" #include <sax/fastattribs.hxx> -#define PARSER_IMPLEMENTATION_NAME "com.sun.star.comp.extensions.xml.sax.FastParser" -#define PARSER_SERVICE_NAME "com.sun.star.xml.sax.FastParser" - namespace sax_fastparser { struct Event; class FastLocatorImpl; struct NamespaceDefine; +struct Entity; typedef ::boost::shared_ptr< NamespaceDefine > NamespaceDefineRef; typedef ::boost::unordered_map< OUString, sal_Int32, OUStringHash, ::std::equal_to< OUString > > NamespaceMap; -struct NameWithToken +struct SAX_DLLPUBLIC NameWithToken { OUString msName; sal_Int32 mnToken; @@ -66,7 +64,8 @@ typedef std::vector<Event> EventList; enum CallbackType { INVALID, START_ELEMENT, END_ELEMENT, CHARACTERS, DONE, EXCEPTION }; -struct Event { +struct Event +{ OUString msChars; sal_Int32 mnElementToken; OUString msNamespace; @@ -88,7 +87,7 @@ struct SaxContext // -------------------------------------------------------------------- -struct ParserData +struct SAX_DLLPUBLIC ParserData { ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastDocumentHandler > mxDocumentHandler; ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxTokenHandler; @@ -103,63 +102,8 @@ struct ParserData // -------------------------------------------------------------------- -// Entity binds all information needed for a single file | single call of parseStream -struct Entity : public ParserData -{ - // Amount of work producer sends to consumer in one iteration: - static const size_t mnEventListSize = 1000; - - // unique for each Entity instance: - - // Number of valid events in mpProducedEvents: - size_t mnProducedEventsSize; - EventList *mpProducedEvents; - std::queue< EventList * > maPendingEvents; - std::queue< EventList * > maUsedEvents; - osl::Mutex maEventProtector; - - static const size_t mnEventLowWater = 4; - static const size_t mnEventHighWater = 8; - osl::Condition maConsumeResume; - osl::Condition maProduceResume; - // Event we use to store data if threading is disabled: - Event maSharedEvent; - - // copied in copy constructor: - - // Allow to disable threading for small documents: - bool mbEnableThreads; - ::com::sun::star::xml::sax::InputSource maStructSource; - XML_Parser mpParser; - ::sax_expatwrap::XMLFile2UTFConverter maConverter; - - // Exceptions cannot be thrown through the C-XmlParser (possible resource leaks), - // therefore the exception must be saved somewhere. - ::com::sun::star::uno::Any maSavedException; - - ::std::stack< NameWithToken > maNamespaceStack; - /* Context for main thread consuming events. - * startElement() stores the data, which characters() and endElement() uses - */ - ::std::stack< SaxContext> maContextStack; - // Determines which elements of maNamespaceDefines are valid in current context - ::std::stack< sal_uInt32 > maNamespaceCount; - ::std::vector< NamespaceDefineRef > maNamespaceDefines; - - explicit Entity( const ParserData& rData ); - Entity( const Entity& rEntity ); - ~Entity(); - void startElement( Event *pEvent ); - void characters( const OUString& sChars ); - void endElement(); - EventList* getEventList(); - Event& getEvent( CallbackType aType ); -}; - -// -------------------------------------------------------------------- - // This class implements the external Parser interface -class FastSaxParser : public ::cppu::WeakImplHelper2< ::com::sun::star::xml::sax::XFastParser, ::com::sun::star::lang::XServiceInfo > +class SAX_DLLPUBLIC FastSaxParser : public ::cppu::WeakImplHelper2< ::com::sun::star::xml::sax::XFastParser, ::com::sun::star::lang::XServiceInfo > { public: FastSaxParser(); diff --git a/sax/Library_fastsax.mk b/sax/Library_fastsax.mk index ab0c4e6e14d6..863336fcd9ce 100644 --- a/sax/Library_fastsax.mk +++ b/sax/Library_fastsax.mk @@ -38,7 +38,6 @@ $(eval $(call gb_Library_use_static_libraries,fastsax,\ )) $(eval $(call gb_Library_add_exception_objects,fastsax,\ - sax/source/fastparser/facreg \ sax/source/fastparser/fastparser \ )) diff --git a/sax/source/fastparser/facreg.cxx b/sax/source/fastparser/facreg.cxx deleted file mode 100644 index fbf746f680fd..000000000000 --- a/sax/source/fastparser/facreg.cxx +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <cppuhelper/factory.hxx> -#include <cppuhelper/weak.hxx> -#include <cppuhelper/implbase2.hxx> - -#include "fastparser.hxx" - -using namespace sax_fastparser; -using namespace ::cppu; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::registry; -using namespace ::com::sun::star::lang; - -namespace sax_fastparser -{ - -Reference< XInterface > SAL_CALL FastSaxParser_CreateInstance( - SAL_UNUSED_PARAMETER const Reference< XMultiServiceFactory > & ) - throw(Exception) -{ - FastSaxParser *p = new FastSaxParser; - return Reference< XInterface > ( (OWeakObject * ) p ); -} - -} - -extern "C" -{ - -SAL_DLLPUBLIC_EXPORT void * SAL_CALL fastsax_component_getFactory( - const sal_Char * pImplName, void * pServiceManager, - SAL_UNUSED_PARAMETER void * /*pRegistryKey*/ ) -{ - void * pRet = 0; - - if (pServiceManager ) - { - Reference< XSingleServiceFactory > xRet; - Reference< XMultiServiceFactory > xSMgr( reinterpret_cast< XMultiServiceFactory * > ( pServiceManager ) ); - - OUString aImplementationName( OUString::createFromAscii( pImplName ) ); - - if ( aImplementationName == PARSER_IMPLEMENTATION_NAME ) - { - xRet = createSingleFactory( xSMgr, aImplementationName, - FastSaxParser_CreateInstance, - FastSaxParser::getSupportedServiceNames_Static() ); - } - - if (xRet.is()) - { - xRet->acquire(); - pRet = xRet.get(); - } - } - - return pRet; -} - - -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx index 75974b8befa0..9f60b72c2d5c 100644 --- a/sax/source/fastparser/fastparser.cxx +++ b/sax/source/fastparser/fastparser.cxx @@ -27,11 +27,17 @@ #include <com/sun/star/xml/sax/SAXParseException.hpp> #include <com/sun/star/xml/sax/FastToken.hpp> #include <cppuhelper/supportsservice.hxx> +#include <cppuhelper/factory.hxx> -#include "fastparser.hxx" +#include "sax/fastparser.hxx" + +#include "xml2utf.hxx" #include <string.h> +#define PARSER_IMPLEMENTATION_NAME "com.sun.star.comp.extensions.xml.sax.FastParser" +#define PARSER_SERVICE_NAME "com.sun.star.xml.sax.FastParser" + using namespace ::std; using namespace ::osl; using namespace ::cppu; @@ -105,6 +111,59 @@ struct NamespaceDefine NamespaceDefine( const OString& rPrefix, sal_Int32 nToken, const OUString& rNamespaceURL ) : maPrefix( rPrefix ), mnToken( nToken ), maNamespaceURL( rNamespaceURL ) {} }; +// Entity binds all information needed for a single file | single call of parseStream +struct Entity : public ParserData +{ + // Amount of work producer sends to consumer in one iteration: + static const size_t mnEventListSize = 1000; + + // unique for each Entity instance: + + // Number of valid events in mpProducedEvents: + size_t mnProducedEventsSize; + EventList *mpProducedEvents; + std::queue< EventList * > maPendingEvents; + std::queue< EventList * > maUsedEvents; + osl::Mutex maEventProtector; + + static const size_t mnEventLowWater = 4; + static const size_t mnEventHighWater = 8; + osl::Condition maConsumeResume; + osl::Condition maProduceResume; + // Event we use to store data if threading is disabled: + Event maSharedEvent; + + // copied in copy constructor: + + // Allow to disable threading for small documents: + bool mbEnableThreads; + ::com::sun::star::xml::sax::InputSource maStructSource; + XML_Parser mpParser; + ::sax_expatwrap::XMLFile2UTFConverter maConverter; + + // Exceptions cannot be thrown through the C-XmlParser (possible resource leaks), + // therefore the exception must be saved somewhere. + ::com::sun::star::uno::Any maSavedException; + + ::std::stack< NameWithToken > maNamespaceStack; + /* Context for main thread consuming events. + * startElement() stores the data, which characters() and endElement() uses + */ + ::std::stack< SaxContext> maContextStack; + // Determines which elements of maNamespaceDefines are valid in current context + ::std::stack< sal_uInt32 > maNamespaceCount; + ::std::vector< NamespaceDefineRef > maNamespaceDefines; + + explicit Entity( const ParserData& rData ); + Entity( const Entity& rEntity ); + ~Entity(); + void startElement( Event *pEvent ); + void characters( const OUString& sChars ); + void endElement(); + EventList* getEventList(); + Event& getEvent( CallbackType aType ); +}; + class ParserThread: public salhelper::Thread { FastSaxParser *mpParser; @@ -1182,4 +1241,47 @@ int FastSaxParser::callbackExternalEntityRef( } // namespace sax_fastparser +Reference< XInterface > SAL_CALL FastSaxParser_CreateInstance( + SAL_UNUSED_PARAMETER const Reference< XMultiServiceFactory > & ) + throw(Exception) +{ + sax_fastparser::FastSaxParser *p = new sax_fastparser::FastSaxParser; + return Reference< XInterface > ( (OWeakObject * ) p ); +} + +extern "C" { + +SAL_DLLPUBLIC_EXPORT void * SAL_CALL fastsax_component_getFactory( + const sal_Char * pImplName, void * pServiceManager, + SAL_UNUSED_PARAMETER void * /*pRegistryKey*/ ) +{ + void * pRet = 0; + + if (pServiceManager ) + { + Reference< XSingleServiceFactory > xRet; + Reference< XMultiServiceFactory > xSMgr( reinterpret_cast< XMultiServiceFactory * > ( pServiceManager ) ); + + OUString aImplementationName( OUString::createFromAscii( pImplName ) ); + + if ( aImplementationName == PARSER_IMPLEMENTATION_NAME ) + { + xRet = createSingleFactory( + xSMgr, aImplementationName, + FastSaxParser_CreateInstance, + sax_fastparser::FastSaxParser::getSupportedServiceNames_Static() ); + } + + if (xRet.is()) + { + xRet->acquire(); + pRet = xRet.get(); + } + } + + return pRet; +} + +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |