[Libreoffice-commits] core.git: 2 commits - sw/CppunitTest_sw_filters_test.mk sw/CppunitTest_sw_globalfilter.mk sw/inc sw/Library_sw.mk sw/ooxmlexport_setup.mk sw/qa sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Wed Dec 2 08:17:43 PST 2015
dev/null |binary
sw/CppunitTest_sw_filters_test.mk | 1
sw/CppunitTest_sw_globalfilter.mk | 1
sw/Library_sw.mk | 1
sw/inc/rdfhelper.hxx | 31 ++++++++++++++++
sw/ooxmlexport_setup.mk | 2 +
sw/qa/extras/ooxmlexport/data/tscp.docx |binary
sw/qa/extras/ooxmlexport/ooxmlexport5.cxx | 40 +++++++++++++++++++++
sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 40 ---------------------
sw/source/core/doc/rdfhelper.cxx | 51 +++++++++++++++++++++++++++
sw/source/filter/ww8/docxattributeoutput.cxx | 20 ++++++++++
11 files changed, 147 insertions(+), 40 deletions(-)
New commits:
commit 08e5fc257fa8c106be34bb034ebe5e00b6fcf711
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Wed Dec 2 17:00:17 2015 +0100
DOCX export: handle <w:smartTag>
A Writer document can have multiple arbitrary RDF graphs, handle the following
subset:
- instead of handling all graphs, have a whitelist, look at the TSCP graph the
DOCX importer creates
- look for (paragraph, key, value) statements and export those
Change-Id: I142c24fb4c8140bde5fc1efad2932886de167b90
diff --git a/sw/CppunitTest_sw_filters_test.mk b/sw/CppunitTest_sw_filters_test.mk
index 94b91c3..80d9fce 100644
--- a/sw/CppunitTest_sw_filters_test.mk
+++ b/sw/CppunitTest_sw_filters_test.mk
@@ -80,6 +80,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_filters_test,\
ucb/source/core/ucb1 \
ucb/source/ucp/file/ucpfile1 \
unotools/util/utl \
+ unoxml/source/rdf/unordf \
unoxml/source/service/unoxml \
writerfilter/util/writerfilter \
$(if $(filter DESKTOP,$(BUILD_TYPE)),xmlhelp/util/ucpchelp1) \
diff --git a/sw/CppunitTest_sw_globalfilter.mk b/sw/CppunitTest_sw_globalfilter.mk
index c6fa6cc..6650266 100644
--- a/sw/CppunitTest_sw_globalfilter.mk
+++ b/sw/CppunitTest_sw_globalfilter.mk
@@ -78,6 +78,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_globalfilter,\
ucb/source/core/ucb1 \
ucb/source/ucp/file/ucpfile1 \
unotools/util/utl \
+ unoxml/source/rdf/unordf \
unoxml/source/service/unoxml \
uui/util/uui \
$(if $(filter DESKTOP,$(BUILD_TYPE)),xmlhelp/util/ucpchelp1) \
diff --git a/sw/ooxmlexport_setup.mk b/sw/ooxmlexport_setup.mk
index a3a2182..c8cfc9f 100644
--- a/sw/ooxmlexport_setup.mk
+++ b/sw/ooxmlexport_setup.mk
@@ -58,7 +58,9 @@ define sw_ooxmlexport_components
toolkit/util/tk \
ucb/source/core/ucb1 \
ucb/source/ucp/file/ucpfile1 \
+ ucb/source/ucp/tdoc/ucptdoc1 \
unotools/util/utl \
+ unoxml/source/rdf/unordf \
unoxml/source/service/unoxml \
uui/util/uui \
writerfilter/util/writerfilter \
diff --git a/sw/qa/extras/ooxmlimport/data/tscp.docx b/sw/qa/extras/ooxmlexport/data/tscp.docx
similarity index 100%
rename from sw/qa/extras/ooxmlimport/data/tscp.docx
rename to sw/qa/extras/ooxmlexport/data/tscp.docx
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index b4b8896..c0979db 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -49,6 +49,8 @@
#include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
#include <com/sun/star/drawing/Hatch.hpp>
+#include <com/sun/star/rdf/URI.hpp>
+#include <com/sun/star/rdf/Statement.hpp>
#include <string>
@@ -85,6 +87,44 @@ DECLARE_OOXMLEXPORT_TEST(testFDO76248, "FDO76248.docx")
assertXPath(pXmlDoc, "//a:graphicData[not(*)]", 0);
}
+DECLARE_OOXMLEXPORT_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_OOXMLEXPORT_TEST(testfdo76589 , "fdo76589.docx")
{
/* Numbered list was not preserve after RT.
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index a4bb78b..e19d1ba 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -79,8 +79,6 @@
#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>
@@ -2843,44 +2841,6 @@ 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
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index c219108..e273094 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -36,6 +36,7 @@
#include "unoframe.hxx"
#include "unodraw.hxx"
#include "textboxhelper.hxx"
+#include "rdfhelper.hxx"
#include "wrtww8.hxx"
#include <comphelper/random.hxx>
@@ -1034,6 +1035,25 @@ void DocxAttributeOutput::EndParagraphProperties(const SfxItemSet& rParagraphMar
m_pSerializer->endElementNS( XML_w, XML_pPr );
+ // RDF metadata for this text node.
+ SwTextNode* pTextNode = m_rExport.m_pCurPam->GetNode().GetTextNode();
+ std::map<OUString, OUString> aStatements = SwRDFHelper::getTextNodeStatements("urn:tscp:names:baf:1.1", *pTextNode);
+ if (!aStatements.empty())
+ {
+ m_pSerializer->startElementNS(XML_w, XML_smartTag,
+ FSNS(XML_w, XML_uri), "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ FSNS(XML_w, XML_element), "RDF",
+ FSEND);
+ m_pSerializer->startElementNS(XML_w, XML_smartTagPr, FSEND);
+ for (const std::pair<OUString, OUString>& rStatement : aStatements)
+ m_pSerializer->singleElementNS(XML_w, XML_attr,
+ FSNS(XML_w, XML_name), rStatement.first.toUtf8(),
+ FSNS(XML_w, XML_val), rStatement.second.toUtf8(),
+ FSEND);
+ m_pSerializer->endElementNS(XML_w, XML_smartTagPr);
+ m_pSerializer->endElementNS(XML_w, XML_smartTag);
+ }
+
if ( m_nColBreakStatus == COLBRK_WRITE )
{
m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
commit 5402ac4e006b9aac6944f7fb9f1a9f256a754472
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Wed Dec 2 14:09:42 2015 +0100
sw: initial SwRDFHelper
The purpose of this class is to provide access to the subset of the RDF
metadata that's interesting for core code and for internal filters.
Change-Id: Ibecba302dd839b537a36b9f7a15f012c6ea26869
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 789a777..f9725be 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -214,6 +214,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
sw/source/core/doc/notxtfrm \
sw/source/core/doc/number \
sw/source/core/doc/poolfmt \
+ sw/source/core/doc/rdfhelper \
sw/source/core/doc/sortopt \
sw/source/core/doc/swserv \
sw/source/core/doc/swstylemanager \
diff --git a/sw/inc/rdfhelper.hxx b/sw/inc/rdfhelper.hxx
new file mode 100644
index 0000000..d9787cb
--- /dev/null
+++ b/sw/inc/rdfhelper.hxx
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SW_INC_RDFHELPER_HXX
+#define INCLUDED_SW_INC_RDFHELPER_HXX
+
+#include <map>
+
+#include <rtl/ustring.hxx>
+
+#include <swdllapi.h>
+
+class SwTextNode;
+
+/// Provides access to RDF metadata on core objects.
+class SW_DLLPUBLIC SwRDFHelper
+{
+public:
+ /// Gets all (rTextNode, key, value) statements in RDF graphs of type rType.
+ static std::map<OUString, OUString> getTextNodeStatements(const OUString& rType, SwTextNode& rTextNode);
+};
+
+#endif // INCLUDED_SW_INC_RDFHELPER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/rdfhelper.cxx b/sw/source/core/doc/rdfhelper.cxx
new file mode 100644
index 0000000..f476bf7
--- /dev/null
+++ b/sw/source/core/doc/rdfhelper.cxx
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <rdfhelper.hxx>
+
+#include <com/sun/star/rdf/Statement.hpp>
+#include <com/sun/star/rdf/URI.hpp>
+#include <com/sun/star/rdf/XDocumentMetadataAccess.hpp>
+
+#include <comphelper/processfactory.hxx>
+
+#include <doc.hxx>
+#include <docsh.hxx>
+#include <ndtxt.hxx>
+#include <unoparagraph.hxx>
+
+using namespace com::sun::star;
+
+std::map<OUString, OUString> SwRDFHelper::getTextNodeStatements(const OUString& rType, SwTextNode& rTextNode)
+{
+ std::map<OUString, OUString> aRet;
+
+ uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
+ uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType);
+ uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(rTextNode.GetDoc()->GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
+ uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
+ if (!aGraphNames.hasElements())
+ return aRet;
+
+ uno::Reference<rdf::XResource> xTextNode(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), uno::UNO_QUERY);
+ for (const uno::Reference<rdf::XURI>& xGraphName : aGraphNames)
+ {
+ uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
+ uno::Reference<container::XEnumeration> xStatements = xGraph->getStatements(xTextNode, uno::Reference<rdf::XURI>(), uno::Reference<rdf::XURI>());
+ while (xStatements->hasMoreElements())
+ {
+ rdf::Statement aStatement = xStatements->nextElement().get<rdf::Statement>();
+ aRet[aStatement.Predicate->getStringValue()] = aStatement.Object->getStringValue();
+ }
+ }
+
+ return aRet;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list