[Libreoffice-commits] core.git: include/xmloff oox/source sax/source xmloff/source
Mohammed Abdul Azeem
azeemmysore at gmail.com
Thu Jan 4 11:45:11 UTC 2018
include/xmloff/xmlimp.hxx | 3 +
oox/source/crypto/DocumentDecryption.cxx | 33 +++++++++++---------
sax/source/fastparser/fastparser.cxx | 30 +++++++++++++-----
sax/source/fastparser/legacyfastparser.cxx | 47 ++++++++++++-----------------
xmloff/source/core/xmlictxt.cxx | 41 ++++++++-----------------
xmloff/source/core/xmlimp.cxx | 2 +
6 files changed, 79 insertions(+), 77 deletions(-)
New commits:
commit bb59a80ee6000d3922fa95262f67e291fd9d8ee2
Author: Mohammed Abdul Azeem <azeemmysore at gmail.com>
Date: Sun Dec 24 23:40:39 2017 +0530
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 at libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index 7cc0d76f5c90..339b8cdf7a54 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -519,6 +519,9 @@ public:
**/
bool getBuildIds( sal_Int32& rUPD, sal_Int32& rBuild ) const;
+ static const OUString aDefaultNamespace;
+ static const OUString aNamespaceSeparator;
+
static const sal_uInt16 OOo_1x = 10;
static const sal_uInt16 OOo_2x = 20;
static const sal_uInt16 OOo_30x = 30;
diff --git a/oox/source/crypto/DocumentDecryption.cxx b/oox/source/crypto/DocumentDecryption.cxx
index 7c646877c425..5f5940ad01db 100644
--- a/oox/source/crypto/DocumentDecryption.cxx
+++ b/oox/source/crypto/DocumentDecryption.cxx
@@ -81,11 +81,13 @@ public:
void SAL_CALL startUnknownElement( const OUString& /*aNamespace*/, const OUString& rName, const Reference< XFastAttributeList >& aAttributeList ) override
{
- if (rName == "keyData")
+ const auto& localname = [](const OUString &a) { return a.copy(a.indexOf(":") + 1); };
+ const OUString& rLocalName = localname(rName);
+ if (rLocalName == "keyData")
{
for (const Attribute& rAttribute : aAttributeList->getUnknownAttributes())
{
- if (rAttribute.Name == "saltValue")
+ if (localname(rAttribute.Name) == "saltValue")
{
Sequence<sal_Int8> keyDataSalt;
::sax::Converter::decodeBase64(keyDataSalt, rAttribute.Value);
@@ -93,61 +95,62 @@ public:
}
}
}
- else if (rName == "encryptedKey")
+ else if (rLocalName == "encryptedKey")
{
for (const Attribute& rAttribute : aAttributeList->getUnknownAttributes())
{
- if (rAttribute.Name == "spinCount")
+ const OUString& rAttrLocalName = localname(rAttribute.Name);
+ if (rAttrLocalName == "spinCount")
{
::sax::Converter::convertNumber(mInfo.spinCount, rAttribute.Value);
}
- else if (rAttribute.Name == "saltSize")
+ else if (rAttrLocalName == "saltSize")
{
::sax::Converter::convertNumber(mInfo.saltSize, rAttribute.Value);
}
- else if (rAttribute.Name == "blockSize")
+ else if (rAttrLocalName == "blockSize")
{
::sax::Converter::convertNumber(mInfo.blockSize, rAttribute.Value);
}
- else if (rAttribute.Name == "keyBits")
+ else if (rAttrLocalName == "keyBits")
{
::sax::Converter::convertNumber(mInfo.keyBits, rAttribute.Value);
}
- else if (rAttribute.Name == "hashSize")
+ else if (rAttrLocalName == "hashSize")
{
::sax::Converter::convertNumber(mInfo.hashSize, rAttribute.Value);
}
- else if (rAttribute.Name == "cipherAlgorithm")
+ else if (rAttrLocalName == "cipherAlgorithm")
{
mInfo.cipherAlgorithm = rAttribute.Value;
}
- else if (rAttribute.Name == "cipherChaining")
+ else if (rAttrLocalName == "cipherChaining")
{
mInfo.cipherChaining = rAttribute.Value;
}
- else if (rAttribute.Name == "hashAlgorithm")
+ else if (rAttrLocalName == "hashAlgorithm")
{
mInfo.hashAlgorithm = rAttribute.Value;
}
- else if (rAttribute.Name == "saltValue")
+ else if (rAttrLocalName == "saltValue")
{
Sequence<sal_Int8> saltValue;
::sax::Converter::decodeBase64(saltValue, rAttribute.Value);
mInfo.saltValue = convertToVector(saltValue);
}
- else if (rAttribute.Name == "encryptedVerifierHashInput")
+ else if (rAttrLocalName == "encryptedVerifierHashInput")
{
Sequence<sal_Int8> encryptedVerifierHashInput;
::sax::Converter::decodeBase64(encryptedVerifierHashInput, rAttribute.Value);
mInfo.encryptedVerifierHashInput = convertToVector(encryptedVerifierHashInput);
}
- else if (rAttribute.Name == "encryptedVerifierHashValue")
+ else if (rAttrLocalName == "encryptedVerifierHashValue")
{
Sequence<sal_Int8> encryptedVerifierHashValue;
::sax::Converter::decodeBase64(encryptedVerifierHashValue, rAttribute.Value);
mInfo.encryptedVerifierHashValue = convertToVector(encryptedVerifierHashValue);
}
- else if (rAttribute.Name == "encryptedKeyValue")
+ else if (rAttrLocalName == "encryptedKeyValue")
{
Sequence<sal_Int8> encryptedKeyValue;
::sax::Converter::decodeBase64(encryptedKeyValue, rAttribute.Value);
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())
diff --git a/sax/source/fastparser/legacyfastparser.cxx b/sax/source/fastparser/legacyfastparser.cxx
index 458e91b2af89..97c5ab277f89 100644
--- a/sax/source/fastparser/legacyfastparser.cxx
+++ b/sax/source/fastparser/legacyfastparser.cxx
@@ -134,6 +134,9 @@ private:
const OUString getNamespacePrefixFromToken( sal_Int32 nToken );
const OUString getNameFromToken( sal_Int32 nToken );
+ static const OUString aDefaultNamespace;
+ static const OUString aNamespaceSeparator;
+
public:
CallbackDocumentHandler( Reference< XDocumentHandler > const & xDocumentHandler,
rtl::Reference< NamespaceHandler > const & rNamespaceHandler,
@@ -156,6 +159,9 @@ public:
};
+const OUString CallbackDocumentHandler::aDefaultNamespace = OUString("");
+const OUString CallbackDocumentHandler::aNamespaceSeparator = OUString(":");
+
const OUString CallbackDocumentHandler::getNamespacePrefixFromToken( sal_Int32 nToken )
{
if ( ( nToken & 0xffff0000 ) != 0 )
@@ -210,32 +216,28 @@ void SAL_CALL CallbackDocumentHandler::setDocumentLocator( const Reference< XLoc
void SAL_CALL CallbackDocumentHandler::startFastElement( sal_Int32 nElement , const Reference< XFastAttributeList >& Attribs )
{
- startUnknownElement( CallbackDocumentHandler::getNamespacePrefixFromToken( nElement ),
- CallbackDocumentHandler::getNameFromToken( nElement ), Attribs );
+ const OUString& rPrefix = CallbackDocumentHandler::getNamespacePrefixFromToken( nElement );
+ const OUString& rLocalName = CallbackDocumentHandler::getNameFromToken( nElement );
+ startUnknownElement( aDefaultNamespace, (rPrefix.isEmpty())? rLocalName : rPrefix + aNamespaceSeparator + rLocalName, Attribs );
}
-void SAL_CALL CallbackDocumentHandler::startUnknownElement( const OUString& Namespace, const OUString& Name, const Reference< XFastAttributeList >& Attribs )
+void SAL_CALL CallbackDocumentHandler::startUnknownElement( const OUString& /*Namespace*/, const OUString& Name, const Reference< XFastAttributeList >& Attribs )
{
if ( m_xDocumentHandler.is() )
{
- OUString elementName;
rtl::Reference < comphelper::AttributeList > rAttrList = new comphelper::AttributeList;
m_aNamespaceHandler->addNSDeclAttributes( rAttrList );
- if ( !Namespace.isEmpty() )
- elementName = Namespace + ":" + Name;
- else
- elementName = Name;
Sequence< xml::FastAttribute > fastAttribs = Attribs->getFastAttributes();
sal_uInt16 len = fastAttribs.getLength();
for (sal_uInt16 i = 0; i < len; i++)
{
- OUString& rAttrValue = fastAttribs[i].Value;
+ const OUString& rAttrValue = fastAttribs[i].Value;
sal_Int32 nToken = fastAttribs[i].Token;
const OUString& rAttrNamespacePrefix = CallbackDocumentHandler::getNamespacePrefixFromToken( nToken );
OUString sAttrName = CallbackDocumentHandler::getNameFromToken( nToken );
if ( !rAttrNamespacePrefix.isEmpty() )
- sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
+ sAttrName = rAttrNamespacePrefix + aNamespaceSeparator + sAttrName;
rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
}
@@ -244,35 +246,28 @@ void SAL_CALL CallbackDocumentHandler::startUnknownElement( const OUString& Name
len = unknownAttribs.getLength();
for (sal_uInt16 i = 0; i < len; i++)
{
- OUString& rAttrValue = unknownAttribs[i].Value;
- OUString sAttrName = unknownAttribs[i].Name;
- OUString& rAttrNamespacePrefix = unknownAttribs[i].NamespaceURL;
- if ( !rAttrNamespacePrefix.isEmpty() )
- sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
+ const OUString& rAttrValue = unknownAttribs[i].Value;
+ const OUString& rAttrName = unknownAttribs[i].Name;
- rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
+ rAttrList->AddAttribute( rAttrName, "CDATA", rAttrValue );
}
- m_xDocumentHandler->startElement( elementName, rAttrList.get() );
+ m_xDocumentHandler->startElement( Name, rAttrList.get() );
}
}
void SAL_CALL CallbackDocumentHandler::endFastElement( sal_Int32 nElement )
{
- endUnknownElement( CallbackDocumentHandler::getNamespacePrefixFromToken( nElement ),
- CallbackDocumentHandler::getNameFromToken( nElement ) );
+ const OUString& rPrefix = CallbackDocumentHandler::getNamespacePrefixFromToken( nElement );
+ const OUString& rLocalName = CallbackDocumentHandler::getNameFromToken( nElement );
+ endUnknownElement( aDefaultNamespace, (rPrefix.isEmpty())? rLocalName : rPrefix + aNamespaceSeparator + rLocalName );
}
-void SAL_CALL CallbackDocumentHandler::endUnknownElement( const OUString& Namespace, const OUString& Name )
+void SAL_CALL CallbackDocumentHandler::endUnknownElement( const OUString& /*Namespace*/, const OUString& Name )
{
if ( m_xDocumentHandler.is() )
{
- OUString elementName;
- if ( !Namespace.isEmpty() )
- elementName = Namespace + ":" + Name;
- else
- elementName = Name;
- m_xDocumentHandler->endElement( elementName );
+ m_xDocumentHandler->endElement( Name );
}
}
diff --git a/xmloff/source/core/xmlictxt.cxx b/xmloff/source/core/xmlictxt.cxx
index a00539afce6b..b0494250316f 100644
--- a/xmloff/source/core/xmlictxt.cxx
+++ b/xmloff/source/core/xmlictxt.cxx
@@ -70,15 +70,14 @@ void SvXMLImportContext::Characters( const OUString& )
void SAL_CALL SvXMLImportContext::startFastElement(sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
{
mrImport.isFastContext = false;
- startUnknownElement( SvXMLImport::getNamespacePrefixFromToken( nElement ),
- SvXMLImport::getNameFromToken( nElement ), Attribs );
+ const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken( nElement );
+ const OUString& rLocalName = SvXMLImport::getNameFromToken( nElement );
+ startUnknownElement( SvXMLImport::aDefaultNamespace, (rPrefix.isEmpty())? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName, Attribs );
}
-void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & rPrefix, const OUString & rLocalName,
+void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & /*rNamespace*/, const OUString & rElementName,
const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
{
- OUString elementName;
-
if ( mrImport.maAttrList.is() )
mrImport.maAttrList->Clear();
else
@@ -86,11 +85,6 @@ void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & rPrefix,
mrImport.maNamespaceHandler->addNSDeclAttributes( mrImport.maAttrList );
- if ( !rPrefix.isEmpty() )
- elementName = rPrefix + ":" + rLocalName;
- else
- elementName = rLocalName;
-
if ( Attribs.is() )
{
sax_fastparser::FastAttributeList *pAttribList =
@@ -102,7 +96,7 @@ void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & rPrefix,
const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken( nToken );
OUString sAttrName = SvXMLImport::getNameFromToken( nToken );
if ( !rAttrNamespacePrefix.isEmpty() )
- sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
+ sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName;
mrImport.maAttrList->AddAttribute( sAttrName, "CDATA", it.toString() );
}
@@ -112,33 +106,24 @@ void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & rPrefix,
for ( sal_Int32 i = 0; i < len; i++ )
{
const OUString& rAttrValue = unknownAttribs[i].Value;
- OUString sAttrName = unknownAttribs[i].Name;
- const OUString& rAttrNamespacePrefix = unknownAttribs[i].NamespaceURL;
- if ( !rAttrNamespacePrefix.isEmpty() )
- sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
-
- mrImport.maAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
+ const OUString& rAttrName = unknownAttribs[i].Name;
+ mrImport.maAttrList->AddAttribute( rAttrName, "CDATA", rAttrValue );
}
}
-
- mrImport.startElement( elementName, mrImport.maAttrList.get() );
+ mrImport.startElement( rElementName, mrImport.maAttrList.get() );
}
void SAL_CALL SvXMLImportContext::endFastElement(sal_Int32 nElement)
{
mrImport.isFastContext = false;
- endUnknownElement( SvXMLImport::getNamespacePrefixFromToken( nElement ),
- SvXMLImport::getNameFromToken( nElement ) );
+ const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken( nElement );
+ const OUString& rLocalName = SvXMLImport::getNameFromToken( nElement );
+ endUnknownElement( SvXMLImport::aDefaultNamespace, (rPrefix.isEmpty())? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName );
}
-void SAL_CALL SvXMLImportContext::endUnknownElement (const OUString & rPrefix, const OUString & rLocalName)
+void SAL_CALL SvXMLImportContext::endUnknownElement (const OUString & /*rNamespace*/, const OUString & rElementName)
{
- OUString elementName;
- if ( !rPrefix.isEmpty() )
- elementName = rPrefix + ":" + rLocalName;
- else
- elementName = rLocalName;
- mrImport.endElement( elementName );
+ mrImport.endElement( rElementName );
}
uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::createFastChildContext
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 0718e7af65e6..c8a2417603c9 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -76,6 +76,8 @@ using namespace ::xmloff::token;
css::uno::Reference< css::xml::sax::XFastTokenHandler > SvXMLImport::xTokenHandler( new FastTokenHandler() );
std::unordered_map< sal_Int32, std::pair< OUString, OUString > > SvXMLImport::aNamespaceMap;
+const OUString SvXMLImport::aDefaultNamespace = OUString("");
+const OUString SvXMLImport::aNamespaceSeparator = OUString(":");
bool SvXMLImport::bIsNSMapsInitialized = false;
class SvXMLImportEventListener : public cppu::WeakImplHelper< css::lang::XEventListener >
More information about the Libreoffice-commits
mailing list