summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2013-12-02 18:32:42 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2013-12-04 11:41:34 -0500
commitcd4183a57fd603a7a603514d69cbd50aa19651b4 (patch)
treee9cd8c07a0def311f002cd5de7bde3c29ef22634 /sax
parenta45b87dde5a7ba3ca0baba40b00b162e428475bb (diff)
Move this header out into a public place.
Change-Id: I356b26947d1018276d8a9ff6012fdad3ca2c0fd8
Diffstat (limited to 'sax')
-rw-r--r--sax/Library_fastsax.mk1
-rw-r--r--sax/source/fastparser/facreg.cxx81
-rw-r--r--sax/source/fastparser/fastparser.cxx104
-rw-r--r--sax/source/fastparser/fastparser.hxx233
4 files changed, 103 insertions, 316 deletions
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: */
diff --git a/sax/source/fastparser/fastparser.hxx b/sax/source/fastparser/fastparser.hxx
deleted file mode 100644
index 2943509e8ff2..000000000000
--- a/sax/source/fastparser/fastparser.hxx
+++ /dev/null
@@ -1,233 +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 .
- */
-
-#ifndef _SAX_FASTPARSER_HXX_
-#define _SAX_FASTPARSER_HXX_
-
-#include <queue>
-#include <vector>
-#include <stack>
-#include <boost/optional.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/unordered_map.hpp>
-#include <osl/conditn.hxx>
-#include <rtl/ref.hxx>
-#include <com/sun/star/xml/sax/XFastContextHandler.hpp>
-#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
-#include <com/sun/star/xml/sax/XFastParser.hpp>
-#include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
-#include <com/sun/star/lang/XServiceInfo.hpp>
-#include <cppuhelper/implbase2.hxx>
-
-#include <expat.h>
-#include "xml2utf.hxx"
-
-#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;
-
-typedef ::boost::shared_ptr< NamespaceDefine > NamespaceDefineRef;
-
-typedef ::boost::unordered_map< OUString, sal_Int32,
- OUStringHash, ::std::equal_to< OUString > > NamespaceMap;
-
-struct NameWithToken
-{
- OUString msName;
- sal_Int32 mnToken;
-
- NameWithToken(const OUString& sName, const sal_Int32& nToken);
-};
-
-typedef std::vector<Event> 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 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();
-};
-
-// --------------------------------------------------------------------
-
-// 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 >
-{
-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: */