[Libreoffice-commits] core.git: include/xmloff unoxml/source xmloff/source

Caolán McNamara caolanm at redhat.com
Thu May 17 20:14:55 UTC 2018


 include/xmloff/xmlimp.hxx        |    2 +-
 unoxml/source/dom/saxbuilder.cxx |    6 +++---
 xmloff/source/core/xmlictxt.cxx  |    6 +++---
 xmloff/source/core/xmlimp.cxx    |   10 +++++++++-
 4 files changed, 16 insertions(+), 8 deletions(-)

New commits:
commit bdc0b3e3d7f1f5a07f4863913aef0824dedf9a69
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Apr 11 12:31:36 2018 +0100

    crashtesting: assert on fdo62508-1.odt
    
    document, with meta:generator of "opxml2odf - Version KO 0.1" has
    a styles.xml xmlns of...
    
    xmlns:ofo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
    
    instead of the usual xmlns:fo=...
    
    use the importer namespace map to get the importers namespace prefix
    for the fastparser namespace uri for the token
    
    Change-Id: Ib633009f6c2b7dae5a3ceb1c921adfff84e21150
    Reviewed-on: https://gerrit.libreoffice.org/52720
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index 5ac6e5c2091e..f213f21cd2fa 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -382,7 +382,7 @@ public:
     XMLEventImportHelper& GetEventImport();
 
     static const OUString getNameFromToken( sal_Int32 nToken );
-    static const OUString getNamespacePrefixFromToken( sal_Int32 nToken );
+    static const OUString getNamespacePrefixFromToken(sal_Int32 nToken, const SvXMLNamespaceMap* pMap);
     static const OUString getNamespaceURIFromToken( sal_Int32 nToken );
     static const OUString getNamespacePrefixFromURI( const OUString& rURI );
 
diff --git a/unoxml/source/dom/saxbuilder.cxx b/unoxml/source/dom/saxbuilder.cxx
index 698d923a3ba9..81da91c51073 100644
--- a/unoxml/source/dom/saxbuilder.cxx
+++ b/unoxml/source/dom/saxbuilder.cxx
@@ -210,7 +210,7 @@ namespace DOM
         }
 
         Reference< XElement > aElement;
-        const OUString& aPrefix( SvXMLImport::getNamespacePrefixFromToken( nElement ) );
+        const OUString& aPrefix(SvXMLImport::getNamespacePrefixFromToken(nElement, nullptr));
         const OUString& aURI( SvXMLImport::getNamespaceURIFromToken( nElement ) );
         OUString aQualifiedName( SvXMLImport::getNameFromToken( nElement ) );
         if( !aPrefix.isEmpty() )
@@ -280,7 +280,7 @@ namespace DOM
         for (auto &it : *pAttribList)
         {
             sal_Int32 nAttrToken = it.getToken();
-            const OUString& aAttrPrefix( SvXMLImport::getNamespacePrefixFromToken( nAttrToken ) );
+            const OUString& aAttrPrefix(SvXMLImport::getNamespacePrefixFromToken(nAttrToken, nullptr));
             const OUString& aAttrURI( SvXMLImport::getNamespaceURIFromToken( nAttrToken ) );
             OUString aAttrQualifiedName( SvXMLImport::getNameFromToken( nAttrToken ) );
             if( !aAttrPrefix.isEmpty() )
@@ -307,7 +307,7 @@ namespace DOM
             throw SAXException();
 
         Reference< XElement > aElement(aNode, UNO_QUERY);
-        if( aElement->getPrefix() != SvXMLImport::getNamespacePrefixFromToken( nElement ) ||
+        if( aElement->getPrefix() != SvXMLImport::getNamespacePrefixFromToken(nElement, nullptr) ||
             aElement->getTagName() != SvXMLImport::getNameFromToken( nElement ) ) // consistency check
             throw SAXException();
 
diff --git a/xmloff/source/core/xmlictxt.cxx b/xmloff/source/core/xmlictxt.cxx
index 7d2cc23d9372..18e1446e190a 100644
--- a/xmloff/source/core/xmlictxt.cxx
+++ b/xmloff/source/core/xmlictxt.cxx
@@ -70,7 +70,7 @@ void SvXMLImportContext::Characters( const OUString& )
 void SAL_CALL SvXMLImportContext::startFastElement(sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
 {
     mrImport.isFastContext = false;
-    const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken( nElement );
+    const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken(nElement, &GetImport().GetNamespaceMap());
     const OUString& rLocalName = SvXMLImport::getNameFromToken( nElement );
     startUnknownElement( SvXMLImport::aDefaultNamespace, (rPrefix.isEmpty())? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName, Attribs );
 }
@@ -93,7 +93,7 @@ void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & /*rNamesp
         for( auto &it : *pAttribList )
         {
             sal_Int32 nToken = it.getToken();
-            const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken( nToken );
+            const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &GetImport().GetNamespaceMap());
             OUString sAttrName = SvXMLImport::getNameFromToken( nToken );
             if ( !rAttrNamespacePrefix.isEmpty() )
                 sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName;
@@ -117,7 +117,7 @@ void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & /*rNamesp
 void SAL_CALL SvXMLImportContext::endFastElement(sal_Int32 nElement)
 {
     mrImport.isFastContext = false;
-    const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken( nElement );
+    const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken(nElement, &GetImport().GetNamespaceMap());
     const OUString& rLocalName = SvXMLImport::getNameFromToken( nElement );
     endUnknownElement( SvXMLImport::aDefaultNamespace, (rPrefix.isEmpty())? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName );
 }
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 9b2b51060341..fdf943d775a3 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -2042,12 +2042,20 @@ const OUString SvXMLImport::getNameFromToken( sal_Int32 nToken )
                     aSeq.getConstArray() ), aSeq.getLength(), RTL_TEXTENCODING_UTF8 );
 }
 
-const OUString SvXMLImport::getNamespacePrefixFromToken( sal_Int32 nToken )
+const OUString SvXMLImport::getNamespacePrefixFromToken(sal_Int32 nToken, const SvXMLNamespaceMap* pMap)
 {
     sal_Int32 nNamespaceToken = ( nToken & NMSP_MASK ) >> NMSP_SHIFT;
     auto aIter( aNamespaceMap.find( nNamespaceToken ) );
     if( aIter != aNamespaceMap.end() )
+    {
+        if (pMap)
+        {
+            OUString sRet = pMap->GetPrefixByKey(pMap->GetKeyByName((*aIter).second.second));
+            if (!sRet.isEmpty())
+                return sRet;
+        }
         return (*aIter).second.first;
+    }
     else
         return OUString();
 }


More information about the Libreoffice-commits mailing list