From 2130fd9d610bf12b09fe29bafd46a673b21e064d Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Mon, 2 Dec 2013 18:32:42 -0500 Subject: Move this header out into a public place. Change-Id: I356b26947d1018276d8a9ff6012fdad3ca2c0fd8 --- include/oox/core/fastparser.hxx | 6 ++ include/sax/fastparser.hxx | 177 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 include/sax/fastparser.hxx (limited to 'include') 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/include/sax/fastparser.hxx b/include/sax/fastparser.hxx new file mode 100644 index 000000000000..3a8ae5302073 --- /dev/null +++ b/include/sax/fastparser.hxx @@ -0,0 +1,177 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_SAX_FASTPARSER_HXX +#define INCLUDED_SAX_FASTPARSER_HXX + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "saxdllapi.h" + +#include + +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 SAX_DLLPUBLIC NameWithToken +{ + OUString msName; + sal_Int32 mnToken; + + NameWithToken(const OUString& sName, const sal_Int32& nToken); +}; + +typedef std::vector EventList; + +enum CallbackType { INVALID, START_ELEMENT, END_ELEMENT, CHARACTERS, DONE, EXCEPTION }; + +struct Event +{ + OUString msChars; + sal_Int32 mnElementToken; + OUString msNamespace; + OUString msElementName; + rtl::Reference< FastAttributeList > mxAttributes; + CallbackType maType; +}; + +// -------------------------------------------------------------------- + +struct SaxContext +{ + ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > mxContext; + sal_Int32 mnElementToken; + boost::optional< OUString > maNamespace; + boost::optional< OUString > maElementName; + SaxContext( sal_Int32 nElementToken, const OUString& aNamespace, const OUString& aElementName ); +}; + +// -------------------------------------------------------------------- + +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; + FastTokenHandlerBase *mpTokenHandler; + ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XErrorHandler > mxErrorHandler; + ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XEntityResolver > mxEntityResolver; + ::com::sun::star::lang::Locale maLocale; + + ParserData(); + ~ParserData(); +}; + +// -------------------------------------------------------------------- + +// This class implements the external Parser interface +class SAX_DLLPUBLIC FastSaxParser : public ::cppu::WeakImplHelper2< ::com::sun::star::xml::sax::XFastParser, ::com::sun::star::lang::XServiceInfo > +{ +public: + FastSaxParser(); + virtual ~FastSaxParser(); + + // The implementation details + static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static(void); + + // XFastParser + virtual void SAL_CALL parseStream( const ::com::sun::star::xml::sax::InputSource& aInputSource ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setFastDocumentHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastDocumentHandler >& Handler ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setTokenHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& Handler ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL registerNamespace( const OUString& NamespaceURL, sal_Int32 NamespaceToken ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getNamespaceURL( const OUString& rPrefix ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setErrorHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XErrorHandler >& Handler ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setEntityResolver( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XEntityResolver >& Resolver ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setLocale( const ::com::sun::star::lang::Locale& rLocale ) throw (::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); + + // called by the C callbacks of the expat parser + void callbackStartElement( const XML_Char* name, const XML_Char** atts ); + void callbackEndElement( const XML_Char* name ); + void callbackCharacters( const XML_Char* s, int nLen ); + int callbackExternalEntityRef( XML_Parser parser, const XML_Char *openEntityNames, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId); + void callbackEntityDecl(const XML_Char *entityName, int is_parameter_entity, + const XML_Char *value, int value_length, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId, + const XML_Char *notationName); + + void pushEntity( const Entity& rEntity ); + void popEntity(); + Entity& getEntity(); + void parse(); + void produce( CallbackType aType ); + +private: + bool consume(EventList *); + void deleteUsedEvents(); + + sal_Int32 GetToken( const sal_Char* pToken, sal_Int32 nTokenLen = 0 ); + sal_Int32 GetTokenWithPrefix( const sal_Char*pPrefix, int nPrefixLen, const sal_Char* pName, int nNameLen ) throw (::com::sun::star::xml::sax::SAXException); + OUString GetNamespaceURL( const OString& rPrefix ) throw (::com::sun::star::xml::sax::SAXException); + OUString GetNamespaceURL( const sal_Char*pPrefix, int nPrefixLen ) throw (::com::sun::star::xml::sax::SAXException); + sal_Int32 GetNamespaceToken( const OUString& rNamespaceURL ); + sal_Int32 GetTokenWithContextNamespace( sal_Int32 nNamespaceToken, const sal_Char* pName, int nNameLen ); + void DefineNamespace( const OString& rPrefix, const sal_Char* pNamespaceURL ); + + void pushContext(); + void popContext(); + + void splitName( const XML_Char *pwName, const XML_Char *&rpPrefix, sal_Int32 &rPrefixLen, const XML_Char *&rpName, sal_Int32 &rNameLen ); + +private: + osl::Mutex maMutex; ///< Protecting whole parseStream() execution + ::rtl::Reference< FastLocatorImpl > mxDocumentLocator; + NamespaceMap maNamespaceMap; + + ParserData maData; /// Cached parser configuration for next call of parseStream(). + ::std::stack< Entity > maEntities; /// Entity stack for each call of parseStream(). + FastTokenLookup maTokenLookup; +}; + +} + +#endif // _SAX_FASTPARSER_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit