From 9fed38e7d84614ba7000a19ad868af15b63ec720 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Mon, 15 Mar 2010 11:34:42 +0100 Subject: [PATCH] odfmetadata4: #i110033#: API change: remove rdfs:label statements for RDFa. css.rdf.XDocumentRepository: method getStatementRDFa() also returns a bool. librdf_repository: setStatementRDFa() no longer generates the rdfs:label statement. getStatementRDFa() no longer handles the rdfs:label statement. add a set to store elements with xhtml:content. RDFaExportHelper: adapt export to new getStatementRDFa() and lack of rdfs:label statement. --- .../complex/DocumentMetadataAccessTest.java | 125 +++++++++--------- xmloff/inc/RDFaExportHelper.hxx | 2 - xmloff/source/core/RDFaExportHelper.cxx | 61 +++------ 3 files changed, 87 insertions(+), 101 deletions(-) diff --git a/sfx2/qa/complex/DocumentMetadataAccessTest.java b/sfx2/qa/complex/DocumentMetadataAccessTest.java index 05dc523d6f8b..a61280c45fe5 100644 --- a/sfx2/qa/complex/DocumentMetadataAccessTest.java +++ b/sfx2/qa/complex/DocumentMetadataAccessTest.java @@ -42,6 +42,7 @@ import com.sun.star.lang.WrappedTargetException; import com.sun.star.lang.WrappedTargetRuntimeException; import com.sun.star.beans.XPropertySet; import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.Pair; import com.sun.star.beans.StringPair; import com.sun.star.container.XEnumerationAccess; import com.sun.star.container.XEnumeration; @@ -689,23 +690,25 @@ public class DocumentMetadataAccessTest extends ComplexTestCase log.println("Checking RDFa in loaded test document..."); XMetadatable xPara; - Statement[] stmts; + Pair result; Statement x_FooBarLit1 = new Statement(foo, bar, mkLit("1"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 1", - eq(stmts, new Statement[] { + !result.Second && + eq(result.First, new Statement[] { x_FooBarLit1 })); Statement x_FooBarLit2 = new Statement(foo, bar, mkLit("2"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 2", - eq(stmts, new Statement[] { + !result.Second && + eq(result.First, new Statement[] { x_FooBarLit2 })); @@ -713,37 +716,40 @@ public class DocumentMetadataAccessTest extends ComplexTestCase new Statement(blank1, bar, mkLit("3"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 3", - eq(stmts, new Statement[] { + !result.Second && + eq(result.First, new Statement[] { x_BlankBarLit3 })); XBlankNode b3 = (XBlankNode) UnoRuntime.queryInterface( - XBlankNode.class, stmts[0].Subject); + XBlankNode.class, result.First[0].Subject); Statement x_BlankBarLit4 = new Statement(blank2, bar, mkLit("4"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 4", - eq(stmts, new Statement[] { + !result.Second && + eq(result.First, new Statement[] { x_BlankBarLit4 })); XBlankNode b4 = (XBlankNode) UnoRuntime.queryInterface( - XBlankNode.class, stmts[0].Subject); + XBlankNode.class, result.First[0].Subject); Statement x_BlankBarLit5 = new Statement(blank1, bar, mkLit("5"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 5", - eq(stmts, new Statement[] { + !result.Second && + eq(result.First, new Statement[] { x_BlankBarLit5 })); XBlankNode b5 = (XBlankNode) UnoRuntime.queryInterface( - XBlankNode.class, stmts[0].Subject); + XBlankNode.class, result.First[0].Subject); assure("RDFa: 3 != 4", !b3.getStringValue().equals(b4.getStringValue())); @@ -754,9 +760,10 @@ public class DocumentMetadataAccessTest extends ComplexTestCase Statement x_FooBazLit6 = new Statement(foo, baz, mkLit("6"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 6", - eq(stmts, new Statement[] { + !result.Second && + eq(result.First, new Statement[] { x_FooBarLit6, x_FooBazLit6 })); @@ -765,9 +772,10 @@ public class DocumentMetadataAccessTest extends ComplexTestCase Statement x_FooFooLit7 = new Statement(foo, foo, mkLit("7"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 7", - eq(stmts, new Statement[] { + !result.Second && + eq(result.First, new Statement[] { x_FooBarLit7, x_FooBazLit7, x_FooFooLit7 })); @@ -776,43 +784,41 @@ public class DocumentMetadataAccessTest extends ComplexTestCase Statement x_FooBarLit = new Statement(foo, bar, lit, null); Statement x_FooBarLittype = new Statement(foo, bar, lit_type, null); - Statement x_FooLabelLit8 = - new Statement(foo, rdfs_label, mkLit("8"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 8", - eq(stmts, new Statement[] { - x_FooBarLit, x_FooLabelLit8 + result.Second && + eq(result.First, new Statement[] { + x_FooBarLit })); - Statement x_FooLabelLit9 = - new Statement(foo, rdfs_label, mkLit("9"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 9", - eq(stmts, new Statement[] { - x_FooBarLit, x_FooLabelLit9 + result.Second && + eq(result.First, new Statement[] { + x_FooBarLit })); - Statement x_FooLabelLit10 = - new Statement(foo, rdfs_label, mkLit("10"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 10", - eq(stmts, new Statement[] { - x_FooBarLittype, x_FooLabelLit10 + result.Second && + eq(result.First, new Statement[] { + x_FooBarLittype })); Statement x_FooBarLit11 = new Statement(foo, bar, mkLit("11", bar), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 11", - eq(stmts, new Statement[] { + !result.Second && + eq(result.First, new Statement[] { x_FooBarLit11 })); @@ -821,66 +827,67 @@ public class DocumentMetadataAccessTest extends ComplexTestCase new Statement(xFile, bar, mkLit("12"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 12", - eq(stmts, new Statement[] { + !result.Second && + eq(result.First, new Statement[] { x_FileBarLit12 })); - Statement x_FooLabelLit13 = - new Statement(foo, rdfs_label, mkLit("13"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 13", - eq(stmts, new Statement[] { - x_FooBarLit, x_FooLabelLit13 + result.Second && + eq(result.First, new Statement[] { + x_FooBarLit })); Statement x_FooLabelLit14 = new Statement(foo, rdfs_label, mkLit("14"), null); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); + result = xRep.getStatementRDFa(xPara); assure("RDFa: 14", - eq(stmts, new Statement[] { - x_FooBarLit, x_FooLabelLit14 + result.Second && + eq(result.First, new Statement[] { + x_FooBarLit })); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); - assure("RDFa: 15", eq(stmts, new Statement[] { } )); + result = xRep.getStatementRDFa(xPara); + assure("RDFa: 15", eq(result.First, new Statement[] { } )); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); - assure("RDFa: 16", eq(stmts, new Statement[] { } )); + result = xRep.getStatementRDFa(xPara); + assure("RDFa: 16", eq(result.First, new Statement[] { } )); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); - assure("RDFa: 17", eq(stmts, new Statement[] { } )); + result = xRep.getStatementRDFa(xPara); + assure("RDFa: 17", eq(result.First, new Statement[] { } )); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); - assure("RDFa: 18", eq(stmts, new Statement[] { } )); + result = xRep.getStatementRDFa(xPara); + assure("RDFa: 18", eq(result.First, new Statement[] { } )); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); - assure("RDFa: 19", eq(stmts, new Statement[] { } )); + result = xRep.getStatementRDFa(xPara); + assure("RDFa: 19", eq(result.First, new Statement[] { } )); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); - assure("RDFa: 20", eq(stmts, new Statement[] { } )); + result = xRep.getStatementRDFa(xPara); + assure("RDFa: 20", eq(result.First, new Statement[] { } )); xPara = (XMetadatable) UnoRuntime.queryInterface( XMetadatable.class, xEnum.nextElement()); - stmts = xRep.getStatementRDFa(xPara); - assure("RDFa: 21", eq(stmts, new Statement[] { } )); + result = xRep.getStatementRDFa(xPara); + assure("RDFa: 21", eq(result.First, new Statement[] { } )); log.println("...done"); diff --git a/xmloff/inc/RDFaExportHelper.hxx b/xmloff/inc/RDFaExportHelper.hxx index 9dd23e230e01..f8e991060eea 100644 --- a/xmloff/inc/RDFaExportHelper.hxx +++ b/xmloff/inc/RDFaExportHelper.hxx @@ -53,8 +53,6 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::rdf::XDocumentRepository> m_xRepository; - ::rtl::OUString m_RDFsLabel; - typedef ::std::map< ::rtl::OUString, ::rtl::OUString > BlankNodeMap_t; diff --git a/xmloff/source/core/RDFaExportHelper.cxx b/xmloff/source/core/RDFaExportHelper.cxx index 6e3129f48d71..593e2d1f29e6 100644 --- a/xmloff/source/core/RDFaExportHelper.cxx +++ b/xmloff/source/core/RDFaExportHelper.cxx @@ -95,11 +95,6 @@ RDFaExportHelper::RDFaExportHelper(SvXMLExport & i_rExport) OSL_ENSURE(xRS.is(), "AddRDFa: model is no rdf::XRepositorySupplier"); if (!xRS.is()) throw uno::RuntimeException(); m_xRepository.set(xRS->getRDFRepository(), uno::UNO_QUERY_THROW); - - const uno::Reference xLabel( - rdf::URI::createKnown(m_rExport.GetComponentContext(), - rdf::URIs::RDFS_LABEL)); - m_RDFsLabel = xLabel->getStringValue(); } ::rtl::OUString @@ -128,19 +123,21 @@ RDFaExportHelper::AddRDFa( { try { - uno::Sequence stmts( - m_xRepository->getStatementRDFa(i_xMetadatable) ); + beans::Pair< uno::Sequence, sal_Bool > const + RDFaResult( m_xRepository->getStatementRDFa(i_xMetadatable) ); - if (0 == stmts.getLength()) + uno::Sequence const & rStatements( RDFaResult.First ); + + if (0 == rStatements.getLength()) { return; // no RDFa } // all stmts have the same subject, so we only handle first one - const uno::Reference xSubjectURI(stmts[0].Subject, - uno::UNO_QUERY); - const uno::Reference xSubjectBNode(stmts[0].Subject, + const uno::Reference xSubjectURI(rStatements[0].Subject, uno::UNO_QUERY); + const uno::Reference xSubjectBNode( + rStatements[0].Subject, uno::UNO_QUERY); if (!xSubjectURI.is() && !xSubjectBNode.is()) { throw uno::RuntimeException(); @@ -154,47 +151,31 @@ RDFaExportHelper::AddRDFa( .makeStringAndClear() ); - rdf::Statement* const iter - ( ::std::partition( ::comphelper::stl_begin(stmts), - ::comphelper::stl_end(stmts), - ::boost::bind(&::rtl::OUString::equals, m_RDFsLabel, - ::boost::bind(&rdf::XNode::getStringValue, - ::boost::bind(&rdf::Statement::Predicate, _1))) ) ); - - if (iter != ::comphelper::stl_end(stmts)) + const uno::Reference xContent( + rStatements[0].Object, uno::UNO_QUERY_THROW ); + const uno::Reference xDatatype(xContent->getDatatype()); + if (xDatatype.is()) { - // from iter to end, all stmts should have same object - const uno::Reference xContent( - (*iter).Object, uno::UNO_QUERY_THROW ); - const uno::Reference xDatatype(xContent->getDatatype()); - if (xDatatype.is()) - { - const ::rtl::OUString datatype( - makeCURIE(&m_rExport, xDatatype) ); - m_rExport.AddAttribute(XML_NAMESPACE_XHTML, - token::XML_DATATYPE, datatype); - } - if (iter != ::comphelper::stl_begin(stmts)) // there is rdfs:label - { - m_rExport.AddAttribute(XML_NAMESPACE_XHTML, token::XML_CONTENT, - xContent->getValue()); - } + const ::rtl::OUString datatype( + makeCURIE(&m_rExport, xDatatype) ); + m_rExport.AddAttribute(XML_NAMESPACE_XHTML, + token::XML_DATATYPE, datatype); } - else + if (RDFaResult.Second) // there is xhtml:content { - OSL_ENSURE(false,"invalid RDFa: every property is rdfs:label"); - return; + m_rExport.AddAttribute(XML_NAMESPACE_XHTML, token::XML_CONTENT, + xContent->getValue()); } ::rtl::OUStringBuffer property; ::comphelper::intersperse( ::boost::make_transform_iterator( - iter, // omit RDFsLabel predicates! + ::comphelper::stl_begin(rStatements), ::boost::bind(&makeCURIE, &m_rExport, ::boost::bind(&rdf::Statement::Predicate, _1))), // argh, this must be the same type :( ::boost::make_transform_iterator( - ::comphelper::stl_end(stmts), + ::comphelper::stl_end(rStatements), ::boost::bind(&makeCURIE, &m_rExport, ::boost::bind(&rdf::Statement::Predicate, _1))), ::comphelper::OUStringBufferAppender(property),