diff options
author | Mohammed Abdul Azeem <azeemmysore@gmail.com> | 2017-06-14 18:16:41 +0530 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2017-06-15 11:08:20 +0200 |
commit | 420cecf55878a2d652a61540ddc37a7faaf4cc46 (patch) | |
tree | 1a4ee822f7b5e9e0e21c31e6d24d7a8273c1b87e /sax/source/fastparser | |
parent | dd0df1c8a213ab6f0959145396bc273bf885af39 (diff) |
[API CHANGE] Add processingInstruction event to XFastDocumentHandler:
Also made changes in FastParser impl. to emit this event. I've made use
of existing namespace and element name strings to store target
and data for this event.
Change-Id: I6f00cd1172552dd9a74ec22190bef3d2289ae515
Reviewed-on: https://gerrit.libreoffice.org/38784
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'sax/source/fastparser')
-rw-r--r-- | sax/source/fastparser/fastparser.cxx | 48 | ||||
-rw-r--r-- | sax/source/fastparser/legacyfastparser.cxx | 7 |
2 files changed, 54 insertions, 1 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx index eb15b19e94be..4cdd3b034962 100644 --- a/sax/source/fastparser/fastparser.cxx +++ b/sax/source/fastparser/fastparser.cxx @@ -77,7 +77,7 @@ struct EventList bool mbIsAttributesEmpty; }; -enum CallbackType { INVALID, START_ELEMENT, END_ELEMENT, CHARACTERS, DONE, EXCEPTION }; +enum CallbackType { INVALID, START_ELEMENT, END_ELEMENT, CHARACTERS, PROCESSING_INSTRUCTION, DONE, EXCEPTION }; struct Event { @@ -193,6 +193,7 @@ struct Entity : public ParserData void startElement( Event *pEvent ); void characters( const OUString& sChars ); void endElement(); + void processingInstruction( const OUString& rTarget, const OUString& rData ); EventList* getEventList(); Event& getEvent( CallbackType aType ); }; @@ -236,6 +237,7 @@ public: int numNamespaces, const xmlChar** namespaces, int numAttributes, const xmlChar **attributes ); void callbackEndElement(); void callbackCharacters( const xmlChar* s, int nLen ); + void callbackProcessingInstruction( const xmlChar *target, const xmlChar *data ); #if 0 bool callbackExternalEntityRef( XML_Parser parser, const xmlChar *openEntityNames, const xmlChar *base, const xmlChar *systemId, const xmlChar *publicId); void callbackEntityDecl(const xmlChar *entityName, int is_parameter_entity, @@ -326,6 +328,12 @@ static void call_callbackCharacters( void *userData , const xmlChar *s , int nLe pFastParser->callbackCharacters( s, nLen ); } +static void call_callbackProcessingInstruction( void *userData, const xmlChar *target, const xmlChar *data ) +{ + FastSaxParserImpl* pFastParser = static_cast<FastSaxParserImpl*>( userData ); + pFastParser->callbackProcessingInstruction( target, data ); +} + #if 0 static void call_callbackEntityDecl(void *userData, const xmlChar *entityName, int is_parameter_entity, const xmlChar *value, int value_length, @@ -529,6 +537,18 @@ void Entity::endElement() maContextStack.pop(); } +void Entity::processingInstruction( const OUString& rTarget, const OUString& rData ) +{ + if( mxDocumentHandler.is() ) try + { + mxDocumentHandler->processingInstruction( rTarget, rData ); + } + catch (const Exception&) + { + saveException( ::cppu::getCaughtException() ); + } +} + EventList* Entity::getEventList() { if (!mpProducedEvents) @@ -976,6 +996,10 @@ bool FastSaxParserImpl::consume(EventList *pEventList) case CHARACTERS: rEntity.characters( (*aEventIt).msChars ); break; + case PROCESSING_INSTRUCTION: + rEntity.processingInstruction( + (*aEventIt).msNamespace, (*aEventIt).msElementName ); // ( target, data ) + break; case DONE: return false; case EXCEPTION: @@ -1014,6 +1038,7 @@ void FastSaxParserImpl::parse() callbacks.startElementNs = call_callbackStartElement; callbacks.endElementNs = call_callbackEndElement; callbacks.characters = call_callbackCharacters; + callbacks.processingInstruction = call_callbackProcessingInstruction; callbacks.initialized = XML_SAX2_MAGIC; #if 0 XML_SetEntityDeclHandler(entity.mpParser, call_callbackEntityDecl); @@ -1259,6 +1284,27 @@ void FastSaxParserImpl::sendPendingCharacters() rEntity.characters( rEvent.msChars ); } +void FastSaxParserImpl::callbackProcessingInstruction( const xmlChar *target, const xmlChar *data ) +{ + if (!pendingCharacters.isEmpty()) + sendPendingCharacters(); + Entity& rEntity = getEntity(); + Event& rEvent = rEntity.getEvent( PROCESSING_INSTRUCTION ); + + // This event is very rare, so no need to waste extra space for this + // Using namespace and element strings to be target and data in that order. + rEvent.msNamespace = OUString( XML_CAST( target ), strlen( XML_CAST( target ) ), RTL_TEXTENCODING_UTF8 ); + if ( data != nullptr ) + rEvent.msElementName = OUString( XML_CAST( data ), strlen( XML_CAST( data ) ), RTL_TEXTENCODING_UTF8 ); + else + rEvent.msElementName.clear(); + + if (rEntity.mbEnableThreads) + produce(); + else + rEntity.processingInstruction( rEvent.msNamespace, rEvent.msElementName ); +} + #if 0 void FastSaxParserImpl::callbackEntityDecl( SAL_UNUSED_PARAMETER const xmlChar * /*entityName*/, diff --git a/sax/source/fastparser/legacyfastparser.cxx b/sax/source/fastparser/legacyfastparser.cxx index 4acb1d890090..81e394b4f907 100644 --- a/sax/source/fastparser/legacyfastparser.cxx +++ b/sax/source/fastparser/legacyfastparser.cxx @@ -142,6 +142,7 @@ public: // XFastDocumentHandler virtual void SAL_CALL startDocument() override; virtual void SAL_CALL endDocument() override; + virtual void SAL_CALL processingInstruction( const OUString& rTarget, const OUString& rData ) override; virtual void SAL_CALL setDocumentLocator( const Reference< XLocator >& xLocator ) override; // XFastContextHandler @@ -195,6 +196,12 @@ void SAL_CALL CallbackDocumentHandler::endDocument() m_xDocumentHandler->endDocument(); } +void SAL_CALL CallbackDocumentHandler::processingInstruction( const OUString& rTarget, const OUString& rData ) +{ + if ( m_xDocumentHandler.is() ) + m_xDocumentHandler->processingInstruction( rTarget, rData ); +} + void SAL_CALL CallbackDocumentHandler::setDocumentLocator( const Reference< XLocator >& xLocator ) { if ( m_xDocumentHandler.is() ) |