summaryrefslogtreecommitdiff
path: root/sax/source/fastparser/fastparser.cxx
diff options
context:
space:
mode:
authorMohammed Abdul Azeem <azeemmysore@gmail.com>2017-12-24 23:40:39 +0530
committerMichael Meeks <michael.meeks@collabora.com>2018-01-04 12:44:39 +0100
commitbb59a80ee6000d3922fa95262f67e291fd9d8ee2 (patch)
tree3b6b4c2ba1e589b67f59e118b752f00010bec238 /sax/source/fastparser/fastparser.cxx
parent2dd45c0c62b3ef3d8057b3fc70af24ae11a3d01d (diff)
Modifying the impl. of startUnknownElement of FastParser:
Modifying it to emit the namespace URI instead of prefix and qualified name instead of local name. This will be useful for handling arbitrary elements in the fast contexts. Change-Id: I0f150b862574612e97491f6c335f3f4c9966da0a Reviewed-on: https://gerrit.libreoffice.org/47055 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'sax/source/fastparser/fastparser.cxx')
-rw-r--r--sax/source/fastparser/fastparser.cxx30
1 files changed, 22 insertions, 8 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 55b6545c5114..f56d368580ac 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -249,6 +249,7 @@ private:
bool consume(EventList&);
void deleteUsedEvents();
void sendPendingCharacters();
+ void addUnknownElementWithPrefix(const xmlChar **attributes, int i, rtl::Reference< FastAttributeList >& xAttributes);
sal_Int32 GetToken( const xmlChar* pName, sal_Int32 nameLen );
/// @throws css::xml::sax::SAXException
@@ -1148,8 +1149,7 @@ void FastSaxParserImpl::callbackStartElement(const xmlChar *localName , const xm
if( nAttributeToken != FastToken::DONTKNOW )
rEvent.mxAttributes->add( nAttributeToken, XML_CAST( attributes[ i + 3 ] ), attributes[ i + 4 ] - attributes[ i + 3 ] );
else
- rEvent.mxAttributes->addUnknown( OUString( XML_CAST( attributes[ i + 1 ] ), strlen( XML_CAST( attributes[ i + 1 ] )), RTL_TEXTENCODING_UTF8 ),
- OString( XML_CAST( attributes[ i ] )), OString( XML_CAST( attributes[ i + 3 ] ), attributes[ i + 4 ] - attributes[ i + 3 ] ));
+ addUnknownElementWithPrefix(attributes, i, rEvent.mxAttributes);
}
else
{
@@ -1174,8 +1174,7 @@ void FastSaxParserImpl::callbackStartElement(const xmlChar *localName , const xm
for (int i = 0; i < numAttributes * 5; i += 5)
{
if( attributes[ i + 1 ] != nullptr )
- rEvent.mxAttributes->addUnknown( OUString( XML_CAST( attributes[ i + 1 ] ), strlen( XML_CAST( attributes[ i + 1 ] )), RTL_TEXTENCODING_UTF8 ),
- OString( XML_CAST( attributes[ i ] )), OString( XML_CAST( attributes[ i + 3 ] ), attributes[ i + 4 ] - attributes[ i + 3 ] ));
+ addUnknownElementWithPrefix(attributes, i, rEvent.mxAttributes);
else
rEvent.mxAttributes->addUnknown( XML_CAST( attributes[ i ] ),
OString( XML_CAST( attributes[ i + 3 ] ), attributes[ i + 4 ] - attributes[ i + 3 ] ));
@@ -1186,16 +1185,19 @@ void FastSaxParserImpl::callbackStartElement(const xmlChar *localName , const xm
if( rEvent.mnElementToken == FastToken::DONTKNOW )
{
+ OUString aElementPrefix;
if( prefix != nullptr )
{
if ( !m_bIgnoreMissingNSDecl || URI != nullptr )
sNamespace = OUString( XML_CAST( URI ), strlen( XML_CAST( URI )), RTL_TEXTENCODING_UTF8 );
+ else
+ sNamespace.clear();
nNamespaceToken = GetNamespaceToken( sNamespace );
- rEvent.msNamespace = OUString( XML_CAST( prefix ), strlen( XML_CAST( prefix )), RTL_TEXTENCODING_UTF8 );
+ aElementPrefix = OUString( XML_CAST( prefix ), strlen( XML_CAST( prefix )), RTL_TEXTENCODING_UTF8 );
}
- else
- rEvent.msNamespace.clear();
- rEvent.msElementName = OUString( XML_CAST( localName ), strlen( XML_CAST( localName )), RTL_TEXTENCODING_UTF8 );
+ const OUString& rElementLocalName = OUString( XML_CAST( localName ), strlen( XML_CAST( localName )), RTL_TEXTENCODING_UTF8 );
+ rEvent.msNamespace = sNamespace;
+ rEvent.msElementName = (aElementPrefix.isEmpty())? rElementLocalName : aElementPrefix + ":" + rElementLocalName;
}
else // token is always preferred.
rEvent.msElementName.clear();
@@ -1215,6 +1217,18 @@ void FastSaxParserImpl::callbackStartElement(const xmlChar *localName , const xm
}
}
+void FastSaxParserImpl::addUnknownElementWithPrefix(const xmlChar **attributes, int i, rtl::Reference< FastAttributeList >& xAttributes)
+{
+ OUString aNamespaceURI;
+ if ( !m_bIgnoreMissingNSDecl || attributes[i + 2] != nullptr )
+ aNamespaceURI = OUString( XML_CAST( attributes[ i + 2 ] ), strlen( XML_CAST( attributes[ i + 2 ] )), RTL_TEXTENCODING_UTF8 );
+ const OString& rPrefix = OString( XML_CAST( attributes[ i + 1 ] ));
+ const OString& rLocalName = OString( XML_CAST( attributes[ i ] ));
+ OString aQualifiedName = (rPrefix.isEmpty())? rLocalName : rPrefix + ":" + rLocalName;
+ xAttributes->addUnknown( aNamespaceURI, aQualifiedName,
+ OString( XML_CAST( attributes[ i + 3 ] ), attributes[ i + 4 ] - attributes[ i + 3 ] ));
+}
+
void FastSaxParserImpl::callbackEndElement()
{
if (!pendingCharacters.isEmpty())