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

Michael Stahl (via logerrit) logerrit at kemper.freedesktop.org
Tue May 19 15:04:59 UTC 2020


 filter/source/xmlfilteradaptor/XmlFilterAdaptor.cxx |    1 
 include/xmloff/xmlmetai.hxx                         |    2 +
 xmloff/source/meta/xmlmetai.cxx                     |   35 ++++++++++++++------
 3 files changed, 28 insertions(+), 10 deletions(-)

New commits:
commit 34a513428d0786578c1c5f38fdc8a0fbd3b8f82f
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue May 19 12:40:32 2020 +0200
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Tue May 19 17:04:13 2020 +0200

    xmloff,filter: Flat ODF import: import BuildId from meta:generator
    
    The problem is that SvXMLMetaDocumentContext::endFastElement() works to
    init BuildId property for ODF packages but not for flat ODF files
    because the entire content of the document is inside that element.
    
    So init BuildId when the office:meta element ends.
    
    Also, add the missing "BuildId" property in XmlFilterAdaptor.
    
    This allows the CppunitTest_sd_import_tests testGradientAngle to work in
    the subsequent commit.
    
    Change-Id: I916a9288631078c1552cd8673e41fa9a9679f574
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94499
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>

diff --git a/filter/source/xmlfilteradaptor/XmlFilterAdaptor.cxx b/filter/source/xmlfilteradaptor/XmlFilterAdaptor.cxx
index 5e5a897e9e8e..8a1b2c96ade2 100644
--- a/filter/source/xmlfilteradaptor/XmlFilterAdaptor.cxx
+++ b/filter/source/xmlfilteradaptor/XmlFilterAdaptor.cxx
@@ -84,6 +84,7 @@ bool XmlFilterAdaptor::importImpl( const Sequence< css::beans::PropertyValue >&
     PropertyMapEntry aImportInfoMap[] =
     {
         { OUString("BaseURI"), 0, ::cppu::UnoType<OUString>::get(), PropertyAttribute::MAYBEVOID, 0},
+        { OUString("BuildId"), 0, ::cppu::UnoType<OUString>::get(), PropertyAttribute::MAYBEVOID, 0 },
         { OUString("DefaultDocumentSettings"), 0,
           ::cppu::UnoType<Sequence<PropertyValue>>::get(), PropertyAttribute::MAYBEVOID, 0 },
         { OUString(), 0, css::uno::Type(), 0, 0 }
diff --git a/include/xmloff/xmlmetai.hxx b/include/xmloff/xmlmetai.hxx
index b35291adc707..3af85c3f4a39 100644
--- a/include/xmloff/xmlmetai.hxx
+++ b/include/xmloff/xmlmetai.hxx
@@ -56,6 +56,8 @@ public:
         sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
 
 public:
+    void FinishMetaElement();
+
     static void setBuildId(const OUString & rGenerator,
         const css::uno::Reference< css::beans::XPropertySet>& xImportInfo );
 };
diff --git a/xmloff/source/meta/xmlmetai.cxx b/xmloff/source/meta/xmlmetai.cxx
index 20fcfb38cdf9..2f818681a8a5 100644
--- a/xmloff/source/meta/xmlmetai.cxx
+++ b/xmloff/source/meta/xmlmetai.cxx
@@ -47,11 +47,13 @@ class XMLDocumentBuilderContext : public SvXMLImportContext
 {
 private:
     css::uno::Reference< css::xml::dom::XSAXDocumentBuilder2> mxDocBuilder;
+    SvXMLMetaDocumentContext *const m_pTopLevel;
 
 public:
     XMLDocumentBuilderContext(SvXMLImport& rImport, sal_Int32 nElement,
         const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList,
-        const css::uno::Reference< css::xml::dom::XSAXDocumentBuilder2>& rDocBuilder);
+        const css::uno::Reference<css::xml::dom::XSAXDocumentBuilder2>& rDocBuilder,
+        SvXMLMetaDocumentContext * pTopLevel);
 
     virtual void SAL_CALL characters( const OUString& aChars ) override;
 
@@ -74,9 +76,11 @@ public:
 
 XMLDocumentBuilderContext::XMLDocumentBuilderContext(SvXMLImport& rImport,
         sal_Int32 /*nElement*/, const uno::Reference<xml::sax::XFastAttributeList>&,
-        const uno::Reference<xml::dom::XSAXDocumentBuilder2>& rDocBuilder) :
-    SvXMLImportContext( rImport ),
-    mxDocBuilder(rDocBuilder)
+        const uno::Reference<xml::dom::XSAXDocumentBuilder2>& rDocBuilder,
+        SvXMLMetaDocumentContext *const pTopLevel)
+    : SvXMLImportContext(rImport)
+    , mxDocBuilder(rDocBuilder)
+    , m_pTopLevel(pTopLevel)
 {
 }
 
@@ -89,6 +93,13 @@ void SAL_CALL XMLDocumentBuilderContext::startFastElement( sal_Int32 nElement,
 void SAL_CALL XMLDocumentBuilderContext::endFastElement( sal_Int32 nElement )
 {
     mxDocBuilder->endFastElement(nElement);
+    if (m_pTopLevel)
+    {
+        // call this here because in the flat ODF case the top-level
+        // endFastElement is called only at the very end of the document,
+        // which is too late to init BuildId
+        m_pTopLevel->FinishMetaElement();
+    }
 }
 
 void SAL_CALL XMLDocumentBuilderContext::startUnknownElement( const OUString& rNamespace,
@@ -110,7 +121,7 @@ void SAL_CALL XMLDocumentBuilderContext::characters( const OUString& rChars )
 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL XMLDocumentBuilderContext::createFastChildContext(
     sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
 {
-    return new XMLDocumentBuilderContext( GetImport(), nElement, xAttrList, mxDocBuilder );
+    return new XMLDocumentBuilderContext(GetImport(), nElement, xAttrList, mxDocBuilder, nullptr);
 }
 
 static void
@@ -186,18 +197,22 @@ SvXMLMetaDocumentContext::~SvXMLMetaDocumentContext()
 {
 }
 
-void SAL_CALL SvXMLMetaDocumentContext::startFastElement( sal_Int32 nElement,
+void SAL_CALL SvXMLMetaDocumentContext::startFastElement(sal_Int32 /*nElement*/,
             const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
 {
     mxDocBuilder->startDocument();
     // hardcode office:document-meta (necessary in case of flat file ODF)
-    mxDocBuilder->startFastElement( ( nElement & NMSP_MASK ) | XML_DOCUMENT_META, xAttrList );
+    mxDocBuilder->startFastElement(XML_ELEMENT(OFFICE, XML_DOCUMENT_META), xAttrList);
+}
+
+void SAL_CALL SvXMLMetaDocumentContext::endFastElement(sal_Int32 /*nElement*/)
+{
 }
 
-void SAL_CALL SvXMLMetaDocumentContext::endFastElement( sal_Int32 nElement )
+void SvXMLMetaDocumentContext::FinishMetaElement()
 {
     // hardcode office:document-meta (necessary in case of flat file ODF)
-    mxDocBuilder->endFastElement( ( nElement & NMSP_MASK ) | XML_DOCUMENT_META );
+    mxDocBuilder->endFastElement(XML_ELEMENT(OFFICE, XML_DOCUMENT_META));
     mxDocBuilder->endDocument();
     if (mxDocProps.is())
     {
@@ -218,7 +233,7 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLMetaDocumentContex
 {
     if ( nElement == XML_ELEMENT(OFFICE, XML_META) )
         return new XMLDocumentBuilderContext(
-                GetImport(), nElement, xAttrList, mxDocBuilder);
+                GetImport(), nElement, xAttrList, mxDocBuilder, this);
     return nullptr;
 }
 


More information about the Libreoffice-commits mailing list