diff options
Diffstat (limited to 'sax/source')
-rw-r--r-- | sax/source/fastparser/fastparser.cxx | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx index e7f21da8e658..a12bd23fc2d5 100644 --- a/sax/source/fastparser/fastparser.cxx +++ b/sax/source/fastparser/fastparser.cxx @@ -119,7 +119,6 @@ struct SaxContext } }; - struct ParserData { css::uno::Reference< css::xml::sax::XFastDocumentHandler > mxDocumentHandler; @@ -211,6 +210,11 @@ public: explicit FastSaxParserImpl(); ~FastSaxParserImpl(); +private: + ::css::uno::Sequence< ::rtl::OUString > mEntityNames; + ::css::uno::Sequence< ::rtl::OUString > mEntityReplacements; + +public: // XFastParser /// @throws css::xml::sax::SAXException /// @throws css::io::IOException @@ -230,6 +234,8 @@ public: void setErrorHandler( const css::uno::Reference< css::xml::sax::XErrorHandler >& Handler ); /// @throws css::uno::RuntimeException void setNamespaceHandler( const css::uno::Reference< css::xml::sax::XFastNamespaceHandler >& Handler); + // Fake DTD file + void setCustomEntityNames( const ::css::uno::Sequence< ::rtl::OUString >& names, const ::css::uno::Sequence< ::rtl::OUString >& replacements ); // called by the C callbacks of the expat parser void callbackStartElement( const xmlChar *localName , const xmlChar* prefix, const xmlChar* URI, @@ -237,6 +243,7 @@ public: void callbackEndElement(); void callbackCharacters( const xmlChar* s, int nLen ); void callbackProcessingInstruction( const xmlChar *target, const xmlChar *data ); + xmlEntityPtr callbackGetEntity( const xmlChar *name ); void pushEntity(const ParserData&, xml::sax::InputSource const&); void popEntity(); @@ -325,6 +332,12 @@ static void call_callbackProcessingInstruction( void *userData, const xmlChar *t pFastParser->callbackProcessingInstruction( target, data ); } +static xmlEntityPtr call_callbackGetEntity( void *userData, const xmlChar *name) +{ + FastSaxParserImpl* pFastParser = static_cast<FastSaxParserImpl*>( userData ); + return pFastParser->callbackGetEntity( name ); +} + } class FastLocatorImpl : public WeakImplHelper< XLocator > @@ -921,6 +934,12 @@ void FastSaxParserImpl::setNamespaceHandler( const Reference< XFastNamespaceHand maData.mxNamespaceHandler = Handler; } +void FastSaxParserImpl::setCustomEntityNames( const ::css::uno::Sequence< ::rtl::OUString >& names, const ::css::uno::Sequence< ::rtl::OUString >& replacements ) +{ + mEntityNames = names; + mEntityReplacements = replacements; +} + void FastSaxParserImpl::deleteUsedEvents() { Entity& rEntity = getEntity(); @@ -1036,6 +1055,7 @@ void FastSaxParserImpl::parse() callbacks.endElementNs = call_callbackEndElement; callbacks.characters = call_callbackCharacters; callbacks.processingInstruction = call_callbackProcessingInstruction; + callbacks.getEntity = call_callbackGetEntity; callbacks.initialized = XML_SAX2_MAGIC; int nRead = 0; do @@ -1344,6 +1364,21 @@ void FastSaxParserImpl::callbackProcessingInstruction( const xmlChar *target, co rEntity.processingInstruction( rEvent.msNamespace, rEvent.msElementName ); } +xmlEntityPtr FastSaxParserImpl::callbackGetEntity( const xmlChar *name ) +{ + for( size_t i = 0; i < mEntityNames.size(); ++i ) + { + if( mEntityNames[i].compareToAscii(XML_CAST(name)) == 0 ) + { + return xmlNewEntity( nullptr, + BAD_CAST(OUStringToOString(mEntityNames[i],RTL_TEXTENCODING_UTF8).getStr()), + XML_INTERNAL_GENERAL_ENTITY, nullptr, nullptr, + BAD_CAST(OUStringToOString(mEntityReplacements[i],RTL_TEXTENCODING_UTF8).getStr())); + } + } + return xmlGetPredefinedEntity(name); +} + FastSaxParser::FastSaxParser() : mpImpl(new FastSaxParserImpl) {} FastSaxParser::~FastSaxParser() @@ -1421,6 +1456,12 @@ OUString FastSaxParser::getImplementationName() return "com.sun.star.comp.extensions.xml.sax.FastParser"; } +void FastSaxParser::setCustomEntityNames( const ::css::uno::Sequence< ::rtl::OUString >& names, const ::css::uno::Sequence< ::rtl::OUString >& replacements ) +{ + assert(names.size() == replacements.size()); + mpImpl->setCustomEntityNames(names, replacements); +} + sal_Bool FastSaxParser::supportsService( const OUString& ServiceName ) { return cppu::supportsService(this, ServiceName); |