summaryrefslogtreecommitdiff
path: root/writerfilter/source/dmapper/SmartTagHandler.cxx
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 /writerfilter/source/dmapper/SmartTagHandler.cxx
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 'writerfilter/source/dmapper/SmartTagHandler.cxx')
-rw-r--r--writerfilter/source/dmapper/SmartTagHandler.cxx62
1 files changed, 60 insertions, 2 deletions
diff --git a/writerfilter/source/dmapper/SmartTagHandler.cxx b/writerfilter/source/dmapper/SmartTagHandler.cxx
index 7c44cde2d544..dc9f094e4917 100644
--- a/writerfilter/source/dmapper/SmartTagHandler.cxx
+++ b/writerfilter/source/dmapper/SmartTagHandler.cxx
@@ -8,8 +8,22 @@
*/
#include <SmartTagHandler.hxx>
+
+#include <com/sun/star/rdf/URI.hpp>
+
#include <ooxml/resourceids.hxx>
+namespace
+{
+OUString lcl_getTypePath(const OUString& rType)
+{
+ OUString aRet;
+ if (rType == "urn:tscp:names:baf:1.1")
+ aRet = "tscp/baf.rdf";
+ return aRet;
+}
+}
+
namespace writerfilter
{
namespace dmapper
@@ -17,8 +31,10 @@ namespace dmapper
using namespace ::com::sun::star;
-SmartTagHandler::SmartTagHandler()
- : LoggedProperties("SmartTagHandler")
+SmartTagHandler::SmartTagHandler(const uno::Reference<uno::XComponentContext>& xComponentContext, const uno::Reference<text::XTextDocument>& xTextDocument)
+ : LoggedProperties("SmartTagHandler"),
+ m_xComponentContext(xComponentContext),
+ m_xDocumentMetadataAccess(xTextDocument, uno::UNO_QUERY)
{
}
@@ -31,8 +47,11 @@ void SmartTagHandler::lcl_attribute(Id nName, Value& rValue)
switch (nName)
{
case NS_ooxml::LN_CT_Attr_name:
+ m_aAttributes.emplace_back(rValue.getString(), OUString());
break;
case NS_ooxml::LN_CT_Attr_val:
+ if (!m_aAttributes.empty())
+ m_aAttributes.back().second = rValue.getString();
break;
default:
SAL_WARN("writerfilter", "SmartTagHandler::lcl_attribute: unhandled attribute " << nName << " (string value: '"<<rValue.getString()<<"')");
@@ -64,6 +83,45 @@ void SmartTagHandler::setElement(const OUString& rElement)
m_aElement = rElement;
}
+void SmartTagHandler::handle(const uno::Reference<text::XTextRange>& xParagraph)
+{
+ if (!m_aURI.isEmpty() && !m_aElement.isEmpty() && !m_aAttributes.empty())
+ {
+ uno::Reference<rdf::XResource> xSubject(xParagraph, uno::UNO_QUERY);
+
+ for (const std::pair<OUString, OUString>& rAttribute : m_aAttributes)
+ {
+ sal_Int32 nIndex = rAttribute.first.indexOf('#');
+ if (nIndex == -1)
+ continue;
+
+ OUString aTypeNS = rAttribute.first.copy(0, nIndex);
+ OUString aMetadataFilePath = lcl_getTypePath(aTypeNS);
+ if (aMetadataFilePath.isEmpty())
+ continue;
+
+ uno::Reference<rdf::XURI> xType = rdf::URI::create(m_xComponentContext, aTypeNS);
+ uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = m_xDocumentMetadataAccess->getMetadataGraphsWithType(xType);
+ uno::Reference<rdf::XURI> xGraphName;
+ if (aGraphNames.hasElements())
+ xGraphName = aGraphNames[0];
+ else
+ {
+ uno::Sequence< uno::Reference<rdf::XURI> > xTypes = { xType };
+ xGraphName = m_xDocumentMetadataAccess->addMetadataFile(aMetadataFilePath, xTypes);
+ }
+ uno::Reference<rdf::XNamedGraph> xGraph = m_xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName);
+ uno::Reference<rdf::XURI> xKey = rdf::URI::create(m_xComponentContext, rAttribute.first);
+ uno::Reference<rdf::XURI> xValue = rdf::URI::create(m_xComponentContext, rAttribute.second);
+ xGraph->addStatement(xSubject, xKey, xValue);
+ }
+
+ m_aURI.clear();
+ m_aElement.clear();
+ m_aAttributes.clear();
+ }
+}
+
} // namespace dmapper
} // namespace writerfilter