summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2020-05-19 12:40:32 +0200
committerMichael Stahl <michael.stahl@cib.de>2020-05-19 17:04:13 +0200
commit34a513428d0786578c1c5f38fdc8a0fbd3b8f82f (patch)
tree1156c86be7d235e03821b11928d5b7637c02d1a7
parent96db6fb300473fc7ba2af22770f0a7bd7c4f780b (diff)
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@cib.de>
-rw-r--r--filter/source/xmlfilteradaptor/XmlFilterAdaptor.cxx1
-rw-r--r--include/xmloff/xmlmetai.hxx2
-rw-r--r--xmloff/source/meta/xmlmetai.cxx35
3 files changed, 28 insertions, 10 deletions
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;
}