diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-11-29 20:23:13 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-11-30 06:52:09 +0100 |
commit | dda4867a0b5a2d29d8a01a3656e0c8dac7626d2f (patch) | |
tree | 0f0b2b2a41b7e7be7413407f37709cecb8a78e84 /writerfilter | |
parent | 98d8adc5b377039d5dee0d5046ece721010a960c (diff) |
tdf#152289: implement external glossary relations roundtrip
Change-Id: I20f4439abfbf73485734fd8373fffb2916d390f0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143470
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/inc/ooxml/OOXMLDocument.hxx | 3 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLDocumentImpl.cxx | 163 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLDocumentImpl.hxx | 4 |
3 files changed, 85 insertions, 85 deletions
diff --git a/writerfilter/inc/ooxml/OOXMLDocument.hxx b/writerfilter/inc/ooxml/OOXMLDocument.hxx index 8bf1502848ec..1179be43c8ac 100644 --- a/writerfilter/inc/ooxml/OOXMLDocument.hxx +++ b/writerfilter/inc/ooxml/OOXMLDocument.hxx @@ -19,6 +19,7 @@ #pragma once #include <sal/types.h> +#include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/uno/XComponentContext.hpp> @@ -219,7 +220,7 @@ public: virtual void popShapeContext() = 0; virtual css::uno::Reference<css::xml::dom::XDocument> getThemeDom( ) = 0; virtual css::uno::Reference<css::xml::dom::XDocument> getGlossaryDocDom( ) = 0; - virtual css::uno::Sequence<css::uno::Sequence< css::uno::Any> > getGlossaryDomList() = 0; + virtual css::uno::Sequence<css::uno::Sequence< css::beans::NamedValue> > getGlossaryDomList() = 0; virtual css::uno::Sequence<css::uno::Reference<css::xml::dom::XDocument> > getCustomXmlDomList( ) = 0; virtual css::uno::Sequence<css::uno::Reference<css::xml::dom::XDocument> > getCustomXmlDomPropsList( ) = 0; virtual css::uno::Sequence<css::beans::PropertyValue > getEmbeddingsList() = 0; diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx index 174549ed5e4b..fdfc1f1ed0ab 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx @@ -37,6 +37,7 @@ #include <svx/dialmgr.hxx> #include <svx/strings.hrc> #include <comphelper/sequence.hxx> +#include <comphelper/namedvaluecollection.hxx> #include <cppuhelper/exc_hlp.hxx> #include <unotools/mediadescriptor.hxx> @@ -600,17 +601,32 @@ void OOXMLDocumentImpl::resolveCustomXmlStream(Stream & rStream) mxCustomXmlDomPropsList = comphelper::containerToSequence(aCustomXmlDomPropsList); } -void OOXMLDocumentImpl::resolveGlossaryStream(Stream & /*rStream*/) +namespace { - static const char sSettingsType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"; - static const char sStylesType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"; - static const char sFonttableType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"; - static const char sWebSettings[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"; - static const char sSettingsTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/settings"; - static const char sStylesTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/styles"; - static const char sFonttableTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/fontTable"; - static const char sWebSettingsStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/webSettings"; +const char sSettingsType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"; +const char sStylesType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"; +const char sFonttableType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"; +const char sWebSettings[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"; +const char sSettingsTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/settings"; +const char sStylesTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/styles"; +const char sFonttableTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/fontTable"; +const char sWebSettingsStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/webSettings"; + +constexpr OUStringLiteral sId = u"Id"; +constexpr OUStringLiteral sType = u"Type"; +constexpr OUStringLiteral sTarget = u"Target"; +constexpr OUStringLiteral sTargetMode = u"TargetMode"; +constexpr OUStringLiteral sContentType = u"_contentType"; +constexpr OUStringLiteral sRelDom = u"_relDom"; +constexpr OUStringLiteral sSettingsContentType = u"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"; +constexpr OUStringLiteral sStylesContentType = u"application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"; +constexpr OUStringLiteral sWebsettingsContentType = u"application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"; +constexpr OUStringLiteral sFonttableContentType = u"application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"; +} +// See DocxExport::WriteGlossary +void OOXMLDocumentImpl::resolveGlossaryStream(Stream & /*rStream*/) +{ OOXMLStream::Pointer_t pStream; try { @@ -629,80 +645,63 @@ void OOXMLDocumentImpl::resolveGlossaryStream(Stream & /*rStream*/) const uno::Sequence< uno::Sequence< beans::StringPair > >aSeqs = xRelationshipAccess->getAllRelationships(); - std::vector< uno::Sequence<uno::Any> > aGlossaryDomList; + std::vector< uno::Sequence<beans::NamedValue> > aGlossaryDomList; for (const uno::Sequence< beans::StringPair >& aSeq : aSeqs) { - OOXMLStream::Pointer_t gStream; - //Follows following aSeq[0] is Id, aSeq[1] is Type, aSeq[2] is Target - if (aSeq.getLength() < 3) - { - SAL_WARN("writerfilter.ooxml", "too short sequence"); - continue; - } - - OUString gId(aSeq[0].Second); - OUString gType(aSeq[1].Second); - OUString gTarget(aSeq[2].Second); - OUString contentType; - - OOXMLStream::StreamType_t nType(OOXMLStream::UNKNOWN); - bool bFound = true; - if(gType == sSettingsType || - gType == sSettingsTypeStrict) - { - nType = OOXMLStream::SETTINGS; - contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"; - } - else if(gType == sStylesType || - gType == sStylesTypeStrict) - { - nType = OOXMLStream::STYLES; - contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"; - } - else if(gType == sWebSettings || - gType == sWebSettingsStrict) - { - nType = OOXMLStream::WEBSETTINGS; - contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"; - } - else if(gType == sFonttableType || - gType == sFonttableTypeStrict) - { - nType = OOXMLStream::FONTTABLE; - contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"; - } - else - { - bFound = false; - //"Unhandled content-type while grab bagging Glossary Folder"); - } - - if (bFound) - { - uno::Reference<xml::dom::XDocument> xDom; - try - { - gStream = OOXMLDocumentFactory::createStream(pStream, nType); - uno::Reference<io::XInputStream> xInputStream = gStream->getDocumentStream(); - uno::Reference<uno::XComponentContext> xContext(pStream->getContext()); - uno::Reference<xml::dom::XDocumentBuilder> xDomBuilder(xml::dom::DocumentBuilder::create(xContext)); - xDom = xDomBuilder->parse(xInputStream); - } - catch (uno::Exception const&) - { - TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while " - "parsing stream of Type" << nType); - return; - } - - if (xDom.is()) - { - uno::Sequence< uno::Any > glossaryTuple{ uno::Any(xDom), uno::Any(gId), - uno::Any(gType), uno::Any(gTarget), - uno::Any(contentType) }; - aGlossaryDomList.push_back(glossaryTuple); - } - } + comphelper::NamedValueCollection aRelDefinition; + for (const auto& [name, value] : aSeq) + aRelDefinition.put(name, value); + + const OUString gType = aRelDefinition.getOrDefault(sType, OUString{}); + OOXMLStream::StreamType_t nType(OOXMLStream::UNKNOWN); + if (gType == sSettingsType || gType == sSettingsTypeStrict) + { + nType = OOXMLStream::SETTINGS; + aRelDefinition.put(sContentType, sSettingsContentType); + } + else if (gType == sStylesType || gType == sStylesTypeStrict) + { + nType = OOXMLStream::STYLES; + aRelDefinition.put(sContentType, sStylesContentType); + } + else if (gType == sWebSettings || gType == sWebSettingsStrict) + { + nType = OOXMLStream::WEBSETTINGS; + aRelDefinition.put(sContentType, sWebsettingsContentType); + } + else if (gType == sFonttableType || gType == sFonttableTypeStrict) + { + nType = OOXMLStream::FONTTABLE; + aRelDefinition.put(sContentType, sFonttableContentType); + } + else if (aRelDefinition.getOrDefault(sTargetMode, OUString{}) != "External") + { + // Some internal relation, but we don't create a DOM for it here yet? + SAL_WARN("writerfilter.ooxml", "Unknown type of glossary internal relation: " + "Id=\"" + aRelDefinition.getOrDefault<OUString>(sId, {}) + "\" " + "Type=\"" + gType + "\" " + "Target=\"" + aRelDefinition.getOrDefault<OUString>(sTarget, {}) + "\""); + continue; + } + + if (nType != OOXMLStream::UNKNOWN) + { + try + { + auto gStream = OOXMLDocumentFactory::createStream(pStream, nType); + uno::Reference xInputStream = gStream->getDocumentStream(); + uno::Reference xContext(pStream->getContext()); + uno::Reference xDomBuilder(xml::dom::DocumentBuilder::create(xContext)); + uno::Reference xDom = xDomBuilder->parse(xInputStream); + aRelDefinition.put(sRelDom, xDom); + } + catch (uno::Exception const&) + { + TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while " + "parsing stream of Type" << nType); + } + } + aGlossaryDomList.push_back(aRelDefinition.getNamedValues()); } mxGlossaryDomList = comphelper::containerToSequence(aGlossaryDomList); } @@ -797,7 +796,7 @@ uno::Reference<xml::dom::XDocument> OOXMLDocumentImpl::getGlossaryDocDom( ) return mxGlossaryDocDom; } -uno::Sequence<uno::Sequence< uno::Any> > OOXMLDocumentImpl::getGlossaryDomList() +uno::Sequence<uno::Sequence< beans::NamedValue> > OOXMLDocumentImpl::getGlossaryDomList() { return mxGlossaryDomList; } diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx index d7a8a00bd58c..c896d7bf4901 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx @@ -44,7 +44,7 @@ class OOXMLDocumentImpl : public OOXMLDocument css::uno::Reference<css::frame::XModel> mxModel; css::uno::Reference<css::drawing::XDrawPage> mxDrawPage; css::uno::Reference<css::xml::dom::XDocument> mxGlossaryDocDom; - css::uno::Sequence < css::uno::Sequence< css::uno::Any > > mxGlossaryDomList; + css::uno::Sequence < css::uno::Sequence< css::beans::NamedValue > > mxGlossaryDomList; /// Stack of shape contexts, 1 element for VML, 1 element / nesting level for drawingML. std::stack< rtl::Reference<oox::shape::ShapeContextHandler> > maShapeContexts; css::uno::Reference<css::xml::dom::XDocument> mxThemeDom; @@ -141,7 +141,7 @@ public: virtual css::uno::Sequence<css::uno::Reference<css::xml::dom::XDocument> > getCustomXmlDomList() override; virtual css::uno::Sequence<css::uno::Reference<css::xml::dom::XDocument> > getCustomXmlDomPropsList() override; virtual css::uno::Reference<css::xml::dom::XDocument> getGlossaryDocDom() override; - virtual css::uno::Sequence<css::uno::Sequence< css::uno::Any> > getGlossaryDomList() override; + virtual css::uno::Sequence<css::uno::Sequence< css::beans::NamedValue> > getGlossaryDomList() override; virtual css::uno::Sequence<css::beans::PropertyValue > getEmbeddingsList() override; void incrementProgress(); |