diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-07-23 13:41:27 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-07-23 14:34:35 +0200 |
commit | ee3d408fd6c909556d1671d28591cde4c0122979 (patch) | |
tree | fbd524a11840527aa461899b511a7a9046a1d4b0 /xmloff | |
parent | daffec714ef28f52ae2d70e5553500046b8b26c2 (diff) |
sw bibliography, local copy: add ODF filter
Map it to <text:bibliography-mark loext:local-url="...">.
Note how this can be a relative URL, while the text:url attribute is
typically a http(s) URL.
Change-Id: If16171c9761221841ff07824cb0466fd42911480
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119407
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/qa/unit/text.cxx | 54 | ||||
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/text/txtflde.cxx | 17 | ||||
-rw-r--r-- | xmloff/source/text/txtfldi.cxx | 8 | ||||
-rw-r--r-- | xmloff/source/token/tokens.txt | 1 |
5 files changed, 75 insertions, 7 deletions
diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index d3b1fcc84a2c..22d1d3c15fcf 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -14,8 +14,11 @@ #include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/frame/XStorable.hpp> #include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/BibliographyDataType.hpp> #include <comphelper/propertysequence.hxx> +#include <comphelper/propertyvalue.hxx> +#include <comphelper/sequenceashashmap.hxx> #include <unotools/tempfile.hxx> using namespace ::com::sun::star; @@ -99,6 +102,57 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testCommentResolved) CPPUNIT_ASSERT(bResolved); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testBibliographyLocalUrl) +{ + // Given a document with a biblio field, with non-empty LocalURL: + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Reference<lang::XMultiServiceFactory> xFactory(getComponent(), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xField( + xFactory->createInstance("com.sun.star.text.TextField.Bibliography"), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aFields = { + comphelper::makePropertyValue("BibiliographicType", text::BibliographyDataType::WWW), + comphelper::makePropertyValue("Identifier", OUString("AT")), + comphelper::makePropertyValue("Author", OUString("Author")), + comphelper::makePropertyValue("Title", OUString("Title")), + comphelper::makePropertyValue("URL", OUString("http://www.example.com/test.pdf#page=1")), + comphelper::makePropertyValue("LocalURL", OUString("file:///home/me/test.pdf")), + }; + xField->setPropertyValue("Fields", uno::makeAny(aFields)); + uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextContent> xContent(xField, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false); + + // When invoking ODT export + import on it: + uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aStoreProps = { + comphelper::makePropertyValue("FilterName", OUString("writer8")), + }; + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + // Without the accompanying fix in place, this test would have resulted in an assertion failure, + // as LocalURL was mapped to XML_TOKEN_INVALID. + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + getComponent()->dispose(); + validate(aTempFile.GetFileName(), test::ODF); + getComponent() = loadFromDesktop(aTempFile.GetURL()); + + // Then make sure that LocalURL is preserved: + xTextDocument.set(getComponent(), uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference<container::XEnumerationAccess> xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortionEnum = xPara->createEnumeration(); + uno::Reference<beans::XPropertySet> xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY); + xField.set(xPortion->getPropertyValue("TextField"), uno::UNO_QUERY); + comphelper::SequenceAsHashMap aMap(xField->getPropertyValue("Fields")); + CPPUNIT_ASSERT(aMap.find("LocalURL") != aMap.end()); + auto aActual = aMap["LocalURL"].get<OUString>(); + CPPUNIT_ASSERT_EQUAL(OUString("file:///home/me/test.pdf"), aActual); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 27815a3d1ebf..e65de4fc61cb 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3416,6 +3416,8 @@ namespace xmloff::token { TOKEN( "page-content-bottom", XML_PAGE_CONTENT_BOTTOM ), TOKEN("margin-gutter", XML_MARGIN_GUTTER), + TOKEN("local-url", XML_LOCAL_URL), + #if OSL_DEBUG_LEVEL > 0 { 0, nullptr, std::nullopt, XML_TOKEN_END } #else diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx index 0513dc8e5273..713c5aff895b 100644 --- a/xmloff/source/text/txtflde.cxx +++ b/xmloff/source/text/txtflde.cxx @@ -2741,13 +2741,16 @@ void XMLTextFieldExport::ProcessBibliographyData( if (!sStr.isEmpty()) { XMLTokenEnum eElement = MapBibliographyFieldName(rProp.Name); - if (eElement == XML_URL) + if (eElement == XML_URL || eElement == XML_LOCAL_URL) { sStr = GetExport().GetRelativeReference(sStr); } - rExport.AddAttribute(XML_NAMESPACE_TEXT, - eElement, - sStr); + sal_uInt16 nPrefix = XML_NAMESPACE_TEXT; + if (eElement == XML_LOCAL_URL) + { + nPrefix = XML_NAMESPACE_LO_EXT; + } + rExport.AddAttribute(nPrefix, eElement, sStr); } } } @@ -3440,9 +3443,13 @@ enum XMLTokenEnum XMLTextFieldExport::MapBibliographyFieldName(std::u16string_vi { eName = XML_ISBN; } + else if (sName == u"LocalURL") + { + eName = XML_LOCAL_URL; + } else { - OSL_FAIL("Unknown bibliography info data"); + SAL_WARN("xmloff.text", "Unknown bibliography info data"); eName = XML_TOKEN_INVALID; } diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx index 93cd88152a35..dda0e0c8bf5a 100644 --- a/xmloff/source/text/txtfldi.cxx +++ b/xmloff/source/text/txtfldi.cxx @@ -2948,7 +2948,8 @@ void XMLBibliographyFieldImportContext::startFastElement( // iterate over attributes for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) ) { - if (IsTokenInNamespace(aIter.getToken(), XML_NAMESPACE_TEXT)) + if (IsTokenInNamespace(aIter.getToken(), XML_NAMESPACE_TEXT) + || IsTokenInNamespace(aIter.getToken(), XML_NAMESPACE_LO_EXT)) { auto nToken = aIter.getToken() & TOKEN_MASK; PropertyValue aValue; @@ -2975,7 +2976,7 @@ void XMLBibliographyFieldImportContext::startFastElement( else { OUString aStringValue = aIter.toString(); - if (nToken == XML_URL) + if (nToken == XML_URL || nToken == XML_LOCAL_URL) { aStringValue = GetImport().GetAbsoluteReference(aStringValue); } @@ -3115,6 +3116,9 @@ const char* XMLBibliographyFieldImportContext::MapBibliographyFieldName( case XML_ISBN: pName = "ISBN"; break; + case XML_LOCAL_URL: + pName = "LocalURL"; + break; default: assert(false && "Unknown bibliography info data"); pName = nullptr; diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index 403482cce9ab..3524d1ce8686 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -3170,4 +3170,5 @@ resolved page-content-top page-content-bottom margin-gutter +local-url TOKEN_END_DUMMY |