summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-12-02 10:38:20 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-12-02 10:55:11 +0100
commit831492f3d50f3d131f458f4ec0e5e802b612923f (patch)
tree8588488a1ec159171da00f11f8c53c9ea9478111 /sw
parentfb60f000525427af3b331a746f8cedc54fd32922 (diff)
DOCX import: handle <w:smartTag>
These can be sort of arbitrary key-value pairs around one or multiple runs, handle the following subset: - when they appear at a paragraph context -> we assume they are annotations on the paragraph - when the smart tag's URI/element is RDF -> we map these to RDF metadata statements on paragraphs - when the attribute name's namespace is known, because in ODF we need to specify both a path and a type (namespace) for the RDF graph, and OOXML only provides a namespace As a start, recognize the TSCP BAF namespace from <https://www.tscp.org/wp-content/uploads/2013/08/TSCP_BAFv1.pdf>. Change-Id: Ib188b1395e7ec7e0441b4f12f86cfef99fb9f096
Diffstat (limited to 'sw')
-rw-r--r--sw/CppunitTest_sw_ooxmlimport.mk1
-rw-r--r--sw/qa/extras/ooxmlimport/data/tscp.docxbin0 -> 4758 bytes
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport.cxx40
3 files changed, 41 insertions, 0 deletions
diff --git a/sw/CppunitTest_sw_ooxmlimport.mk b/sw/CppunitTest_sw_ooxmlimport.mk
index 5aae15d8a6b4..4074255a7cf3 100644
--- a/sw/CppunitTest_sw_ooxmlimport.mk
+++ b/sw/CppunitTest_sw_ooxmlimport.mk
@@ -95,6 +95,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_ooxmlimport,\
ucb/source/ucp/file/ucpfile1 \
unotools/util/utl \
unoxml/source/service/unoxml \
+ unoxml/source/rdf/unordf \
writerfilter/util/writerfilter \
xmloff/util/xo \
))
diff --git a/sw/qa/extras/ooxmlimport/data/tscp.docx b/sw/qa/extras/ooxmlimport/data/tscp.docx
new file mode 100644
index 000000000000..3cda72de572e
--- /dev/null
+++ b/sw/qa/extras/ooxmlimport/data/tscp.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index e19d1ba4c91e..a4bb78b8d81c 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -79,6 +79,8 @@
#include <unotools/streamwrap.hxx>
#include <comphelper/propertysequence.hxx>
#include <com/sun/star/drawing/HomogenMatrix3.hpp>
+#include <com/sun/star/rdf/URI.hpp>
+#include <com/sun/star/rdf/Statement.hpp>
#include <bordertest.hxx>
@@ -2841,6 +2843,44 @@ DECLARE_OOXMLIMPORT_TEST(testIndents, "indents.docx")
} while (xParaEnum->hasMoreElements());
}
+DECLARE_OOXMLIMPORT_TEST(testTscp, "tscp.docx")
+{
+ uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
+ uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, "urn:tscp:names:baf:1.1");
+ uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(mxComponent, uno::UNO_QUERY);
+ uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
+ // This failed, no graphs had the urn:tscp:names:baf:1.1 type.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aGraphNames.getLength());
+ uno::Reference<rdf::XURI> xGraphName = aGraphNames[0];
+ uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
+
+ // No RDF statement on the first paragraph.
+ uno::Reference<rdf::XResource> xParagraph(getParagraph(1), uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xStatements = xGraph->getStatements(xParagraph, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>());
+ CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(xStatements->hasMoreElements()));
+
+ // 3 RDF statements on the second paragraph.
+ xParagraph.set(getParagraph(2), uno::UNO_QUERY);
+ std::map<OUString, OUString> aExpectedStatements = {
+ {"urn:tscp:names:baf:1.1#BusinessAuthorization", "urn:example:tscp:1"},
+ {"urn:tscp:names:baf:1.1#BusinessAuthorizationCategory", "urn:example:tscp:1:confidential"},
+ {"urn:tscp:names:baf:1.1#BusinessAuthorizationDate", "2015-11-27T11:45:00"}
+ };
+ std::map<OUString, OUString> aActualStatements;
+ xStatements = xGraph->getStatements(xParagraph, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>());
+ while (xStatements->hasMoreElements())
+ {
+ rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>();
+ aActualStatements[aStatement.Predicate->getNamespace() + aStatement.Predicate->getLocalName()] = aStatement.Object->getStringValue();
+ }
+ CPPUNIT_ASSERT(aExpectedStatements == aActualStatements);
+
+ // No RDF statement on the third paragraph.
+ xParagraph.set(getParagraph(3), uno::UNO_QUERY);
+ xStatements = xGraph->getStatements(xParagraph, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>());
+ CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(xStatements->hasMoreElements()));
+}
+
DECLARE_OOXMLIMPORT_TEST(testTdf92454, "tdf92454.docx")
{
// The first paragraph had a large indentation / left margin as inheritance