summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authordante <dante19031999@gmail.com>2020-11-28 14:26:40 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-11-29 19:53:20 +0100
commitf28c8085d14f65aa40da434c1d9d5ae60bfad862 (patch)
treea94fd6bbd0e1dd7ef19dc6ad0024e19f36d8c440 /sax
parentb4534d1ea4c0d36f7e5220729c959d0ad148e352 (diff)
Preparing for mathml support of custom entity references.
This should be enough for the starmath mathml project. It can be reused from other modules for doing custom stuff. It keeps to minimum changes on generic modules. My current abilities don't allow me to go much beyond this approach. Change-Id: If7f157f8a71d6c3bff50fdbcd80bed23c92f40bb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106804 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sax')
-rw-r--r--sax/source/fastparser/fastparser.cxx43
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);