summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-09-04 17:27:39 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-09-04 20:53:22 +0200
commit41092fe0bb0d2f49948bf2a1f27acb53f21a84aa (patch)
treefadc83af7778ce362610dfc72954e8ef98f8ad2e /writerperfect
parent72b19aa29f9adcab6dd20d1517208f3b999d055e (diff)
EPUB export: write author metadata
<meta:initial-creator> is the author and <dc:creator> is the "last modified by" in ODF (it seems), so map the first to EPUB's <dc:creator>. Change-Id: Id701c8c38b0901ae14fbbc7b32d01b43d6d03f68 Reviewed-on: https://gerrit.libreoffice.org/41903 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'writerperfect')
-rw-r--r--writerperfect/qa/unit/EPUBExportTest.cxx13
-rw-r--r--writerperfect/qa/unit/data/writer/epubexport/meta.fodt12
-rw-r--r--writerperfect/source/writer/exp/xmlmetai.cxx24
3 files changed, 49 insertions, 0 deletions
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index fef1cf19770c..61a6da2941f0 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -53,6 +53,7 @@ public:
void testPageBreakSplit();
void testSpanAutostyle();
void testParaAutostyleCharProps();
+ void testMeta();
CPPUNIT_TEST_SUITE(EPUBExportTest);
CPPUNIT_TEST(testOutlineLevel);
@@ -61,6 +62,7 @@ public:
CPPUNIT_TEST(testPageBreakSplit);
CPPUNIT_TEST(testSpanAutostyle);
CPPUNIT_TEST(testParaAutostyleCharProps);
+ CPPUNIT_TEST(testMeta);
CPPUNIT_TEST_SUITE_END();
};
@@ -88,6 +90,7 @@ void EPUBExportTest::tearDown()
void EPUBExportTest::registerNamespaces(xmlXPathContextPtr &pXmlXpathCtx)
{
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dc"), BAD_CAST("http://purl.org/dc/elements/1.1/"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("opf"), BAD_CAST("http://www.idpf.org/2007/opf"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xhtml"), BAD_CAST("http://www.w3.org/1999/xhtml"));
}
@@ -202,6 +205,16 @@ void EPUBExportTest::testParaAutostyleCharProps()
assertXPath(mpXmlDoc, "//xhtml:p[2]/xhtml:span", "class", "span1");
}
+void EPUBExportTest::testMeta()
+{
+ createDoc("meta.fodt", {});
+
+ mpXmlDoc = parseExport("OEBPS/content.opf");
+ // This was "Unknown Author", <meta:initial-creator> was not handled.
+ assertXPathContent(mpXmlDoc, "/opf:package/opf:metadata/dc:creator", "A U Thor");
+ assertXPathContent(mpXmlDoc, "/opf:package/opf:metadata/dc:title", "Title");
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest);
}
diff --git a/writerperfect/qa/unit/data/writer/epubexport/meta.fodt b/writerperfect/qa/unit/data/writer/epubexport/meta.fodt
new file mode 100644
index 000000000000..4e46fe79fcda
--- /dev/null
+++ b/writerperfect/qa/unit/data/writer/epubexport/meta.fodt
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document office:mimetype="application/vnd.oasis.opendocument.text" office:version="1.2" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <office:meta>
+ <meta:initial-creator>A U Thor</meta:initial-creator>
+ <dc:title>Title</dc:title>
+ </office:meta>
+ <office:body>
+ <office:text>
+ <text:p><text:span>Hello world!</text:span></text:p>
+ </office:text>
+ </office:body>
+</office:document>
diff --git a/writerperfect/source/writer/exp/xmlmetai.cxx b/writerperfect/source/writer/exp/xmlmetai.cxx
index 6c01adeb8f11..8777f4fa0b6f 100644
--- a/writerperfect/source/writer/exp/xmlmetai.cxx
+++ b/writerperfect/source/writer/exp/xmlmetai.cxx
@@ -106,6 +106,28 @@ void XMLMetaGeneratorContext::characters(const OUString &rChars)
mrMeta.m_aPropertyList.insert("meta:generator", librevenge::RVNGString(sCharU8.getStr()));
}
+/// Handler for <meta:initial-creator>.
+class XMLMetaInitialCreatorContext : public XMLImportContext
+{
+public:
+ XMLMetaInitialCreatorContext(XMLImport &rImport, XMLMetaDocumentContext &rMeta);
+
+ void SAL_CALL characters(const OUString &rChars) override;
+
+ XMLMetaDocumentContext &mrMeta;
+};
+
+XMLMetaInitialCreatorContext::XMLMetaInitialCreatorContext(XMLImport &rImport, XMLMetaDocumentContext &rMeta)
+ : XMLImportContext(rImport), mrMeta(rMeta)
+{
+}
+
+void XMLMetaInitialCreatorContext::characters(const OUString &rChars)
+{
+ OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8);
+ mrMeta.m_aPropertyList.insert("meta:initial-creator", librevenge::RVNGString(sCharU8.getStr()));
+}
+
XMLMetaDocumentContext::XMLMetaDocumentContext(XMLImport &rImport)
: XMLImportContext(rImport)
{
@@ -121,6 +143,8 @@ XMLImportContext *XMLMetaDocumentContext::CreateChildContext(const OUString &rNa
return new XMLDcDateContext(mrImport, *this);
if (rName == "meta:generator")
return new XMLMetaGeneratorContext(mrImport, *this);
+ if (rName == "meta:initial-creator")
+ return new XMLMetaInitialCreatorContext(mrImport, *this);
return nullptr;
}