Kaydet (Commit) 420cecf5 authored tarafından Mohammed Abdul Azeem's avatar Mohammed Abdul Azeem Kaydeden (comit) Michael Meeks

[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/38784Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst dd0df1c8
......@@ -67,6 +67,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 css::uno::Reference< css::xml::sax::XLocator >& xLocator ) override;
// XFastContextHandler
......
......@@ -101,6 +101,7 @@ public:
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 css::uno::Reference< css::xml::sax::XLocator >& rxLocator ) override;
// com.sun.star.xml.sax.XFastContextHandler interface ---------------------
......
......@@ -50,6 +50,12 @@ interface XFastDocumentHandler: XFastContextHandler
raises( com::sun::star::xml::sax::SAXException );
/** receives notification of a processing instruction.
*/
void processingInstruction( [in] string aTarget, [in] string aData )
raises( com::sun::star::xml::sax::SAXException );
/** receives an object for locating the origin of SAX document events.
*/
void setDocumentLocator( [in] com::sun::star::xml::sax::XLocator xLocator )
......
......@@ -72,6 +72,10 @@ void SAL_CALL FilterDetectDocHandler::endDocument()
{
}
void SAL_CALL FilterDetectDocHandler::processingInstruction( const OUString& /*rTarget*/, const OUString& /*rData*/ )
{
}
void SAL_CALL FilterDetectDocHandler::setDocumentLocator( const Reference<XLocator>& /*xLocator*/ )
{
}
......
......@@ -59,6 +59,10 @@ void FragmentHandler::endDocument()
{
}
void FragmentHandler::processingInstruction( const OUString& /*rTarget*/, const OUString& /*rData*/ )
{
}
void FragmentHandler::setDocumentLocator( const Reference< XLocator >& rxLocator )
{
implSetLocator( rxLocator );
......
......@@ -72,6 +72,8 @@ public:
{}
void SAL_CALL endDocument() override
{}
void SAL_CALL processingInstruction( const OUString& /*rTarget*/, const OUString& /*rData*/ ) override
{}
void SAL_CALL setDocumentLocator( const Reference< XLocator >& /*xLocator*/ ) override
{}
void SAL_CALL startFastElement( sal_Int32 /*Element*/, const Reference< XFastAttributeList >& /*Attribs*/ ) override
......
......@@ -276,6 +276,10 @@ void SAL_CALL OOXMLDocPropHandler::endDocument()
InitNew();
}
void OOXMLDocPropHandler::processingInstruction( const OUString& /*rTarget*/, const OUString& /*rData*/ )
{
}
void SAL_CALL OOXMLDocPropHandler::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& )
{
}
......
......@@ -68,6 +68,7 @@ public:
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 css::uno::Reference< css::xml::sax::XLocator >& rxLocator ) override;
// com.sun.star.xml.sax.XFastContextHandler
......
......@@ -191,8 +191,9 @@ void SAL_CALL TestDocumentHandler::ignorableWhitespace( const OUString& aWhitesp
}
void SAL_CALL TestDocumentHandler::processingInstruction( const OUString& /*aTarget*/, const OUString& /*aData*/ )
void SAL_CALL TestDocumentHandler::processingInstruction( const OUString& aTarget, const OUString& aData )
{
m_aStr = m_aStr + aTarget + aData;
}
......
<?xml version="1.0" ?>
<?pi-target pi-data?>
<Elements>
<Book xmlns:lib="http://www.library.com/">
<lib:Title>Sherlock Holmes - I</lib:Title>
......@@ -13,6 +14,7 @@
<Electronics xmlns="http://doesntexist.com/electronics/">
<item>
<Name>Apple iPhone 6s</Name>
<?pi-target-only?>
<Price>$324</Price>
</item>
<item xmlns="http://doesntexist.com/dailyuse/">
......
......@@ -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*/,
......
......@@ -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() )
......
......@@ -163,6 +163,10 @@ struct DocumentHandler
{
}
virtual void SAL_CALL processingInstruction( const OUString& /*rTarget*/, const OUString& /*rData*/ ) override
{
}
virtual void SAL_CALL setDocumentLocator( const uno::Reference< xml::sax::XLocator >& ) override
{
}
......
......@@ -174,6 +174,10 @@ void SAL_CALL OOXMLFastDocumentHandler::endDocument()
{
}
void SAL_CALL OOXMLFastDocumentHandler::processingInstruction( const OUString& /*rTarget*/, const OUString& /*rData*/ )
{
}
void SAL_CALL OOXMLFastDocumentHandler::setDocumentLocator
(const uno::Reference< xml::sax::XLocator > & /*xLocator*/)
{
......
......@@ -47,6 +47,7 @@ public:
// css::xml::sax::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 css::uno::Reference< css::xml::sax::XLocator > & xLocator) override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment