diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-10-18 11:33:20 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-10-18 12:40:31 +0200 |
commit | 888a8c3ca70ed19309c15ff7b9f0968ece337cb5 (patch) | |
tree | 9c5749e71e609722ae6cecfbd82459a0e626bb53 /xmloff/qa | |
parent | 36bffa3cb5d30a6f58253c627ba23d1cde6864c8 (diff) |
sw content controls, alias and tag: add ODT filter
Map the Alias/Tag UNO properties to:
<loext:content-control loext:alias="..." loext:tag="...">
on export, and do the opposite on import.
Change-Id: Icecbe9037ede0bf8d72d52f2db44328a8db1d83a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141492
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'xmloff/qa')
-rw-r--r-- | xmloff/qa/unit/data/content-control-alias.fodt | 8 | ||||
-rw-r--r-- | xmloff/qa/unit/text.cxx | 74 |
2 files changed, 82 insertions, 0 deletions
diff --git a/xmloff/qa/unit/data/content-control-alias.fodt b/xmloff/qa/unit/data/content-control-alias.fodt new file mode 100644 index 000000000000..8307f682e474 --- /dev/null +++ b/xmloff/qa/unit/data/content-control-alias.fodt @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:body> + <office:text> + <text:p><loext:content-control loext:alias="my alias" loext:tag="my tag">test</loext:content-control></text:p> + </office:text> + </office:body> +</office:document> diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index ee5e4a580ebb..3476aee49c71 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -935,6 +935,45 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testComboBoxContentControlExport) assertXPath(pXmlDoc, "//loext:content-control", "combobox", "true"); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testAliasContentControlExport) +{ + // Given a document with a content control and its alias around a text portion: + getComponent() = loadFromDesktop("private:factory/swriter"); + uno::Reference<lang::XMultiServiceFactory> xMSF(getComponent(), uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("Alias", uno::Any(OUString("my alias"))); + xContentControlProps->setPropertyValue("Tag", uno::Any(OUString("my tag"))); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When exporting to ODT: + uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aStoreProps = comphelper::InitPropertySequence({ + { "FilterName", uno::Any(OUString("writer8")) }, + }); + utl::TempFileNamed aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aStoreProps); + validate(aTempFile.GetFileName(), test::ODF); + + // Then make sure the expected markup is used: + std::unique_ptr<SvStream> pStream = parseExportStream(aTempFile, "content.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + // Without the accompanying fix in place, this test would have failed with: + // - Expression: prop + // - XPath '//loext:content-control' no attribute 'alias' exist + // i.e. alias was lost on export. + assertXPath(pXmlDoc, "//loext:content-control", "alias", "my alias"); + assertXPath(pXmlDoc, "//loext:content-control", "tag", "my tag"); +} + CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testComboBoxContentControlImport) { // Given an ODF document with a plain-text content control: @@ -965,6 +1004,41 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testComboBoxContentControlImport) CPPUNIT_ASSERT(bComboBox); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testAliasContentControlImport) +{ + // Given an ODF document with a content control and its alias/tag: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "content-control-alias.fodt"; + + // When loading that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure that the content control is not lost on import: + uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs = xParagraphsAccess->createEnumeration(); + uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); + uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + uno::Reference<text::XTextContent> xContentControl; + xTextPortion->getPropertyValue("ContentControl") >>= xContentControl; + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + OUString aAlias; + xContentControlProps->getPropertyValue("Alias") >>= aAlias; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: my alias + // - Actual : + // i.e. the alias was lost on import. + CPPUNIT_ASSERT_EQUAL(OUString("my alias"), aAlias); + OUString aTag; + xContentControlProps->getPropertyValue("Tag") >>= aTag; + CPPUNIT_ASSERT_EQUAL(OUString("my tag"), aTag); +} + CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDropdownContentControlAutostyleExport) { // Given a document with a dropdown content control, and formatting that forms an autostyle in |