summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohammed Abdul Azeem <azeemmysore@gmail.com>2017-06-14 18:16:41 +0530
committerMichael Meeks <michael.meeks@collabora.com>2017-06-15 11:08:20 +0200
commit420cecf55878a2d652a61540ddc37a7faaf4cc46 (patch)
tree1a4ee822f7b5e9e0e21c31e6d24d7a8273c1b87e
parentWatermark: RTF font import and export (diff)
downloadcore-420cecf55878a2d652a61540ddc37a7faaf4cc46.tar.gz
core-420cecf55878a2d652a61540ddc37a7faaf4cc46.zip
[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>
-rw-r--r--include/oox/core/filterdetect.hxx1
-rw-r--r--include/oox/core/fragmenthandler.hxx1
-rw-r--r--offapi/com/sun/star/xml/sax/XFastDocumentHandler.idl6
-rw-r--r--oox/source/core/filterdetect.cxx4
-rw-r--r--oox/source/core/fragmenthandler.cxx4
-rw-r--r--oox/source/crypto/DocumentDecryption.cxx2
-rw-r--r--oox/source/docprop/docprophandler.cxx4
-rw-r--r--oox/source/docprop/docprophandler.hxx1
-rw-r--r--sax/qa/cppunit/xmlimport.cxx3
-rw-r--r--sax/qa/data/nestedns.xml2
-rw-r--r--sax/source/fastparser/fastparser.cxx48
-rw-r--r--sax/source/fastparser/legacyfastparser.cxx7
-rw-r--r--unoxml/qa/unit/domtest.cxx4
-rw-r--r--writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx4
-rw-r--r--writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx1
15 files changed, 90 insertions, 2 deletions
diff --git a/include/oox/core/filterdetect.hxx b/include/oox/core/filterdetect.hxx
index f5932eab8af6..44f0363187c9 100644
--- a/include/oox/core/filterdetect.hxx
+++ b/include/oox/core/filterdetect.hxx
@@ -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
diff --git a/include/oox/core/fragmenthandler.hxx b/include/oox/core/fragmenthandler.hxx
index 7ab4261c5901..e8107a1dae82 100644
--- a/include/oox/core/fragmenthandler.hxx
+++ b/include/oox/core/fragmenthandler.hxx
@@ -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 ---------------------
diff --git a/offapi/com/sun/star/xml/sax/XFastDocumentHandler.idl b/offapi/com/sun/star/xml/sax/XFastDocumentHandler.idl
index 61cb668c00c7..bdabf6d51701 100644
--- a/offapi/com/sun/star/xml/sax/XFastDocumentHandler.idl
+++ b/offapi/com/sun/star/xml/sax/XFastDocumentHandler.idl
@@ -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 )
diff --git a/oox/source/core/filterdetect.cxx b/oox/source/core/filterdetect.cxx
index 991b3d86a585..13d3fed8a773 100644
--- a/oox/source/core/filterdetect.cxx
+++ b/oox/source/core/filterdetect.cxx
@@ -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*/ )
{
}
diff --git a/oox/source/core/fragmenthandler.cxx b/oox/source/core/fragmenthandler.cxx
index 564306e647fb..58c5d7ab1093 100644
--- a/oox/source/core/fragmenthandler.cxx
+++ b/oox/source/core/fragmenthandler.cxx
@@ -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 );
diff --git a/oox/source/crypto/DocumentDecryption.cxx b/oox/source/crypto/DocumentDecryption.cxx
index 0209f3d24ba5..f06516c51757 100644
--- a/oox/source/crypto/DocumentDecryption.cxx
+++ b/oox/source/crypto/DocumentDecryption.cxx
@@ -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
diff --git a/oox/source/docprop/docprophandler.cxx b/oox/source/docprop/docprophandler.cxx
index 43fd8bc12de6..3f8912d0f0d3 100644
--- a/oox/source/docprop/docprophandler.cxx
+++ b/oox/source/docprop/docprophandler.cxx
@@ -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 >& )
{
}
diff --git a/oox/source/docprop/docprophandler.hxx b/oox/source/docprop/docprophandler.hxx
index 0cf7dcf0a501..00ace3d7f007 100644
--- a/oox/source/docprop/docprophandler.hxx
+++ b/oox/source/docprop/docprophandler.hxx
@@ -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
diff --git a/sax/qa/cppunit/xmlimport.cxx b/sax/qa/cppunit/xmlimport.cxx
index f08c0357af28..f6f320696d3d 100644
--- a/sax/qa/cppunit/xmlimport.cxx
+++ b/sax/qa/cppunit/xmlimport.cxx
@@ -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;
}
diff --git a/sax/qa/data/nestedns.xml b/sax/qa/data/nestedns.xml
index 18bc4ed34e60..566332b40ace 100644
--- a/sax/qa/data/nestedns.xml
+++ b/sax/qa/data/nestedns.xml
@@ -1,4 +1,5 @@
<?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/">
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() )
diff --git a/unoxml/qa/unit/domtest.cxx b/unoxml/qa/unit/domtest.cxx
index 35f41974acd7..6080020e7647 100644
--- a/unoxml/qa/unit/domtest.cxx
+++ b/unoxml/qa/unit/domtest.cxx
@@ -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
{
}
diff --git a/writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx b/writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx
index 7c027680abaa..19e6656f128f 100644
--- a/writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx
@@ -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*/)
{
diff --git a/writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx b/writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx
index c47bb96ad18a..1251203fb792 100644
--- a/writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx
@@ -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;