summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Kosiorek <gang65@poczta.onet.pl>2020-10-16 16:46:52 +0200
committerMichael Stahl <michael.stahl@cib.de>2020-10-17 12:44:48 +0200
commitf25f804b0009f026cfac665bb8ec03b4656d81fb (patch)
tree7099ef7cf815bf2523e84a717e7a6eaecc923bfe
parent13331f26106fdf7c9563374d81baad6e293bb542 (diff)
tdf#133377 OOXML Fix storage of date in Custom Properties
During exporting documents into OOXML formats (docx, xlsx, pptx), if custom properties have Date format, the day and year were switched. This commit fixes that. Change-Id: Id497602eb3354de78bfd52bf5ef61d32aafd957d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104450 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r--oox/source/core/xmlfilterbase.cxx4
-rw-r--r--sw/qa/extras/ooxmlexport/data/custom-properties.docxbin0 -> 12892 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport2.cxx47
-rw-r--r--sw/qa/unit/swmodeltestbase.cxx10
4 files changed, 60 insertions, 1 deletions
diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index dbc419c28a3e..43f4e573229a 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -826,11 +826,13 @@ writeCustomProperties( XmlFilterBase& rSelf, const Reference< XDocumentPropertie
util::DateTime aDateTime;
if ( rProp.Value >>= num )
{
+ // i4 - 4-byte signed integer
+ // r8 - 8-byte real number
writeElement( pAppProps, FSNS( XML_vt, XML_i4 ), num );
}
else if ( rProp.Value >>= aDate )
{
- aDateTime = util::DateTime( 0, 0 , 0, 0, aDate.Year, aDate.Month, aDate.Day, true );
+ aDateTime = util::DateTime( 0, 0 , 0, 0, aDate.Day, aDate.Month, aDate.Year, true );
writeElement( pAppProps, FSNS( XML_vt, XML_filetime ), aDateTime);
}
else if ( rProp.Value >>= aDuration )
diff --git a/sw/qa/extras/ooxmlexport/data/custom-properties.docx b/sw/qa/extras/ooxmlexport/data/custom-properties.docx
new file mode 100644
index 000000000000..33cce91f7ec4
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/custom-properties.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
index f05f6251ed48..a77d41b64094 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
@@ -85,6 +85,53 @@ DECLARE_OOXMLEXPORT_TEST(testPageGraphicBackground, "page-graphic-background.odt
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(xPageStyle, "BackColor"));
}
+
+DECLARE_OOXMLEXPORT_TEST(testCustomProperties, "custom-properties.docx")
+{
+ // tdf#133377 FILESAVE XLSX: Make sure the custom/core/application file properties
+ // are stored correctly after roundtrip to .docx
+
+ // Extended file properties - specific to Office package,
+ // eg. docx - Number of Pages, pptx - Number of Slides
+ xmlDocUniquePtr pXmlDoc = parseExport("docProps/app.xml");
+ if (!pXmlDoc)
+ return;
+
+ assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:Paragraphs", "1");
+ //assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:Lines", "1");
+ assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:Pages", "1");
+ assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:Words", "3");
+ assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:Characters", "21");
+ assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:CharactersWithSpaces", "23");
+ assertXPathContent(pXmlDoc, "/extended-properties:Properties/extended-properties:Company", "hhhhkompany");
+
+ // Custom file properties - defined by user
+ xmlDocUniquePtr pCustomXml = parseExport("docProps/custom.xml");
+ assertXPath(pCustomXml, "/custom-properties:Properties/custom-properties:property[12]",
+ "name", "testDateProperty");
+ assertXPathContent(pCustomXml, "/custom-properties:Properties/custom-properties:property[12]/vt:filetime",
+ "1982-04-19T10:00:00Z");
+ assertXPath(pCustomXml, "/custom-properties:Properties/custom-properties:property[14]",
+ "name", "testNegativeNumberProperty");
+ assertXPathContent(pCustomXml, "/custom-properties:Properties/custom-properties:property[14]/vt:i4",
+ "-100");
+ assertXPath(pCustomXml, "/custom-properties:Properties/custom-properties:property[17]",
+ "name", "testTextProperty");
+ assertXPathContent(pCustomXml, "/custom-properties:Properties/custom-properties:property[17]/vt:lpwstr",
+ "testPropertyValue");
+ assertXPath(pCustomXml, "/custom-properties:Properties/custom-properties:property[18]",
+ "name", "testYesNoProperty");
+ assertXPathContent(pCustomXml, "/custom-properties:Properties/custom-properties:property[18]/vt:bool",
+ "1");
+
+ // Core file properties - common for all packages (eg. creation date, modify date)
+ pXmlDoc = parseExport("docProps/core.xml");
+ assertXPathContent(pXmlDoc, "/cp:coreProperties/dc:creator", "Bartosz Kosiorek");
+ assertXPathContent(pXmlDoc, "/cp:coreProperties/dc:description", "cccckomentarzglowny");
+ assertXPathContent(pXmlDoc, "/cp:coreProperties/cp:lastPrinted", "2020-10-15T07:42:00Z");
+ assertXPathContent(pXmlDoc, "/cp:coreProperties/dcterms:created", "2020-10-14T16:23:00Z");
+}
+
DECLARE_OOXMLEXPORT_TEST(testZoom, "zoom.docx")
{
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
diff --git a/sw/qa/unit/swmodeltestbase.cxx b/sw/qa/unit/swmodeltestbase.cxx
index 306e03476cef..b520967b21f4 100644
--- a/sw/qa/unit/swmodeltestbase.cxx
+++ b/sw/qa/unit/swmodeltestbase.cxx
@@ -729,8 +729,18 @@ void SwModelTestBase::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("lc"),
BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas"));
xmlXPathRegisterNs(
+ pXmlXpathCtx, BAD_CAST("cp"),
+ BAD_CAST("http://schemas.openxmlformats.org/package/2006/metadata/core-properties"));
+ xmlXPathRegisterNs(
pXmlXpathCtx, BAD_CAST("extended-properties"),
BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"));
+ xmlXPathRegisterNs(
+ pXmlXpathCtx, BAD_CAST("custom-properties"),
+ BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"));
+ xmlXPathRegisterNs(
+ pXmlXpathCtx, BAD_CAST("vt"),
+ BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"));
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dcterms"), BAD_CAST("http://purl.org/dc/terms/"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("a14"),
BAD_CAST("http://schemas.microsoft.com/office/drawing/2010/main"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("c"),