oox/source/core/xmlfilterbase.cxx                    |    4 +
 sw/qa/extras/ooxmlexport/data/custom-properties.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport2.cxx            |   47 +++++++++++++++++++
 sw/qa/unit/swmodeltestbase.cxx                       |   10 ++++
 4 files changed, 60 insertions(+), 1 deletion(-)

New commits:
commit f25f804b0009f026cfac665bb8ec03b4656d81fb
Author:     Bartosz Kosiorek <gan...@poczta.onet.pl>
AuthorDate: Fri Oct 16 16:46:52 2020 +0200
Commit:     Michael Stahl <michael.st...@cib.de>
CommitDate: Sat Oct 17 12:44:48 2020 +0200

    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.st...@cib.de>

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
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/custom-properties.docx 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
@@ -728,9 +728,19 @@ void 
SwModelTestBase::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
                        
BAD_CAST("http://schemas.openxmlformats.org/package/2006/content-types";));
     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"),
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to