1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ShapeContextHandler.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "ShapeContextHandler.hxx"
32 #include "oox/vml/vmldrawingfragment.hxx"
33 #include "oox/vml/vmlshape.hxx"
34 #include "oox/vml/vmlshapecontainer.hxx"
42 namespace oox
{ namespace shape
{
44 using namespace ::com::sun::star
;
46 using namespace drawingml
;
48 ShapeContextHandler::ShapeContextHandler
49 (uno::Reference
< uno::XComponentContext
> const & context
) :
50 mnStartToken(0), m_xContext(context
)
54 uno::Reference
<lang::XMultiServiceFactory
>
55 xFactory(m_xContext
->getServiceManager(), uno::UNO_QUERY_THROW
);
56 mxFilterBase
.set( new ShapeFilterBase(xFactory
) );
58 catch( uno::Exception
& )
63 ShapeContextHandler::~ShapeContextHandler()
67 uno::Reference
<xml::sax::XFastContextHandler
>
68 ShapeContextHandler::getGraphicShapeContext(::sal_Int32 Element
)
70 if (! mxGraphicShapeContext
.is())
72 FragmentHandlerRef rFragmentHandler
73 (new ShapeFragmentHandler(*mxFilterBase
, msRelationFragmentPath
));
74 ShapePtr pMasterShape
;
76 switch (Element
& 0xffff)
79 mpShape
.reset(new Shape("com.sun.star.drawing.OLE2Shape" ));
80 mxGraphicShapeContext
.set
81 (new GraphicalObjectFrameContext(*rFragmentHandler
, pMasterShape
, mpShape
));
84 mpShape
.reset(new Shape("com.sun.star.drawing.GraphicObjectShape" ));
85 mxGraphicShapeContext
.set
86 (new GraphicShapeContext(*rFragmentHandler
, pMasterShape
, mpShape
));
93 return mxGraphicShapeContext
;
96 uno::Reference
<xml::sax::XFastContextHandler
>
97 ShapeContextHandler::getDrawingShapeContext()
100 clog
<< "ShapeContextHandler::getDrawingShapeContext" << endl
;
102 if (!mxDrawingFragmentHandler
.is())
104 mpDrawing
.reset( new oox::vml::Drawing( *mxFilterBase
, mxDrawPage
, oox::vml::VMLDRAWING_WORD
) );
105 mxDrawingFragmentHandler
.set
106 (dynamic_cast<ContextHandler
*>
107 (new oox::vml::DrawingFragment
108 ( *mxFilterBase
, msRelationFragmentPath
, *mpDrawing
)));
111 return mxDrawingFragmentHandler
;
114 uno::Reference
<xml::sax::XFastContextHandler
>
115 ShapeContextHandler::getContextHandler()
117 uno::Reference
<xml::sax::XFastContextHandler
> xResult
;
119 switch (mnStartToken
& NMSP_MASK
)
123 xResult
.set(getDrawingShapeContext());
126 xResult
.set(getGraphicShapeContext(mnStartToken
));
133 // ::com::sun::star::xml::sax::XFastContextHandler:
134 void SAL_CALL
ShapeContextHandler::startFastElement
135 (::sal_Int32 Element
,
136 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
137 throw (uno::RuntimeException
, xml::sax::SAXException
)
139 static const ::rtl::OUString sInputStream
140 (RTL_CONSTASCII_USTRINGPARAM ("InputStream"));
142 uno::Sequence
<beans::PropertyValue
> aSeq(1);
143 aSeq
[0].Name
= sInputStream
;
144 aSeq
[0].Value
<<= mxInputStream
;
145 mxFilterBase
->filter(aSeq
);
147 mpThemePtr
.reset(new Theme());
149 uno::Reference
<XFastContextHandler
> xContextHandler(getContextHandler());
151 if (xContextHandler
.is())
152 xContextHandler
->startFastElement(Element
, Attribs
);
155 void SAL_CALL
ShapeContextHandler::startUnknownElement
156 (const ::rtl::OUString
& Namespace
, const ::rtl::OUString
& Name
,
157 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
158 throw (uno::RuntimeException
, xml::sax::SAXException
)
160 uno::Reference
<XFastContextHandler
> xContextHandler(getContextHandler());
162 if (xContextHandler
.is())
163 xContextHandler
->startUnknownElement(Namespace
, Name
, Attribs
);
166 void SAL_CALL
ShapeContextHandler::endFastElement(::sal_Int32 Element
)
167 throw (uno::RuntimeException
, xml::sax::SAXException
)
169 uno::Reference
<XFastContextHandler
> xContextHandler(getContextHandler());
171 if (xContextHandler
.is())
172 xContextHandler
->endFastElement(Element
);
175 void SAL_CALL
ShapeContextHandler::endUnknownElement
176 (const ::rtl::OUString
& Namespace
,
177 const ::rtl::OUString
& Name
)
178 throw (uno::RuntimeException
, xml::sax::SAXException
)
180 uno::Reference
<XFastContextHandler
> xContextHandler(getContextHandler());
182 if (xContextHandler
.is())
183 xContextHandler
->endUnknownElement(Namespace
, Name
);
186 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
187 ShapeContextHandler::createFastChildContext
188 (::sal_Int32 Element
,
189 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
190 throw (uno::RuntimeException
, xml::sax::SAXException
)
193 clog
<< "ShapeContextHandler::createFastChildContext" << endl
;
195 uno::Reference
< xml::sax::XFastContextHandler
> xResult
;
196 uno::Reference
< xml::sax::XFastContextHandler
> xContextHandler(getContextHandler());
198 if (xContextHandler
.is())
199 xResult
.set(xContextHandler
->createFastChildContext
205 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
206 ShapeContextHandler::createUnknownChildContext
207 (const ::rtl::OUString
& Namespace
,
208 const ::rtl::OUString
& Name
,
209 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
210 throw (uno::RuntimeException
, xml::sax::SAXException
)
212 uno::Reference
<XFastContextHandler
> xContextHandler(getContextHandler());
214 if (xContextHandler
.is())
215 return xContextHandler
->createUnknownChildContext
216 (Namespace
, Name
, Attribs
);
218 return uno::Reference
< xml::sax::XFastContextHandler
>();
221 void SAL_CALL
ShapeContextHandler::characters(const ::rtl::OUString
& aChars
)
222 throw (uno::RuntimeException
, xml::sax::SAXException
)
224 uno::Reference
<XFastContextHandler
> xContextHandler(getContextHandler());
226 if (xContextHandler
.is())
227 xContextHandler
->characters(aChars
);
230 // ::com::sun::star::xml::sax::XFastShapeContextHandler:
231 uno::Reference
< drawing::XShape
> SAL_CALL
232 ShapeContextHandler::getShape() throw (uno::RuntimeException
)
234 uno::Reference
< drawing::XShape
> xResult
;
235 uno::Reference
< drawing::XShapes
> xShapes( mxDrawPage
, uno::UNO_QUERY
);
237 if (mxFilterBase
.is() && xShapes
.is())
239 if (mpDrawing
.get() != NULL
)
241 mpDrawing
->finalizeFragmentImport();
242 if( const ::oox::vml::ShapeBase
* pShape
= mpDrawing
->getShapes().getFirstShape() )
243 xResult
= pShape
->convertAndInsert( xShapes
);
245 else if (mpShape
.get() != NULL
)
247 mpShape
->addShape(*mxFilterBase
, mpThemePtr
, xShapes
);
248 xResult
.set(mpShape
->getXShape());
255 css::uno::Reference
< css::drawing::XDrawPage
> SAL_CALL
256 ShapeContextHandler::getDrawPage() throw (css::uno::RuntimeException
)
261 void SAL_CALL
ShapeContextHandler::setDrawPage
262 (const css::uno::Reference
< css::drawing::XDrawPage
> & the_value
)
263 throw (css::uno::RuntimeException
)
265 mxDrawPage
= the_value
;
268 css::uno::Reference
< css::frame::XModel
> SAL_CALL
269 ShapeContextHandler::getModel() throw (css::uno::RuntimeException
)
271 if( !mxFilterBase
.is() )
272 throw uno::RuntimeException();
273 return mxFilterBase
->getModel();
276 void SAL_CALL
ShapeContextHandler::setModel
277 (const css::uno::Reference
< css::frame::XModel
> & the_value
)
278 throw (css::uno::RuntimeException
)
280 if( !mxFilterBase
.is() )
281 throw uno::RuntimeException();
282 uno::Reference
<lang::XComponent
> xComp(the_value
, uno::UNO_QUERY_THROW
);
283 mxFilterBase
->setTargetDocument(xComp
);
286 uno::Reference
< io::XInputStream
> SAL_CALL
287 ShapeContextHandler::getInputStream() throw (uno::RuntimeException
)
289 return mxInputStream
;
292 void SAL_CALL
ShapeContextHandler::setInputStream
293 (const uno::Reference
< io::XInputStream
> & the_value
)
294 throw (uno::RuntimeException
)
296 mxInputStream
= the_value
;
299 ::rtl::OUString SAL_CALL
ShapeContextHandler::getRelationFragmentPath()
300 throw (uno::RuntimeException
)
302 return msRelationFragmentPath
;
305 void SAL_CALL
ShapeContextHandler::setRelationFragmentPath
306 (const ::rtl::OUString
& the_value
)
307 throw (uno::RuntimeException
)
309 msRelationFragmentPath
= the_value
;
312 ::sal_Int32 SAL_CALL
ShapeContextHandler::getStartToken() throw (::com::sun::star::uno::RuntimeException
)
317 void SAL_CALL
ShapeContextHandler::setStartToken( ::sal_Int32 _starttoken
) throw (::com::sun::star::uno::RuntimeException
)
319 mnStartToken
= _starttoken
;
324 ::rtl::OUString
ShapeContextHandler::getImplementationName()
325 throw (css::uno::RuntimeException
)
327 return ShapeContextHandler_getImplementationName();
330 uno::Sequence
< ::rtl::OUString
> ShapeContextHandler::getSupportedServiceNames()
331 throw (css::uno::RuntimeException
)
333 return ShapeContextHandler_getSupportedServiceNames();
336 ::rtl::OUString SAL_CALL
ShapeContextHandler_getImplementationName() {
337 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
338 "com.sun.star.comp.oox.ShapeContextHandler"));
341 ::sal_Bool SAL_CALL
ShapeContextHandler::supportsService
342 (const ::rtl::OUString
& ServiceName
) throw (css::uno::RuntimeException
)
344 uno::Sequence
< ::rtl::OUString
> aSeq
= getSupportedServiceNames();
346 if (aSeq
[0].equals(ServiceName
))
352 uno::Sequence
< ::rtl::OUString
> SAL_CALL
353 ShapeContextHandler_getSupportedServiceNames()
355 uno::Sequence
< ::rtl::OUString
> s(1);
356 s
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
357 "com.sun.star.xml.sax.FastShapeContextHandler"));
361 uno::Reference
< uno::XInterface
> SAL_CALL
362 ShapeContextHandler_create(
363 const uno::Reference
< uno::XComponentContext
> & context
)
364 SAL_THROW((uno::Exception
))
366 return static_cast< ::cppu::OWeakObject
* >
367 (new ShapeContextHandler(context
));
370 uno::Reference
< uno::XInterface
> SAL_CALL
371 ShapeContextHandler_createInstance
372 ( const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
373 throw( uno::Exception
)
375 uno::Reference
<beans::XPropertySet
>
376 xPropertySet(rSMgr
, uno::UNO_QUERY_THROW
);
377 uno::Any aDefaultContext
= xPropertySet
->getPropertyValue
378 (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")));
380 uno::Reference
<uno::XComponentContext
> xContext
;
381 aDefaultContext
>>= xContext
;
383 return ShapeContextHandler_create(xContext
);