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>
This commit is contained in:
Andres Gomez 2013-09-13 18:18:39 +03:00 committed by Miklos Vajna
parent 44c5fcb7eb
commit 290f03e8bb
5 changed files with 113 additions and 2 deletions

View File

@ -539,6 +539,25 @@ void Test::testN764005()
void Test::testSmartart()
{
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xTextDocumentPropertySet(xTextDocument, uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> aGrabBag(0);
xTextDocumentPropertySet->getPropertyValue(OUString("InteropGrabBag")) >>= aGrabBag;
CPPUNIT_ASSERT(aGrabBag.hasElements()); // Grab Bag not empty
sal_Bool bTheme = sal_False;
for(int i = 0; i < aGrabBag.getLength(); ++i)
{
if (aGrabBag[i].Name == OUString("OOXTheme"))
{
bTheme = sal_True;
uno::Reference<xml::dom::XDocument> aThemeDom;
CPPUNIT_ASSERT(aGrabBag[i].Value >>= aThemeDom); // PropertyValue of proper type
CPPUNIT_ASSERT(aThemeDom.get()); // Reference not empty
}
}
CPPUNIT_ASSERT(bTheme); // Grab Bag has all the expected elements
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDraws->getCount()); // One groupshape in the doc
@ -547,7 +566,6 @@ void Test::testSmartart()
CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xGroup->getCount()); // 3 rectangles and an arrow in the group
uno::Reference<beans::XPropertySet> xGroupPropertySet(getShape(1), uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> aGrabBag(0);
xGroupPropertySet->getPropertyValue(OUString::createFromAscii("InteropGrabBag")) >>= aGrabBag;
CPPUNIT_ASSERT(aGrabBag.hasElements()); // Grab Bag not empty

View File

@ -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;
};

View File

@ -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() )

View File

@ -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)

View File

@ -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