summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-10-18 11:33:20 +0200
committerAndras Timar <andras.timar@collabora.com>2022-10-18 21:23:58 +0200
commit351139a183da5ab0a0a9dedc532ce729e369fea8 (patch)
tree82528a7026d085135be5f791999770dc504035ba
parentb3afa2d07bd55c04e545c3d6f1e8d8c4a4ceaf09 (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. (cherry picked from commit 888a8c3ca70ed19309c15ff7b9f0968ece337cb5) Conflicts: xmloff/source/token/tokens.txt Change-Id: Icecbe9037ede0bf8d72d52f2db44328a8db1d83a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141500 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r--include/xmloff/xmltoken.hxx2
-rw-r--r--schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng10
-rw-r--r--xmloff/qa/unit/data/content-control-alias.fodt8
-rw-r--r--xmloff/qa/unit/text.cxx74
-rw-r--r--xmloff/source/core/xmltoken.cxx2
-rw-r--r--xmloff/source/text/txtparae.cxx14
-rw-r--r--xmloff/source/text/xmlcontentcontrolcontext.cxx20
-rw-r--r--xmloff/source/text/xmlcontentcontrolcontext.hxx2
-rw-r--r--xmloff/source/token/tokens.txt2
9 files changed, 134 insertions, 0 deletions
diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
index 3a109374e177..e5c38a25bcfd 100644
--- a/include/xmloff/xmltoken.hxx
+++ b/include/xmloff/xmltoken.hxx
@@ -3501,6 +3501,8 @@ namespace xmloff::token {
XML_DATE_FORMAT,
XML_DATE_RFC_LANGUAGE_TAG,
XML_PLAIN_TEXT,
+ XML_ALIAS,
+ XML_TAG,
XML_TOKEN_END
};
diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
index 039750e5d5a8..0c9d2818e1cb 100644
--- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
+++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
@@ -2928,6 +2928,16 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.
<rng:ref name="boolean"/>
</rng:attribute>
</rng:optional>
+ <rng:optional>
+ <rng:attribute name="loext:alias">
+ <rng:ref name="string"/>
+ </rng:attribute>
+ </rng:optional>
+ <rng:optional>
+ <rng:attribute name="loext:tag">
+ <rng:ref name="string"/>
+ </rng:attribute>
+ </rng:optional>
<rng:zeroOrMore>
<rng:element name="loext:list-item">
<rng:attribute name="loext:display-text">
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 388106702217..446e292a08cf 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -831,6 +831,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::TempFile 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:
@@ -861,6 +900,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
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index ab3400634a9f..468c727e3d52 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -3504,6 +3504,8 @@ namespace xmloff::token {
TOKEN("date-format", XML_DATE_FORMAT),
TOKEN("date-rfc-language-tag", XML_DATE_RFC_LANGUAGE_TAG),
TOKEN("plain-text", XML_PLAIN_TEXT),
+ TOKEN("alias", XML_ALIAS),
+ TOKEN("tag", XML_TAG),
#if OSL_DEBUG_LEVEL > 0
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 0a8d3b59bdd6..eb510f025383 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -3965,6 +3965,20 @@ void XMLTextParagraphExport::ExportContentControl(
sax::Converter::convertBool(aBuffer, bComboBox);
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_COMBOBOX, aBuffer.makeStringAndClear());
}
+
+ OUString aAlias;
+ xPropertySet->getPropertyValue("Alias") >>= aAlias;
+ if (!aAlias.isEmpty())
+ {
+ GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_ALIAS, aAlias);
+ }
+
+ OUString aTag;
+ xPropertySet->getPropertyValue("Tag") >>= aTag;
+ if (!aTag.isEmpty())
+ {
+ GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_TAG, aTag);
+ }
}
SvXMLElementExport aElem(GetExport(), bExport, XML_NAMESPACE_LO_EXT, XML_CONTENT_CONTROL, false,
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.cxx b/xmloff/source/text/xmlcontentcontrolcontext.cxx
index 36580bab3a02..bb4580b2cb78 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.cxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.cxx
@@ -133,6 +133,16 @@ void XMLContentControlContext::startFastElement(
}
break;
}
+ case XML_ELEMENT(LO_EXT, XML_ALIAS):
+ {
+ m_aAlias = rIter.toString();
+ break;
+ }
+ case XML_ELEMENT(LO_EXT, XML_TAG):
+ {
+ m_aTag = rIter.toString();
+ break;
+ }
default:
XMLOFF_WARN_UNKNOWN("xmloff", rIter);
}
@@ -228,6 +238,16 @@ void XMLContentControlContext::endFastElement(sal_Int32)
{
xPropertySet->setPropertyValue("ComboBox", uno::Any(m_bComboBox));
}
+
+ if (!m_aAlias.isEmpty())
+ {
+ xPropertySet->setPropertyValue("Alias", uno::Any(m_aAlias));
+ }
+
+ if (!m_aTag.isEmpty())
+ {
+ xPropertySet->setPropertyValue("Tag", uno::Any(m_aTag));
+ }
}
css::uno::Reference<css::xml::sax::XFastContextHandler>
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.hxx b/xmloff/source/text/xmlcontentcontrolcontext.hxx
index e507b02e85cd..0bfca015ec68 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.hxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.hxx
@@ -50,6 +50,8 @@ class XMLContentControlContext : public SvXMLImportContext
OUString m_aCurrentDate;
bool m_bPlainText = false;
bool m_bComboBox = false;
+ OUString m_aAlias;
+ OUString m_aTag;
public:
XMLContentControlContext(SvXMLImport& rImport, sal_Int32 nElement, XMLHints_Impl& rHints,
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
index 11b83bdcbd77..d3f9c6f45d81 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -3247,4 +3247,6 @@ picture
date-format
date-rfc-language-tag
plain-text
+alias
+tag
TOKEN_END_DUMMY