Move this header out into a public place.
Change-Id: I356b26947d1018276d8a9ff6012fdad3ca2c0fd8
This commit is contained in:
parent
8ef9d65177
commit
2130fd9d61
@ -28,6 +28,10 @@ namespace oox {
|
|||||||
class StorageBase;
|
class StorageBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace sax_fastparser {
|
||||||
|
class FastSaxParser;
|
||||||
|
}
|
||||||
|
|
||||||
namespace oox {
|
namespace oox {
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
@ -85,6 +89,8 @@ private:
|
|||||||
::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >
|
::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >
|
||||||
mxTokenHandler;
|
mxTokenHandler;
|
||||||
const NamespaceMap& mrNamespaceMap;
|
const NamespaceMap& mrNamespaceMap;
|
||||||
|
|
||||||
|
sax_fastparser::FastSaxParser* mpParser;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _SAX_FASTPARSER_HXX_
|
#ifndef INCLUDED_SAX_FASTPARSER_HXX
|
||||||
#define _SAX_FASTPARSER_HXX_
|
#define INCLUDED_SAX_FASTPARSER_HXX
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -36,25 +36,23 @@
|
|||||||
#include <cppuhelper/implbase2.hxx>
|
#include <cppuhelper/implbase2.hxx>
|
||||||
|
|
||||||
#include <expat.h>
|
#include <expat.h>
|
||||||
#include "xml2utf.hxx"
|
#include "saxdllapi.h"
|
||||||
|
|
||||||
#include <sax/fastattribs.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 {
|
namespace sax_fastparser {
|
||||||
|
|
||||||
struct Event;
|
struct Event;
|
||||||
class FastLocatorImpl;
|
class FastLocatorImpl;
|
||||||
struct NamespaceDefine;
|
struct NamespaceDefine;
|
||||||
|
struct Entity;
|
||||||
|
|
||||||
typedef ::boost::shared_ptr< NamespaceDefine > NamespaceDefineRef;
|
typedef ::boost::shared_ptr< NamespaceDefine > NamespaceDefineRef;
|
||||||
|
|
||||||
typedef ::boost::unordered_map< OUString, sal_Int32,
|
typedef ::boost::unordered_map< OUString, sal_Int32,
|
||||||
OUStringHash, ::std::equal_to< OUString > > NamespaceMap;
|
OUStringHash, ::std::equal_to< OUString > > NamespaceMap;
|
||||||
|
|
||||||
struct NameWithToken
|
struct SAX_DLLPUBLIC NameWithToken
|
||||||
{
|
{
|
||||||
OUString msName;
|
OUString msName;
|
||||||
sal_Int32 mnToken;
|
sal_Int32 mnToken;
|
||||||
@ -66,7 +64,8 @@ typedef std::vector<Event> EventList;
|
|||||||
|
|
||||||
enum CallbackType { INVALID, START_ELEMENT, END_ELEMENT, CHARACTERS, DONE, EXCEPTION };
|
enum CallbackType { INVALID, START_ELEMENT, END_ELEMENT, CHARACTERS, DONE, EXCEPTION };
|
||||||
|
|
||||||
struct Event {
|
struct Event
|
||||||
|
{
|
||||||
OUString msChars;
|
OUString msChars;
|
||||||
sal_Int32 mnElementToken;
|
sal_Int32 mnElementToken;
|
||||||
OUString msNamespace;
|
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::XFastDocumentHandler > mxDocumentHandler;
|
||||||
::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxTokenHandler;
|
::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
|
// 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:
|
public:
|
||||||
FastSaxParser();
|
FastSaxParser();
|
@ -38,7 +38,6 @@ $(eval $(call gb_Library_use_static_libraries,fastsax,\
|
|||||||
))
|
))
|
||||||
|
|
||||||
$(eval $(call gb_Library_add_exception_objects,fastsax,\
|
$(eval $(call gb_Library_add_exception_objects,fastsax,\
|
||||||
sax/source/fastparser/facreg \
|
|
||||||
sax/source/fastparser/fastparser \
|
sax/source/fastparser/fastparser \
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@ -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: */
|
|
@ -27,11 +27,17 @@
|
|||||||
#include <com/sun/star/xml/sax/SAXParseException.hpp>
|
#include <com/sun/star/xml/sax/SAXParseException.hpp>
|
||||||
#include <com/sun/star/xml/sax/FastToken.hpp>
|
#include <com/sun/star/xml/sax/FastToken.hpp>
|
||||||
#include <cppuhelper/supportsservice.hxx>
|
#include <cppuhelper/supportsservice.hxx>
|
||||||
|
#include <cppuhelper/factory.hxx>
|
||||||
|
|
||||||
#include "fastparser.hxx"
|
#include "sax/fastparser.hxx"
|
||||||
|
|
||||||
|
#include "xml2utf.hxx"
|
||||||
|
|
||||||
#include <string.h>
|
#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 ::std;
|
||||||
using namespace ::osl;
|
using namespace ::osl;
|
||||||
using namespace ::cppu;
|
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 ) {}
|
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
|
class ParserThread: public salhelper::Thread
|
||||||
{
|
{
|
||||||
FastSaxParser *mpParser;
|
FastSaxParser *mpParser;
|
||||||
@ -1182,4 +1241,47 @@ int FastSaxParser::callbackExternalEntityRef(
|
|||||||
|
|
||||||
} // namespace sax_fastparser
|
} // 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: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user