diff options
author | Andres Gomez <agomez@igalia.com> | 2013-09-13 18:18:39 +0300 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2013-09-20 08:51:37 +0000 |
commit | 290f03e8bb5071d7716fb6563e3274caa51102f0 (patch) | |
tree | 0eb52118efb357d309461baf9e1098cdaf650ca0 /writerfilter | |
parent | 44c5fcb7eb4077740ef497ff4bb6c4cf23224dbf (diff) |
writerfilter: OOXML theme saved in InteropGrabBag
The XDocuments representing the DOM of an OOXML's theme document is
now stored as the PropertyValue "OOXTheme" into the "InteropGraBag"
property of the SwXTextDocument.
Added the importSubStream() method to the
writerfilter::ooxml::OOXMLDocumentImpl class in order to create the
XDocument for the theme XML fragment stream and invoked it during the
resolve() method.
Modified the writerfilter::ooxml::OOXMLDocument abstract class to be
able to hold the OOXML's theme XDocument. Added the set/getTheme()
methods to store and obtain the XDocument directly.
Modified the WriterFilter::filter() method to store the OOXML's theme
XDocument in the "InteropGrabBag" property of the TextDocument service
SwXTextDocument implementation.
Updated the UTs accordingly.
Change-Id: I3960590fcf4856caf770908b983ffb6898f061c0
Reviewed-on: https://gerrit.libreoffice.org/6002
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/inc/ooxml/OOXMLDocument.hxx | 3 | ||||
-rw-r--r-- | writerfilter/source/filter/ImportFilter.cxx | 33 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLDocumentImpl.cxx | 52 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLDocumentImpl.hxx | 7 |
4 files changed, 94 insertions, 1 deletions
diff --git a/writerfilter/inc/ooxml/OOXMLDocument.hxx b/writerfilter/inc/ooxml/OOXMLDocument.hxx index c97e2b2b08c0..1f4930b692e3 100644 --- a/writerfilter/inc/ooxml/OOXMLDocument.hxx +++ b/writerfilter/inc/ooxml/OOXMLDocument.hxx @@ -28,6 +28,7 @@ #include <com/sun/star/xml/sax/XFastParser.hpp> #include <com/sun/star/xml/sax/XFastTokenHandler.hpp> #include <com/sun/star/xml/sax/XFastShapeContextHandler.hpp> +#include <com/sun/star/xml/dom/XDocument.hpp> #include <com/sun/star/frame/XModel.hpp> #include <com/sun/star/drawing/XDrawPage.hpp> @@ -239,6 +240,8 @@ public: virtual const OUString & getTarget() const = 0; virtual uno::Reference<xml::sax::XFastShapeContextHandler> getShapeContext( ) = 0; virtual void setShapeContext( uno::Reference<xml::sax::XFastShapeContextHandler> xContext ) = 0; + virtual uno::Reference<xml::dom::XDocument> getThemeDom( ) = 0; + virtual void setThemeDom( uno::Reference<xml::dom::XDocument> xThemeDom ) = 0; }; diff --git a/writerfilter/source/filter/ImportFilter.cxx b/writerfilter/source/filter/ImportFilter.cxx index e56cbca4dff6..df5604b74a77 100644 --- a/writerfilter/source/filter/ImportFilter.cxx +++ b/writerfilter/source/filter/ImportFilter.cxx @@ -116,6 +116,39 @@ sal_Bool WriterFilter::filter( const uno::Sequence< beans::PropertyValue >& aDes pDocument->setDrawPage(xDrawPage); pDocument->resolve(*pStream); + + // Adding the saved Theme DOM to the document's grab bag + try + { + uno::Reference<beans::XPropertySet> xDocProps(m_xDstDoc, uno::UNO_QUERY); + if (xDocProps.is()) + { + uno::Reference<beans::XPropertySetInfo> xPropsInfo = xDocProps->getPropertySetInfo(); + + const OUString& aGrabBagPropName = OUString("InteropGrabBag"); + if( xPropsInfo.is() && xPropsInfo->hasPropertyByName( aGrabBagPropName ) ) + { + uno::Sequence<beans::PropertyValue> aGrabBag; + + // We want to keep the previous items + xDocProps->getPropertyValue( aGrabBagPropName ) >>= aGrabBag; + sal_Int32 length = aGrabBag.getLength(); + aGrabBag.realloc(length+1); + + uno::Reference<xml::dom::XDocument> aThemeDom = pDocument->getThemeDom(); + + beans::PropertyValue* pValue = aGrabBag.getArray(); + pValue[length].Name = OUString("OOXTheme"); + pValue[length].Value = uno::makeAny( aThemeDom ); + + xDocProps->setPropertyValue( aGrabBagPropName, uno::Any( aGrabBag ) ); + } + } + } + catch(const uno::Exception&) + { + } + writerfilter::ooxml::OOXMLStream::Pointer_t pVBAProjectStream(writerfilter::ooxml::OOXMLDocumentFactory::createStream( pDocStream, writerfilter::ooxml::OOXMLStream::VBAPROJECT )); oox::StorageRef xVbaPrjStrg( new ::oox::ole::OleStorage( m_xContext, pVBAProjectStream->getDocumentStream(), false ) ); if( xVbaPrjStrg.get() && xVbaPrjStrg->isStorage() ) diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx index b64c28a10e4c..c77cebbad70c 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx @@ -20,6 +20,7 @@ #include <com/sun/star/xml/sax/XParser.hpp> #include <com/sun/star/xml/sax/SAXException.hpp> +#include <com/sun/star/xml/dom/DocumentBuilder.hpp> #include <doctok/resourceids.hxx> #include <ooxml/resourceids.hxx> #include "OOXMLDocumentImpl.hxx" @@ -43,7 +44,7 @@ using namespace ::std; OOXMLDocumentImpl::OOXMLDocumentImpl (OOXMLStream::Pointer_t pStream) -: mpStream(pStream), mXNoteType(0), mbIsSubstream( false ) +: mpStream(pStream), mXNoteType(0), mxThemeDom(0), mbIsSubstream( false ) { } @@ -109,6 +110,44 @@ void OOXMLDocumentImpl::resolveFastSubStreamWithId(Stream & rStream, rStream.substream(nId, pStream); } +uno::Reference<xml::dom::XDocument> OOXMLDocumentImpl::importSubStream(OOXMLStream::StreamType_t nType) +{ + uno::Reference<xml::dom::XDocument> xRet; + + OOXMLStream::Pointer_t pStream; + try + { + pStream = OOXMLDocumentFactory::createStream(mpStream, nType); + } + catch (uno::Exception const& e) + { + SAL_INFO("writerfilter", "importSubStream: exception while " + "importing stream " << nType << " : " << e.Message); + return xRet; + } + + uno::Reference<io::XInputStream> xInputStream = + pStream->getDocumentStream(); + + if (xInputStream.is()) + { + try + { + uno::Reference<uno::XComponentContext> xContext(mpStream->getContext()); + uno::Reference<xml::dom::XDocumentBuilder> xDomBuilder(xml::dom::DocumentBuilder::create(xContext)); + xRet = xDomBuilder->parse(xInputStream); + } + catch (uno::Exception const& e) + { + SAL_INFO("writerfilter", "importSubStream: exception while " + "parsing stream " << nType << " : " << e.Message); + return xRet; + } + } + + return xRet; +} + void OOXMLDocumentImpl::setXNoteId(const sal_Int32 nId) { mnXNoteId = nId; @@ -333,6 +372,7 @@ void OOXMLDocumentImpl::resolve(Stream & rStream) (mpStream->getFastTokenHandler(xContext)); resolveFastSubStream(rStream, OOXMLStream::SETTINGS); + mxThemeDom = importSubStream(OOXMLStream::THEME); resolveFastSubStream(rStream, OOXMLStream::THEME); resolveFastSubStream(rStream, OOXMLStream::FONTTABLE); resolveFastSubStream(rStream, OOXMLStream::STYLES); @@ -411,6 +451,16 @@ uno::Reference<xml::sax::XFastShapeContextHandler> OOXMLDocumentImpl::getShapeCo return mxShapeContext; } +void OOXMLDocumentImpl::setThemeDom( uno::Reference<xml::dom::XDocument> xThemeDom ) +{ + mxThemeDom = xThemeDom; +} + +uno::Reference<xml::dom::XDocument> OOXMLDocumentImpl::getThemeDom( ) +{ + return mxThemeDom; +} + OOXMLDocument * OOXMLDocumentFactory::createDocument (OOXMLStream::Pointer_t pStream) diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx index f23725d64399..bf185041ea1a 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx @@ -22,6 +22,7 @@ #include <ooxml/OOXMLDocument.hxx> #include <com/sun/star/xml/sax/XFastTokenHandler.hpp> +#include <com/sun/star/xml/dom/XDocument.hpp> #include "OOXMLPropertySet.hxx" @@ -40,6 +41,7 @@ class OOXMLDocumentImpl : public OOXMLDocument uno::Reference<frame::XModel> mxModel; uno::Reference<drawing::XDrawPage> mxDrawPage; uno::Reference<xml::sax::XFastShapeContextHandler> mxShapeContext; + uno::Reference<xml::dom::XDocument> mxThemeDom; bool mbIsSubstream; @@ -51,6 +53,8 @@ protected: writerfilter::Reference<Stream>::Pointer_t pStream, sal_uInt32 nId); + uno::Reference<xml::dom::XDocument> importSubStream(OOXMLStream::StreamType_t nType); + writerfilter::Reference<Stream>::Pointer_t getSubStream(const OUString & rId); @@ -104,6 +108,9 @@ public: virtual const OUString & getTarget() const; virtual uno::Reference<xml::sax::XFastShapeContextHandler> getShapeContext( ); virtual void setShapeContext( uno::Reference<xml::sax::XFastShapeContextHandler> xContext ); + virtual void setThemeDom(uno::Reference<xml::dom::XDocument> xThemeDom); + virtual uno::Reference<xml::dom::XDocument> getThemeDom(); + }; }} #endif // OOXML_DOCUMENT_IMPL_HXX |