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: xmlimp.hxx,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 #ifndef _XMLOFF_XMLIMP_HXX
32 #define _XMLOFF_XMLIMP_HXX
34 #ifndef _COM_SUN_STAR_XML_SAX_SAXPARSEEXCEPTION_HPP_
35 #include <com/sun/star/xml/sax/SAXParseException.hpp>
37 #ifndef _COM_SUN_STAR_XML_SAX_XEXTENDEDDOCUMENTHANDLER_HPP_
38 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
40 #ifndef _COM_SUN_STAR_XML_SAX_SAXEXCEPTION_HPP_
41 #include <com/sun/star/xml/sax/SAXException.hpp>
43 #ifndef _COM_SUN_STAR_XML_SAX_XATTRIBUTELIST_HPP_
44 #include <com/sun/star/xml/sax/XAttributeList.hpp>
46 #ifndef _COM_SUN_STAR_XML_SAX_XLOCATOR_HPP_
47 #include <com/sun/star/xml/sax/XLocator.hpp>
49 #ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
50 #include <com/sun/star/lang/XUnoTunnel.hpp>
52 #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATSSUPPLIER_HPP_
53 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
55 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
56 #include <com/sun/star/container/XNameContainer.hpp>
58 #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
59 #include <com/sun/star/lang/XInitialization.hpp>
61 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
62 #include <com/sun/star/lang/XServiceInfo.hpp>
64 #ifndef _COM_SUN_STAR_DOCUMENT_XIMPORTER_HPP_
65 #include <com/sun/star/document/XImporter.hpp>
67 #ifndef _COM_SUN_STAR_DOCUMENT_XFILTER_HPP_
68 #include <com/sun/star/document/XFilter.hpp>
70 #ifndef _COM_SUN_STAR_DRAWING_XGRAPHICOBJECTRESOLVER_HPP_
71 #include <com/sun/star/document/XGraphicObjectResolver.hpp>
73 #ifndef _COM_SUN_STAR_DRAWING_XEMBEDDEDOBJECTRESOLVER_HPP_
74 #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
76 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
77 #include <com/sun/star/beans/XPropertySet.hpp>
80 #ifndef _CPPUHELPER_WEAK_HXX_ //autogen wg. OWeakObject
81 #include <cppuhelper/weak.hxx>
84 #ifndef _XMLOFF_TEXTIMP_HXX_
85 #include <bf_xmloff/txtimp.hxx>
88 #ifndef _XMLOFF_SHAPEIMPORT_HXX_
89 #include <bf_xmloff/shapeimport.hxx>
92 #ifndef _XMLOFF_SCH_XMLIMPORTHELPER_HXX_
93 #include <bf_xmloff/SchXMLImportHelper.hxx>
95 #ifndef _XMLOFF_PROGRESSBARHELPER_HXX
96 #include <bf_xmloff/ProgressBarHelper.hxx>
99 #ifndef _CPPUHELPER_IMPLBASE6_HXX_
100 #include <cppuhelper/implbase6.hxx>
102 #ifndef _XMLOFF_FORMLAYERIMPORT_HXX_
103 #include <bf_xmloff/formlayerimport.hxx>
106 namespace rtl
{ class OUString
; }
107 namespace com
{ namespace sun
{ namespace star
{
108 namespace frame
{ class XModel
; }
109 namespace io
{ class XOutputStream
; }
112 namespace binfilter
{
114 class SvXMLNamespaceMap
;
115 class SvXMLImportContext
;
116 class SvXMLImportContexts_Impl
;
117 class SvXMLImport_Impl
;
118 class SvXMLUnitConverter
;
119 class SvXMLNumFmtHelper
;
120 class XMLFontStylesContext
;
121 class XMLEventImportHelper
;
123 class SvXMLImportEventListener
;
125 #define IMPORT_META 0x0001
126 #define IMPORT_STYLES 0x0002
127 #define IMPORT_MASTERSTYLES 0x0004
128 #define IMPORT_AUTOSTYLES 0x0008
129 #define IMPORT_CONTENT 0x0010
130 #define IMPORT_SCRIPTS 0x0020
131 #define IMPORT_SETTINGS 0x0040
132 #define IMPORT_FONTDECLS 0x0080
133 #define IMPORT_EMBEDDED 0x0100
134 #define IMPORT_ALL 0xffff
136 class SvXMLImport
: public ::cppu::WeakImplHelper6
<
137 ::com::sun::star::xml::sax::XExtendedDocumentHandler
,
138 ::com::sun::star::lang::XServiceInfo
,
139 ::com::sun::star::lang::XInitialization
,
140 ::com::sun::star::document::XImporter
,
141 ::com::sun::star::document::XFilter
,
142 ::com::sun::star::lang::XUnoTunnel
>
144 friend class SvXMLImportContext
;
146 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XLocator
> xLocator
;
147 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> xModel
;
148 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XNumberFormatsSupplier
> xNumberFormatsSupplier
;
149 ::com::sun::star::uno::Reference
< ::com::sun::star::document::XGraphicObjectResolver
> xGraphicResolver
;
150 ::com::sun::star::uno::Reference
< ::com::sun::star::document::XEmbeddedObjectResolver
> xEmbeddedResolver
;
151 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xImportInfo
;
153 UniReference
< XMLTextImportHelper
> mxTextImport
;
154 UniReference
< XMLShapeImportHelper
> mxShapeImport
;
156 UniReference
< SchXMLImportHelper
> mxChartImport
;
157 UniReference
< ::binfilter::xmloff::OFormLayerXMLImport
> mxFormImport
;
160 SvXMLImportContextRef xFontDecls
;
161 SvXMLImportContextRef xStyles
;
162 SvXMLImportContextRef xAutoStyles
;
163 SvXMLImportContextRef xMasterStyles
;
165 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> xGradientHelper
;
166 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> xHatchHelper
;
167 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> xBitmapHelper
;
168 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> xTransGradientHelper
;
169 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> xMarkerHelper
;
170 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> xDashHelper
;
171 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> xNumberStyles
;
173 SvXMLImport_Impl
*pImpl
; // dummy
176 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> mxServiceFactory
;
178 SvXMLNamespaceMap
*pNamespaceMap
;
179 SvXMLUnitConverter
*pUnitConv
;
180 SvXMLImportContexts_Impl
*pContexts
;
181 SvXMLNumFmtHelper
*pNumImport
;
182 ProgressBarHelper
*pProgressBarHelper
;
183 XMLEventImportHelper
*pEventImportHelper
;
184 XMLErrors
*pXMLErrors
;
185 SvXMLImportEventListener
*pEventListener
;
186 ::rtl::OUString sPackageProtocol
;
190 sal_uInt16 mnImportFlags
;
191 sal_uInt16 mnErrorFlags
;
194 ::com::sun::star::uno::Reference
< ::com::sun::star::task::XStatusIndicator
> mxStatusIndicator
;
195 sal_Bool mbIsFormsSupported
;
197 // This method is called after the namespace map has been updated, but
198 // before a context for the current element has been pushed.
199 virtual SvXMLImportContext
*CreateContext( sal_uInt16 nPrefix
,
200 const ::rtl::OUString
& rLocalName
,
201 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
);
203 virtual XMLTextImportHelper
* CreateTextImport();
204 virtual XMLShapeImportHelper
* CreateShapeImport();
205 inline sal_Bool
HasShapeImport() const { return mxShapeImport
.is(); }
206 inline void ClearShapeImport() { mxShapeImport
= 0; }
209 virtual SchXMLImportHelper
* CreateChartImport();
210 virtual ::binfilter::xmloff::OFormLayerXMLImport
* CreateFormImport();
213 void SetFontDecls( XMLFontStylesContext
*pFontDecls
);
214 void SetStyles( SvXMLStylesContext
*pStyles
);
215 void SetAutoStyles( SvXMLStylesContext
*pAutoStyles
);
216 void SetMasterStyles( SvXMLStylesContext
*pMasterStyles
);
218 const ::com::sun::star::uno::Reference
< ::com::sun::star::document::XEmbeddedObjectResolver
>& GetEmbeddedResolver() const { return xEmbeddedResolver
; }
219 inline void SetEmbeddedResolver( ::com::sun::star::uno::Reference
< ::com::sun::star::document::XEmbeddedObjectResolver
>& _xEmbeddedResolver
);
221 const ::com::sun::star::uno::Reference
< ::com::sun::star::document::XGraphicObjectResolver
>& GetGraphicResolver() const { return xGraphicResolver
; }
222 void SetGraphicResolver( ::com::sun::star::uno::Reference
< ::com::sun::star::document::XGraphicObjectResolver
>& _xGraphicResolver
);
224 void _CreateNumberFormatsSupplier();
225 void _CreateDataStylesImport();
229 // SvXMLImport( sal_uInt16 nImportFlags = IMPORT_ALL ) throw();
231 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xServiceFactory
,
232 sal_uInt16 nImportFlags
= IMPORT_ALL
) throw();
234 virtual ~SvXMLImport() throw();
236 static const ::com::sun::star::uno::Sequence
< sal_Int8
> & getUnoTunnelId() throw();
237 static SvXMLImport
* getImplementation( ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> ) throw();
239 // ::com::sun::star::xml::sax::XDocumentHandler
240 virtual void SAL_CALL
startDocument(void)
241 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
242 virtual void SAL_CALL
endDocument(void)
243 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
244 virtual void SAL_CALL
startElement(const ::rtl::OUString
& aName
,
245 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
> & xAttribs
)
246 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
247 virtual void SAL_CALL
endElement(const ::rtl::OUString
& aName
)
248 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
249 virtual void SAL_CALL
characters(const ::rtl::OUString
& aChars
)
250 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
251 virtual void SAL_CALL
ignorableWhitespace(const ::rtl::OUString
& aWhitespaces
)
252 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
253 virtual void SAL_CALL
processingInstruction(const ::rtl::OUString
& aTarget
,
254 const ::rtl::OUString
& aData
)
255 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
256 virtual void SAL_CALL
setDocumentLocator(const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XLocator
> & xLocator
)
257 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
259 // ::com::sun::star::xml::sax::XExtendedDocumentHandler
260 virtual void SAL_CALL
startCDATA(void) throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
261 virtual void SAL_CALL
endCDATA(void) throw( ::com::sun::star::uno::RuntimeException
);
262 virtual void SAL_CALL
comment(const ::rtl::OUString
& sComment
)
263 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
264 virtual void SAL_CALL
allowLineBreak(void)
265 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
266 virtual void SAL_CALL
unknown(const ::rtl::OUString
& sString
)
267 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
270 virtual void SAL_CALL
setTargetDocument( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>& xDoc
) throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
);
273 virtual sal_Bool SAL_CALL
filter( const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aDescriptor
) throw (::com::sun::star::uno::RuntimeException
);
274 virtual void SAL_CALL
cancel( ) throw (::com::sun::star::uno::RuntimeException
);
277 virtual void SAL_CALL
initialize( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
) throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
280 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& aIdentifier
) throw(::com::sun::star::uno::RuntimeException
);
283 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
);
284 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
);
285 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
);
287 // is called if the meta contains a meta:document-statistic element and gives the attributes of this element
288 virtual void SetStatisticAttributes(const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
> & xAttribs
);
290 // get import helper for text
291 inline UniReference
< XMLTextImportHelper
> GetTextImport();
292 sal_Bool
HasTextImport() const { return mxTextImport
.is(); }
293 inline SvXMLNumFmtHelper
* GetDataStylesImport();
295 // get import helper for shapes
296 inline UniReference
< XMLShapeImportHelper
> GetShapeImport();
299 // get import helper for charts
300 inline UniReference
< SchXMLImportHelper
> GetChartImport();
302 // get import helper for form layer
303 inline UniReference
< ::binfilter::xmloff::OFormLayerXMLImport
> GetFormImport();
304 #endif // #ifndef SVX_LIGHT
306 // get XPropertySet with import information
307 inline ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> getImportInfo() const { return xImportInfo
; }
309 // get import helper for events
310 XMLEventImportHelper
& GetEventImport();
312 SvXMLNamespaceMap
& GetNamespaceMap() { return *pNamespaceMap
; }
313 const SvXMLNamespaceMap
& GetNamespaceMap() const { return *pNamespaceMap
; }
314 const SvXMLUnitConverter
& GetMM100UnitConverter() const { return *pUnitConv
; }
315 SvXMLUnitConverter
& GetMM100UnitConverter() { return *pUnitConv
; }
316 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XLocator
> & GetLocator() const { return xLocator
; }
317 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> &
318 GetModel() const { return xModel
; }
320 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> & GetGradientHelper();
321 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> & GetHatchHelper();
322 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> & GetBitmapHelper();
323 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> & GetTransGradientHelper();
324 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> & GetMarkerHelper();
325 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
> & GetDashHelper();
326 inline ::com::sun::star::uno::Reference
< ::com::sun::star::util::XNumberFormatsSupplier
> & GetNumberFormatsSupplier();
328 // Convert a local packe URL into either a graphic manager or a
329 // internal package URL. The later one happens only if bLoadURL is true
330 ::rtl::OUString
ResolveGraphicObjectURL( const ::rtl::OUString
& rURL
, sal_Bool bLoadOnDemand
);
331 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
>
332 GetStreamForGraphicObjectURLFromBase64();
333 ::rtl::OUString
ResolveGraphicObjectURLFromBase64(
334 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
>& rOut
);
336 ::rtl::OUString
ResolveEmbeddedObjectURL( const ::rtl::OUString
& rURL
,
337 const ::rtl::OUString
& rClassId
);
338 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
>
339 ResolveEmbeddedObjectURLFromBase64( const ::rtl::OUString
& rURL
);
341 ProgressBarHelper
* GetProgressBarHelper();
343 void AddNumberStyle(sal_Int32 nKey
, const ::rtl::OUString
& sName
);
345 virtual void SetViewSettings(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aViewProps
);
346 virtual void SetConfigurationSettings(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aConfigProps
);
348 XMLFontStylesContext
*GetFontDecls();
349 SvXMLStylesContext
*GetStyles();
350 SvXMLStylesContext
*GetAutoStyles();
351 const XMLFontStylesContext
*GetFontDecls() const;
352 const SvXMLStylesContext
*GetStyles() const;
353 const SvXMLStylesContext
*GetAutoStyles() const;
355 sal_uInt16
getImportFlags() const { return mnImportFlags
; }
357 sal_Bool
IsFormsSupported() const { return mbIsFormsSupported
; }
359 ::rtl::OUString
GetAbsoluteReference(const ::rtl::OUString
& rValue
);
361 #ifdef CONV_STAR_FONTS
362 sal_Unicode
ConvStarBatsCharToStarSymbol( sal_Unicode c
);
363 sal_Unicode
ConvStarMathCharToStarSymbol( sal_Unicode c
);
367 * Record an error condition that occured during import. The
368 * behavior of SetError can be modified using the error flag
372 /// error ID, may contain an error flag
374 /// string parameters for the error message
375 const ::com::sun::star::uno::Sequence
< ::rtl::OUString
> & rMsgParams
,
376 /// original exception message (if applicable)
377 const ::rtl::OUString
& rExceptionMessage
,
378 /// error location (if applicable)
379 const ::com::sun::star::uno::Reference
<
380 ::com::sun::star::xml::sax::XLocator
> & rLocator
);
384 const ::com::sun::star::uno::Sequence
< ::rtl::OUString
> & rMsgParams
);
386 /** return current error flags */
387 sal_uInt16
GetErrorFlags() { return mnErrorFlags
; }
389 virtual void DisposingModel();
392 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> getServiceFactory();
395 inline UniReference
< XMLTextImportHelper
> SvXMLImport::GetTextImport()
397 if( !mxTextImport
.is() )
398 mxTextImport
= CreateTextImport();
403 inline UniReference
< XMLShapeImportHelper
> SvXMLImport::GetShapeImport()
405 if( !mxShapeImport
.is() )
406 mxShapeImport
= CreateShapeImport();
408 return mxShapeImport
;
412 inline UniReference
< SchXMLImportHelper
> SvXMLImport::GetChartImport()
414 if( !mxChartImport
.is() )
415 mxChartImport
= CreateChartImport();
417 return mxChartImport
;
422 inline UniReference
< ::binfilter::xmloff::OFormLayerXMLImport
> SvXMLImport::GetFormImport()
424 if( !mxFormImport
.is() )
425 mxFormImport
= CreateFormImport();
429 #endif // #ifndef SVX_LIGHT
431 inline void SvXMLImport::SetEmbeddedResolver(
432 ::com::sun::star::uno::Reference
< ::com::sun::star::document::XEmbeddedObjectResolver
>& _xEmbeddedResolver
)
434 xEmbeddedResolver
= _xEmbeddedResolver
;
437 inline void SvXMLImport::SetGraphicResolver(
438 ::com::sun::star::uno::Reference
< ::com::sun::star::document::XGraphicObjectResolver
>& _xGraphicResolver
)
440 xGraphicResolver
= _xGraphicResolver
;
443 inline ::com::sun::star::uno::Reference
< ::com::sun::star::util::XNumberFormatsSupplier
> & SvXMLImport::GetNumberFormatsSupplier()
445 if ( ! xNumberFormatsSupplier
.is() && xModel
.is() )
446 _CreateNumberFormatsSupplier();
448 return xNumberFormatsSupplier
;
451 inline SvXMLNumFmtHelper
* SvXMLImport::GetDataStylesImport()
453 if ( pNumImport
== NULL
)
454 _CreateDataStylesImport();
459 }//end of namespace binfilter
460 #endif // _XMLOFF_XMLIMP_HXX