diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-11-30 08:49:10 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-11-30 15:36:10 +0100 |
commit | 98770243f7f5387aae06e83ed4de0d68e02abb02 (patch) | |
tree | 7df0c5a943bbfb34251625b0270813ab8e4e1b8a /writerperfect/source/writer | |
parent | 1a48cdaf91633b354fb1110c566c766a4398fba0 (diff) |
EPUB export: allow setting custom metadata explicitly
If not set, fall back to the existing auto-find. The testcase now
asserts that the priority is:
- api
- if that is not set, then xmp
- if that is not set, then doc
(And at the end libepubgen itself has some defaults as well.)
Change-Id: Ie8fc646b81c4a287690fd2eeed43f4786b7938bf
Reviewed-on: https://gerrit.libreoffice.org/45552
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerperfect/source/writer')
-rw-r--r-- | writerperfect/source/writer/EPUBExportDialog.cxx | 2 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/xmlimp.cxx | 54 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/xmlmetai.cxx | 28 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/xmlmetai.hxx | 14 |
4 files changed, 71 insertions, 27 deletions
diff --git a/writerperfect/source/writer/EPUBExportDialog.cxx b/writerperfect/source/writer/EPUBExportDialog.cxx index 5c0eb9d1e930..da42954a5d02 100644 --- a/writerperfect/source/writer/EPUBExportDialog.cxx +++ b/writerperfect/source/writer/EPUBExportDialog.cxx @@ -125,7 +125,7 @@ IMPL_LINK_NOARG(EPUBExportDialog, CoverClickHdl, Button *, void) IMPL_LINK_NOARG(EPUBExportDialog, OKClickHdl, Button *, void) { if (!m_pCoverPath->GetText().isEmpty()) - mrFilterData["EPUBCoverImage"] <<= m_pCoverPath->GetText(); + mrFilterData["RVNGCoverImage"] <<= m_pCoverPath->GetText(); EndDialog(RET_OK); } diff --git a/writerperfect/source/writer/exp/xmlimp.cxx b/writerperfect/source/writer/exp/xmlimp.cxx index 57f89c870b9a..bb3d067660b7 100644 --- a/writerperfect/source/writer/exp/xmlimp.cxx +++ b/writerperfect/source/writer/exp/xmlimp.cxx @@ -56,7 +56,7 @@ OUString FindCoverImage(const OUString &rDocumentBaseURL, OUString &rMimeType, c // See if filter data contains a cover image explicitly. for (sal_Int32 i = 0; i < rFilterData.getLength(); ++i) { - if (rFilterData[i].Name == "EPUBCoverImage") + if (rFilterData[i].Name == "RVNGCoverImage") { rFilterData[i].Value >>= aRet; break; @@ -113,8 +113,45 @@ OUString FindCoverImage(const OUString &rDocumentBaseURL, OUString &rMimeType, c } /// Picks up XMP metadata from the base directory. -void FindXMPMetadata(const uno::Reference<uno::XComponentContext> &xContext, const OUString &rDocumentBaseURL, const uno::Sequence<beans::PropertyValue> &/*rFilterData*/, librevenge::RVNGPropertyList &rMetaData) +void FindXMPMetadata(const uno::Reference<uno::XComponentContext> &xContext, const OUString &rDocumentBaseURL, const uno::Sequence<beans::PropertyValue> &rFilterData, librevenge::RVNGPropertyList &rMetaData) { + // See if filter data contains metadata explicitly. + OUString aValue; + for (sal_Int32 i = 0; i < rFilterData.getLength(); ++i) + { + if (rFilterData[i].Name == "RVNGIdentifier") + { + rFilterData[i].Value >>= aValue; + if (!aValue.isEmpty()) + rMetaData.insert("dc:identifier", aValue.toUtf8().getStr()); + } + else if (rFilterData[i].Name == "RVNGTitle") + { + rFilterData[i].Value >>= aValue; + if (!aValue.isEmpty()) + rMetaData.insert("dc:title", aValue.toUtf8().getStr()); + } + else if (rFilterData[i].Name == "RVNGInitialCreator") + { + rFilterData[i].Value >>= aValue; + if (!aValue.isEmpty()) + rMetaData.insert("meta:initial-creator", aValue.toUtf8().getStr()); + } + else if (rFilterData[i].Name == "RVNGLanguage") + { + rFilterData[i].Value >>= aValue; + if (!aValue.isEmpty()) + rMetaData.insert("dc:language", aValue.toUtf8().getStr()); + } + else if (rFilterData[i].Name == "RVNGDate") + { + rFilterData[i].Value >>= aValue; + if (!aValue.isEmpty()) + rMetaData.insert("dc:date", aValue.toUtf8().getStr()); + } + } + + // If not set explicitly, try to pick it up from the base directory. if (rDocumentBaseURL.isEmpty()) return; @@ -138,7 +175,7 @@ void FindXMPMetadata(const uno::Reference<uno::XComponentContext> &xContext, con uno::Reference<io::XInputStream> xStream(new utl::OStreamWrapper(aStream)); aInputSource.aInputStream = xStream; uno::Reference<xml::sax::XParser> xParser = xml::sax::Parser::create(xContext); - rtl::Reference<XMPParser> xXMP(new XMPParser()); + rtl::Reference<XMPParser> xXMP(new XMPParser(rMetaData)); uno::Reference<xml::sax::XDocumentHandler> xDocumentHandler(xXMP.get()); xParser->setDocumentHandler(xDocumentHandler); try @@ -150,17 +187,6 @@ void FindXMPMetadata(const uno::Reference<uno::XComponentContext> &xContext, con SAL_WARN("writerperfect", "FindXMPMetadata: parseStream() failed:" << rException.Message); return; } - - if (!xXMP->m_aIdentifier.isEmpty()) - rMetaData.insert("dc:identifier", xXMP->m_aIdentifier.toUtf8().getStr()); - if (!xXMP->m_aTitle.isEmpty()) - rMetaData.insert("dc:title", xXMP->m_aTitle.toUtf8().getStr()); - if (!xXMP->m_aCreator.isEmpty()) - rMetaData.insert("meta:initial-creator", xXMP->m_aCreator.toUtf8().getStr()); - if (!xXMP->m_aLanguage.isEmpty()) - rMetaData.insert("dc:language", xXMP->m_aLanguage.toUtf8().getStr()); - if (!xXMP->m_aDate.isEmpty()) - rMetaData.insert("dc:date", xXMP->m_aDate.toUtf8().getStr()); } } diff --git a/writerperfect/source/writer/exp/xmlmetai.cxx b/writerperfect/source/writer/exp/xmlmetai.cxx index 09e56c8c2388..7ee2024968ae 100644 --- a/writerperfect/source/writer/exp/xmlmetai.cxx +++ b/writerperfect/source/writer/exp/xmlmetai.cxx @@ -37,7 +37,8 @@ XMLDcTitleContext::XMLDcTitleContext(XMLImport &rImport, XMLMetaDocumentContext void XMLDcTitleContext::characters(const OUString &rChars) { OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); - mrMeta.m_aPropertyList.insert("dc:title", librevenge::RVNGString(sCharU8.getStr())); + if (!mrMeta.m_aPropertyList["dc:title"]) + mrMeta.m_aPropertyList.insert("dc:title", librevenge::RVNGString(sCharU8.getStr())); } /// Handler for <dc:language>. @@ -59,7 +60,8 @@ XMLDcLanguageContext::XMLDcLanguageContext(XMLImport &rImport, XMLMetaDocumentCo void XMLDcLanguageContext::characters(const OUString &rChars) { OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); - mrMeta.m_aPropertyList.insert("dc:language", librevenge::RVNGString(sCharU8.getStr())); + if (!mrMeta.m_aPropertyList["dc:language"]) + mrMeta.m_aPropertyList.insert("dc:language", librevenge::RVNGString(sCharU8.getStr())); } /// Handler for <dc:date>. @@ -81,7 +83,8 @@ XMLDcDateContext::XMLDcDateContext(XMLImport &rImport, XMLMetaDocumentContext &r void XMLDcDateContext::characters(const OUString &rChars) { OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); - mrMeta.m_aPropertyList.insert("dc:date", librevenge::RVNGString(sCharU8.getStr())); + if (!mrMeta.m_aPropertyList["dc:date"]) + mrMeta.m_aPropertyList.insert("dc:date", librevenge::RVNGString(sCharU8.getStr())); } /// Handler for <meta:generator>. @@ -125,7 +128,8 @@ XMLMetaInitialCreatorContext::XMLMetaInitialCreatorContext(XMLImport &rImport, X void XMLMetaInitialCreatorContext::characters(const OUString &rChars) { OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); - mrMeta.m_aPropertyList.insert("meta:initial-creator", librevenge::RVNGString(sCharU8.getStr())); + if (!mrMeta.m_aPropertyList["meta:initial-creator"]) + mrMeta.m_aPropertyList.insert("meta:initial-creator", librevenge::RVNGString(sCharU8.getStr())); } XMLMetaDocumentContext::XMLMetaDocumentContext(XMLImport &rImport) @@ -157,7 +161,10 @@ void XMLMetaDocumentContext::endElement(const OUString &/*rName*/) mrImport.GetGenerator().setDocumentMetaData(m_aPropertyList); } -XMPParser::XMPParser() = default; +XMPParser::XMPParser(librevenge::RVNGPropertyList &rMetaData) + : mrMetaData(rMetaData) +{ +} XMPParser::~XMPParser() = default; @@ -167,6 +174,17 @@ void XMPParser::startDocument() void XMPParser::endDocument() { + + if (!mrMetaData["dc:identifier"] && !m_aIdentifier.isEmpty()) + mrMetaData.insert("dc:identifier", m_aIdentifier.toUtf8().getStr()); + if (!mrMetaData["dc:title"] && !m_aTitle.isEmpty()) + mrMetaData.insert("dc:title", m_aTitle.toUtf8().getStr()); + if (!mrMetaData["meta:initial-creator"] && !m_aCreator.isEmpty()) + mrMetaData.insert("meta:initial-creator", m_aCreator.toUtf8().getStr()); + if (!mrMetaData["dc:language"] && !m_aLanguage.isEmpty()) + mrMetaData.insert("dc:language", m_aLanguage.toUtf8().getStr()); + if (!mrMetaData["dc:date"] && !m_aDate.isEmpty()) + mrMetaData.insert("dc:date", m_aDate.toUtf8().getStr()); } void XMPParser::startElement(const OUString &rName, const uno::Reference<xml::sax::XAttributeList> &/*xAttribs*/) diff --git a/writerperfect/source/writer/exp/xmlmetai.hxx b/writerperfect/source/writer/exp/xmlmetai.hxx index a011e6b83184..fab55277f0e5 100644 --- a/writerperfect/source/writer/exp/xmlmetai.hxx +++ b/writerperfect/source/writer/exp/xmlmetai.hxx @@ -39,7 +39,7 @@ class XMPParser: public cppu::WeakImplHelper > { public: - explicit XMPParser(); + explicit XMPParser(librevenge::RVNGPropertyList &rMetaData); virtual ~XMPParser() override; // XDocumentHandler @@ -59,22 +59,22 @@ public: virtual void SAL_CALL setDocumentLocator(const css::uno::Reference<css::xml::sax::XLocator> &xLocator) override; - OUString m_aIdentifier; - OUString m_aTitle; - OUString m_aCreator; - OUString m_aLanguage; - OUString m_aDate; - private: + librevenge::RVNGPropertyList &mrMetaData; bool m_bInIdentifier = false; + OUString m_aIdentifier; bool m_bInTitle = false; bool m_bInTitleItem = false; + OUString m_aTitle; bool m_bInCreator = false; bool m_bInCreatorItem = false; + OUString m_aCreator; bool m_bInLanguage = false; bool m_bInLanguageItem = false; + OUString m_aLanguage; bool m_bInDate = false; bool m_bInDateItem = false; + OUString m_aDate; }; } // namespace exp |