sw/CppunitTest_sw_ww8import.mk | 4 +++ sw/qa/extras/ww8import/data/tscp.doc |binary sw/qa/extras/ww8import/ww8import.cxx | 41 +++++++++++++++++++++++++++++++++++ sw/source/core/doc/rdfhelper.cxx | 19 +++++++++++++++- sw/source/filter/ww8/ww8par.cxx | 18 +++++++++++++++ 5 files changed, 81 insertions(+), 1 deletion(-)
New commits: commit b7c2e9ae95ff41570f752ca43c361b249a65da77 Author: Miklos Vajna <[email protected]> Date: Wed Dec 9 15:43:34 2015 +0100 DOC import: initialize RDF metadata before importing document properties With this, it is possible to import part of the document as RDF statements later when SwFltControlStack::SetAttrInDoc() gets an SwFltRDFMark. Previously SfxBaseModel member functions like getMetadataGraphsWithType() and addMetadataFile() failed, as they tried to find the already imported document in UCB, which failed, as the import was still in progress. To prevent that, do the same as the ODT import in XMLReader::Read(), part "RDF metadata". One trick here is the call to comphelper::OStorageHelper::GetTemporaryStorage(), which gives an empty storage. Ideally a wrapper class would be needed that works on a SotStorage, but implements embed::XStorage, but that would be only used to find that the real storage doesn't provide a manifest.rdf stream, which is always the case. So instead of writing such a wrapper, just give loadMetadataFromStorage() an empty storage, which will have the same result without writing lots of dead code. Change-Id: Id1897838b1477eee0489b706d51cb6f59898877b diff --git a/sw/CppunitTest_sw_ww8import.mk b/sw/CppunitTest_sw_ww8import.mk index 63230e4..ed28ae9 100644 --- a/sw/CppunitTest_sw_ww8import.mk +++ b/sw/CppunitTest_sw_ww8import.mk @@ -58,6 +58,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_ww8import,\ i18npool/util/i18npool \ linguistic/source/lng \ package/util/package2 \ + package/source/xstor/xstor \ sw/util/msword \ sw/util/sw \ sw/util/swd \ @@ -67,6 +68,9 @@ $(eval $(call gb_CppunitTest_use_components,sw_ww8import,\ 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 \ $(if $(filter DESKTOP,$(BUILD_TYPE)),xmlhelp/util/ucpchelp1) \ )) diff --git a/sw/qa/extras/ww8import/data/tscp.doc b/sw/qa/extras/ww8import/data/tscp.doc new file mode 100644 index 0000000..7b710fc Binary files /dev/null and b/sw/qa/extras/ww8import/data/tscp.doc differ diff --git a/sw/qa/extras/ww8import/ww8import.cxx b/sw/qa/extras/ww8import/ww8import.cxx index 7e9307b..6714b71 100644 --- a/sw/qa/extras/ww8import/ww8import.cxx +++ b/sw/qa/extras/ww8import/ww8import.cxx @@ -18,6 +18,8 @@ #include <com/sun/star/text/XTextFramesSupplier.hpp> #include <com/sun/star/text/XTextTablesSupplier.hpp> #include <com/sun/star/table/ShadowFormat.hpp> +#include <com/sun/star/rdf/URI.hpp> +#include <com/sun/star/rdf/Statement.hpp> #include <vcl/svapp.hxx> @@ -47,6 +49,45 @@ DECLARE_WW8IMPORT_TEST(testFloatingTableSectionMargins, "floating-table-section- CPPUNIT_ASSERT( abs(( pageLeft + pageWidth / 2 ) - ( tableLeft + tableWidth / 2 )) < 20 ); } +DECLARE_WW8IMPORT_TEST(testTscp, "tscp.doc") +{ + 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_WW8IMPORT_TEST(testN757910, "n757910.doc") { // The internal margin was larger than 0.28cm diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 85557ce..56a819b 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -144,6 +144,8 @@ using namespace nsHdFtFlags; #include <comphelper/sequenceashashmap.hxx> #include <oox/ole/vbaproject.hxx> #include <oox/ole/olestorage.hxx> +#include <comphelper/storagehelper.hxx> +#include <sfx2/DocumentMetadataAccess.hxx> //#define VT_EMPTY 0 //#define VT_I4 3 @@ -4904,7 +4906,23 @@ sal_uLong SwWW8ImplReader::CoreLoad(WW8Glossary *pGloss) m_rDoc.SetDocumentType( SwDoc::DOCTYPE_MSWORD ); if (m_bNewDoc && m_pStg && !pGloss) + { + // Initialize RDF metadata, to be able to add statements during the import. + try + { + uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW); + uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext()); + uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage(); + const uno::Reference<rdf::XURI> xBaseURI(sfx2::createBaseURI(xComponentContext, xStorage, m_sBaseURL)); + uno::Reference<task::XInteractionHandler> xHandler; + xDocumentMetadataAccess->loadMetadataFromStorage(xStorage, xBaseURI, xHandler); + } + catch (const uno::Exception& rException) + { + SAL_WARN("sw.ww8", "SwWW8ImplReader::CoreLoad: failed to initialize RDF metadata: " << rException.Message); + } ReadDocInfo(); + } ::ww8::WW8FibData * pFibData = new ::ww8::WW8FibData(); commit 6e132dea8c33d106793a9e43c2c57406ae221a30 Author: Miklos Vajna <[email protected]> Date: Wed Dec 9 15:01:46 2015 +0100 sw: implement addition of statements in SwRDFHelper With this, the only thing that blocks the DOC import to handle smart tags is the lack of RDF metadata initialization in the filter. Change-Id: I33ab74c7d6ceaac42cc94fdf0b1dfcb0eaf61ab4 diff --git a/sw/source/core/doc/rdfhelper.cxx b/sw/source/core/doc/rdfhelper.cxx index 25acac9..70a885c 100644 --- a/sw/source/core/doc/rdfhelper.cxx +++ b/sw/source/core/doc/rdfhelper.cxx @@ -48,8 +48,25 @@ std::map<OUString, OUString> SwRDFHelper::getTextNodeStatements(const OUString& return aRet; } -void SwRDFHelper::addTextNodeStatement(const OUString& /*rType*/, const OUString& /*rPath*/, SwTextNode& /*rTextNode*/, const OUString& /*rKey*/, const OUString& /*rValue*/) +void SwRDFHelper::addTextNodeStatement(const OUString& rType, const OUString& rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rValue) { + 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); + uno::Reference<rdf::XURI> xGraphName; + if (aGraphNames.hasElements()) + xGraphName = aGraphNames[0]; + else + { + uno::Sequence< uno::Reference<rdf::XURI> > xTypes = { xType }; + xGraphName = xDocumentMetadataAccess->addMetadataFile(rPath, xTypes); + } + uno::Reference<rdf::XNamedGraph> xGraph = xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName); + uno::Reference<rdf::XResource> xSubject(SwXParagraph::CreateXParagraph(*rTextNode.GetDoc(), &rTextNode), uno::UNO_QUERY); + uno::Reference<rdf::XURI> xKey = rdf::URI::create(xComponentContext, rKey); + uno::Reference<rdf::XURI> xValue = rdf::URI::create(xComponentContext, rValue); + xGraph->addStatement(xSubject, xKey, xValue); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
