merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / core / xmlimp.cxx
blobbdf2ce0d8fb167ad7b889cb73cc31d1678086a7b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlimp.cxx,v $
10 * $Revision: 1.112.2.2 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <com/sun/star/beans/XPropertySetInfo.hpp>
34 #include <tools/debug.hxx>
35 #include <tools/urlobj.hxx>
36 #include <osl/mutex.hxx>
37 #include <rtl/uuid.h>
38 #include <rtl/memory.h>
39 #include <svtools/svarray.hxx>
40 #include "unointerfacetouniqueidentifiermapper.hxx"
41 #include <xmloff/nmspmap.hxx>
42 #include <xmloff/xmluconv.hxx>
43 #include "xmlnmspe.hxx"
44 #include "xmlkywd.hxx"
45 #include <xmloff/xmltoken.hxx>
46 #include <xmloff/XMLFontStylesContext.hxx>
47 #include <xmloff/xmlictxt.hxx>
48 #include <xmloff/xmlimp.hxx>
49 #include <xmloff/xmlnumfi.hxx>
50 #include "XMLEventImportHelper.hxx"
51 #include "XMLStarBasicContextFactory.hxx"
52 #include "XMLScriptContextFactory.hxx"
53 #include "StyleMap.hxx"
54 #include <xmloff/ProgressBarHelper.hxx>
55 #include <xmloff/xmltoken.hxx>
56 #include "xmlerror.hxx"
57 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
58 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
59 #include <com/sun/star/io/XOutputStream.hpp>
60 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
61 #include <com/sun/star/document/XStorageBasedDocument.hpp>
62 #include <com/sun/star/xml/sax/XLocator.hpp>
63 #include <com/sun/star/packages/zip/ZipIOException.hpp>
64 #include <comphelper/namecontainer.hxx>
65 #include <rtl/logfile.hxx>
66 #include <tools/string.hxx> // used in StartElement for logging
67 #include <cppuhelper/implbase1.hxx>
68 #include <comphelper/extract.hxx>
69 #include <comphelper/processfactory.hxx>
70 #include <comphelper/documentconstants.hxx>
71 #include <comphelper/storagehelper.hxx>
72 #include <vcl/fontcvt.hxx>
74 #include <com/sun/star/rdf/XMetadatable.hpp>
75 #include <com/sun/star/rdf/XRepositorySupplier.hpp>
76 #include "RDFaImportHelper.hxx"
78 #define LOGFILE_AUTHOR "unknown"
80 using ::com::sun::star::beans::XPropertySetInfo;
82 using ::rtl::OUString;
83 using ::rtl::OUStringBuffer;
85 using namespace ::osl;
86 using namespace ::com::sun::star;
87 using namespace ::com::sun::star::frame;
88 using namespace ::com::sun::star::uno;
89 using namespace ::com::sun::star::util;
90 using namespace ::com::sun::star::io;
91 using namespace ::com::sun::star::container;
92 using namespace ::com::sun::star::document;
93 using namespace ::xmloff::token;
95 sal_Char __READONLY_DATA sXML_np__office[] = "_office";
96 sal_Char __READONLY_DATA sXML_np__office_ext[] = "_office_ooo";
97 sal_Char __READONLY_DATA sXML_np__ooo[] = "_ooo";
98 sal_Char __READONLY_DATA sXML_np__ooow[] = "_ooow";
99 sal_Char __READONLY_DATA sXML_np__oooc[] = "_oooc";
100 sal_Char __READONLY_DATA sXML_np__of[] = "_of";
101 sal_Char __READONLY_DATA sXML_np__style[] = "_style";
102 sal_Char __READONLY_DATA sXML_np__text[] = "_text";
103 sal_Char __READONLY_DATA sXML_np__table[] = "_table";
104 sal_Char __READONLY_DATA sXML_np__draw[] = "_draw";
105 sal_Char __READONLY_DATA sXML_np__dr3d[] = "_dr3d";
106 sal_Char __READONLY_DATA sXML_np__fo[] = "_fo";
107 sal_Char __READONLY_DATA sXML_np__xlink[] = "_xlink";
108 sal_Char __READONLY_DATA sXML_np__dc[] = "_dc";
109 sal_Char __READONLY_DATA sXML_np__dom[] = "_dom";
110 sal_Char __READONLY_DATA sXML_np__meta[] = "_meta";
111 sal_Char __READONLY_DATA sXML_np__number[] = "_number";
112 sal_Char __READONLY_DATA sXML_np__svg[] = "_svg";
113 sal_Char __READONLY_DATA sXML_np__chart[] = "_chart";
114 sal_Char __READONLY_DATA sXML_np__math[] = "_math";
115 sal_Char __READONLY_DATA sXML_np__script[] = "_script";
116 sal_Char __READONLY_DATA sXML_np__config[] = "_config";
117 sal_Char __READONLY_DATA sXML_np__db[] = "_db";
118 sal_Char __READONLY_DATA sXML_np__xforms[] = "_xforms";
119 sal_Char __READONLY_DATA sXML_np__formx[] = "_formx";
120 sal_Char __READONLY_DATA sXML_np__xsd[] = "_xsd";
121 sal_Char __READONLY_DATA sXML_np__xsi[] = "_xsi";
122 sal_Char __READONLY_DATA sXML_np__field[] = "_field";
123 sal_Char __READONLY_DATA sXML_np__xhtml[] = "_xhtml";
125 sal_Char __READONLY_DATA sXML_np__fo_old[] = "__fo";
126 sal_Char __READONLY_DATA sXML_np__xlink_old[] = "__xlink";
127 sal_Char __READONLY_DATA sXML_np__office_old[] = "__office";
128 sal_Char __READONLY_DATA sXML_np__style_old[] = "__style";
129 sal_Char __READONLY_DATA sXML_np__text_old[] = "__text";
130 sal_Char __READONLY_DATA sXML_np__table_old[] = "__table";
131 sal_Char __READONLY_DATA sXML_np__meta_old[] = "__meta";
135 class SvXMLImportEventListener : public cppu::WeakImplHelper1<
136 com::sun::star::lang::XEventListener >
138 private:
139 SvXMLImport* pImport;
141 public:
142 SvXMLImportEventListener(SvXMLImport* pImport);
143 virtual ~SvXMLImportEventListener();
145 // XEventListener
146 virtual void SAL_CALL disposing(const lang::EventObject& rEventObject) throw(::com::sun::star::uno::RuntimeException);
149 SvXMLImportEventListener::SvXMLImportEventListener(SvXMLImport* pTempImport)
150 : pImport(pTempImport)
154 SvXMLImportEventListener::~SvXMLImportEventListener()
158 // XEventListener
159 void SAL_CALL SvXMLImportEventListener::disposing( const lang::EventObject& )
160 throw(uno::RuntimeException)
162 if (pImport)
164 pImport->DisposingModel();
165 pImport = NULL;
169 //==============================================================================
171 class SvXMLImport_Impl
173 public:
174 FontToSubsFontConverter hBatsFontConv;
175 FontToSubsFontConverter hMathFontConv;
177 bool mbOwnGraphicResolver;
178 bool mbOwnEmbeddedResolver;
179 INetURLObject aBaseURL;
180 INetURLObject aDocBase;
182 /// name of stream in package, e.g., "content.xml"
183 ::rtl::OUString mStreamName;
185 ::rtl::OUString aODFVersion;
187 // --> OD 2004-08-10 #i28749# - boolean, indicating that position attributes
188 // of shapes are given in horizontal left-to-right layout. This is the case
189 // for the OpenOffice.org file format.
190 sal_Bool mbShapePositionInHoriL2R;
191 // <--
192 // --> OD 2007-12-19 #152540#
193 sal_Bool mbTextDocInOOoFileFormat;
194 // <--
196 const uno::Reference< uno::XComponentContext > mxComponentContext;
198 std::auto_ptr< xmloff::RDFaImportHelper > mpRDFaHelper;
200 SvXMLImport_Impl() :
201 hBatsFontConv( 0 ), hMathFontConv( 0 ),
202 mbOwnGraphicResolver( false ),
203 mbOwnEmbeddedResolver( false ),
204 mStreamName(),
205 // --> OD 2004-08-11 #i28749#
206 mbShapePositionInHoriL2R( sal_False ),
207 // <--
208 // --> OD 2007-12-19 #152540#
209 mbTextDocInOOoFileFormat( sal_False ),
210 // <--
211 mxComponentContext( ::comphelper::getProcessComponentContext() ),
212 mpRDFaHelper() // lazy
214 OSL_ENSURE(mxComponentContext.is(), "SvXMLImport: no ComponentContext");
215 if (!mxComponentContext.is()) throw uno::RuntimeException();
218 ~SvXMLImport_Impl()
220 if( hBatsFontConv )
221 DestroyFontToSubsFontConverter( hBatsFontConv );
222 if( hMathFontConv )
223 DestroyFontToSubsFontConverter( hMathFontConv );
226 ::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper;
229 typedef SvXMLImportContext *SvXMLImportContextPtr;
230 SV_DECL_PTRARR( SvXMLImportContexts_Impl, SvXMLImportContextPtr, 20, 5 )
231 SV_IMPL_PTRARR( SvXMLImportContexts_Impl, SvXMLImportContextPtr )
233 SvXMLImportContext *SvXMLImport::CreateContext( USHORT nPrefix,
234 const OUString& rLocalName,
235 const uno::Reference< xml::sax::XAttributeList >& )
237 return new SvXMLImportContext( *this, nPrefix, rLocalName );
240 void SvXMLImport::_InitCtor()
242 if( mnImportFlags != 0 )
244 // implicit "xml" namespace prefix
245 mpNamespaceMap->Add( GetXMLToken(XML_XML), GetXMLToken(XML_N_XML),
246 XML_NAMESPACE_XML );
247 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office ) ),
248 GetXMLToken(XML_N_OFFICE),
249 XML_NAMESPACE_OFFICE );
250 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office_ext ) ),
251 GetXMLToken(XML_N_OFFICE_EXT),
252 XML_NAMESPACE_OFFICE_EXT );
253 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__ooo ) ), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
254 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__style) ),
255 GetXMLToken(XML_N_STYLE),
256 XML_NAMESPACE_STYLE );
257 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__text) ),
258 GetXMLToken(XML_N_TEXT),
259 XML_NAMESPACE_TEXT );
260 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__table ) ),
261 GetXMLToken(XML_N_TABLE),
262 XML_NAMESPACE_TABLE );
263 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__draw ) ),
264 GetXMLToken(XML_N_DRAW),
265 XML_NAMESPACE_DRAW );
266 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM (sXML_np__dr3d ) ),
267 GetXMLToken(XML_N_DR3D),
268 XML_NAMESPACE_DR3D );
269 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__fo) ),
270 GetXMLToken(XML_N_FO_COMPAT),
271 XML_NAMESPACE_FO );
272 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xlink) ),
273 GetXMLToken(XML_N_XLINK),
274 XML_NAMESPACE_XLINK );
275 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__dc) ),
276 GetXMLToken(XML_N_DC),
277 XML_NAMESPACE_DC );
278 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__dom ) ),
279 GetXMLToken(XML_N_DOM),
280 XML_NAMESPACE_DOM );
281 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__meta) ),
282 GetXMLToken(XML_N_META),
283 XML_NAMESPACE_META );
284 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__number) ),
285 GetXMLToken(XML_N_NUMBER),
286 XML_NAMESPACE_NUMBER );
287 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__svg) ),
288 GetXMLToken(XML_N_SVG_COMPAT),
289 XML_NAMESPACE_SVG );
290 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__chart) ),
291 GetXMLToken(XML_N_CHART),
292 XML_NAMESPACE_CHART );
293 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__math) ),
294 GetXMLToken(XML_N_MATH),
295 XML_NAMESPACE_MATH );
296 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_namespace_form) ),
297 GetXMLToken(XML_N_FORM),
298 XML_NAMESPACE_FORM );
299 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__script) ),
300 GetXMLToken(XML_N_SCRIPT),
301 XML_NAMESPACE_SCRIPT );
302 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__config) ),
303 GetXMLToken(XML_N_CONFIG),
304 XML_NAMESPACE_CONFIG );
305 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xforms) ),
306 GetXMLToken(XML_N_XFORMS_1_0),
307 XML_NAMESPACE_XFORMS );
308 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__formx) ),
309 GetXMLToken( XML_N_FORMX ),
310 XML_NAMESPACE_FORMX );
311 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xsd) ),
312 GetXMLToken(XML_N_XSD),
313 XML_NAMESPACE_XSD );
314 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xsi) ),
315 GetXMLToken(XML_N_XSI),
316 XML_NAMESPACE_XFORMS );
317 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__ooow ) ), GetXMLToken(XML_N_OOOW), XML_NAMESPACE_OOOW );
318 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__oooc ) ), GetXMLToken(XML_N_OOOC), XML_NAMESPACE_OOOC );
319 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__field ) ), GetXMLToken(XML_N_FIELD), XML_NAMESPACE_FIELD );
320 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__of ) ),
321 GetXMLToken(XML_N_OF), XML_NAMESPACE_OF );
322 mpNamespaceMap->Add(
323 OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xhtml ) ),
324 GetXMLToken(XML_N_XHTML), XML_NAMESPACE_XHTML );
327 msPackageProtocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package:" ) );
329 if (mxNumberFormatsSupplier.is())
330 mpNumImport = new SvXMLNumFmtHelper(mxNumberFormatsSupplier, getServiceFactory());
332 if (mxModel.is() && !mxEventListener.is())
334 mxEventListener.set(new SvXMLImportEventListener(this));
335 mxModel->addEventListener(mxEventListener);
338 ::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper;
342 // #110680#
343 SvXMLImport::SvXMLImport(
344 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
345 sal_uInt16 nImportFlags ) throw ()
346 : mpImpl( new SvXMLImport_Impl() ),
347 mpNamespaceMap( new SvXMLNamespaceMap ),
349 // #110680#
350 // pUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, MAP_100TH_MM ) ),
351 mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, MAP_100TH_MM, xServiceFactory ) ),
353 mpContexts( new SvXMLImportContexts_Impl ),
354 mpNumImport( NULL ),
355 mpProgressBarHelper( NULL ),
356 mpEventImportHelper( NULL ),
357 mpXMLErrors( NULL ),
358 mpStyleMap(0),
359 mnImportFlags( nImportFlags ),
360 mnErrorFlags(0),
361 // #110680#
362 mxServiceFactory(xServiceFactory),
363 mbIsFormsSupported( sal_True ),
364 mbIsTableShapeSupported( false ),
365 mbIsGraphicLoadOnDemandSupported( true )
367 DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
368 _InitCtor();
371 // #110680#
372 SvXMLImport::SvXMLImport(
373 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
374 const Reference< XModel > & rModel ) throw ()
375 : mxModel( rModel ),
376 mxNumberFormatsSupplier (rModel, uno::UNO_QUERY),
377 mpImpl( new SvXMLImport_Impl() ),
378 mpNamespaceMap( new SvXMLNamespaceMap ),
379 // #110680#
380 // pUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, MAP_100TH_MM ) ),
381 mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, MAP_100TH_MM, xServiceFactory ) ),
382 mpContexts( new SvXMLImportContexts_Impl ),
383 mpNumImport( NULL ),
384 mpProgressBarHelper( NULL ),
385 mpEventImportHelper( NULL ),
386 mpXMLErrors( NULL ),
387 mpStyleMap(0),
388 mnImportFlags( IMPORT_ALL ),
389 mnErrorFlags(0),
390 // #110680#
391 mxServiceFactory(xServiceFactory),
392 mbIsFormsSupported( sal_True ),
393 mbIsTableShapeSupported( false ),
394 mbIsGraphicLoadOnDemandSupported( true )
396 DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
397 _InitCtor();
400 // #110680#
401 SvXMLImport::SvXMLImport(
402 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
403 const Reference< XModel > & rModel,
404 const ::com::sun::star::uno::Reference< ::com::sun::star::document::XGraphicObjectResolver > & rGraphicObjects ) throw ()
405 : mxModel( rModel ),
406 mxNumberFormatsSupplier (rModel, uno::UNO_QUERY),
407 mxGraphicResolver( rGraphicObjects ),
408 mpImpl( new SvXMLImport_Impl() ),
409 mpNamespaceMap( new SvXMLNamespaceMap ),
410 // #110680#
411 // pUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, MAP_100TH_MM ) ),
412 mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, MAP_100TH_MM, xServiceFactory ) ),
413 mpContexts( new SvXMLImportContexts_Impl ),
414 mpNumImport( NULL ),
415 mpProgressBarHelper( NULL ),
416 mpEventImportHelper( NULL ),
417 mpXMLErrors( NULL ),
418 mpStyleMap(0),
419 mnImportFlags( IMPORT_ALL ),
420 mnErrorFlags(0),
421 // #110680#
422 mxServiceFactory(xServiceFactory),
423 mbIsFormsSupported( sal_True ),
424 mbIsGraphicLoadOnDemandSupported( true )
426 DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
427 _InitCtor();
430 SvXMLImport::~SvXMLImport() throw ()
432 delete mpXMLErrors;
433 delete mpNamespaceMap;
434 delete mpUnitConv;
435 delete mpEventImportHelper;
436 if( mpContexts )
438 while( mpContexts->Count() )
440 sal_uInt16 n = mpContexts->Count() - 1;
441 SvXMLImportContext *pContext = (*mpContexts)[n];
442 mpContexts->Remove( n, 1 );
443 if( pContext )
444 pContext->ReleaseRef();
446 delete mpContexts;
449 // delete pImageMapImportHelper;
451 // #i9518# the import component might not be deleted until after the document has been closed,
452 // so the stuff that accesses the document has been moved to endDocument.
454 // pNumImport is allocated in the ctor, so it must also be deleted here in case the component
455 // is created and deleted without actually importing.
456 delete mpNumImport;
457 delete mpProgressBarHelper;
459 xmloff::token::ResetTokens();
461 if( mpImpl )
462 delete mpImpl;
464 if (mxEventListener.is() && mxModel.is())
465 mxModel->removeEventListener(mxEventListener);
468 // XUnoTunnel & co
469 const uno::Sequence< sal_Int8 > & SvXMLImport::getUnoTunnelId() throw()
471 static uno::Sequence< sal_Int8 > * pSeq = 0;
472 if( !pSeq )
474 Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
475 if( !pSeq )
477 static uno::Sequence< sal_Int8 > aSeq( 16 );
478 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
479 pSeq = &aSeq;
482 return *pSeq;
485 SvXMLImport* SvXMLImport::getImplementation( uno::Reference< uno::XInterface > xInt ) throw()
487 uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
488 if( xUT.is() )
490 return
491 reinterpret_cast<SvXMLImport*>(
492 sal::static_int_cast<sal_IntPtr>(
493 xUT->getSomething( SvXMLImport::getUnoTunnelId())));
495 else
496 return NULL;
499 // XUnoTunnel
500 sal_Int64 SAL_CALL SvXMLImport::getSomething( const uno::Sequence< sal_Int8 >& rId )
501 throw( uno::RuntimeException )
503 if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
504 rId.getConstArray(), 16 ) )
506 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
508 return 0;
511 void SAL_CALL SvXMLImport::startDocument( void )
512 throw( xml::sax::SAXException, uno::RuntimeException )
514 RTL_LOGFILE_TRACE_AUTHOR( "xmloff", LOGFILE_AUTHOR, "{ SvXMLImport::startDocument" );
516 if( !mxGraphicResolver.is() || !mxEmbeddedResolver.is() )
518 Reference< lang::XMultiServiceFactory > xFactory( mxModel, UNO_QUERY );
519 if( xFactory.is() )
523 if( !mxGraphicResolver.is() )
525 mxGraphicResolver = Reference< XGraphicObjectResolver >::query(
526 xFactory->createInstance(
527 OUString(RTL_CONSTASCII_USTRINGPARAM(
528 // #99870# Import... instead of Export...
529 "com.sun.star.document.ImportGraphicObjectResolver"))));
530 mpImpl->mbOwnGraphicResolver = mxGraphicResolver.is();
533 if( !mxEmbeddedResolver.is() )
535 mxEmbeddedResolver = Reference< XEmbeddedObjectResolver >::query(
536 xFactory->createInstance(
537 OUString(RTL_CONSTASCII_USTRINGPARAM(
538 // #99870# Import... instead of Export...
539 "com.sun.star.document.ImportEmbeddedObjectResolver"))));
540 mpImpl->mbOwnEmbeddedResolver = mxEmbeddedResolver.is();
543 catch( com::sun::star::uno::Exception& )
550 void SAL_CALL SvXMLImport::endDocument( void )
551 throw( xml::sax::SAXException, uno::RuntimeException)
553 RTL_LOGFILE_TRACE_AUTHOR( "xmloff", LOGFILE_AUTHOR, "} SvXMLImport::startDocument" );
555 // #i9518# All the stuff that accesses the document has to be done here, not in the dtor,
556 // because the SvXMLImport dtor might not be called until after the document has been closed.
558 if (mpImpl->mpRDFaHelper.get())
560 const uno::Reference<rdf::XRepositorySupplier> xRS(mxModel,
561 uno::UNO_QUERY);
562 if (xRS.is())
564 mpImpl->mpRDFaHelper->InsertRDFa( xRS );
568 if (mpNumImport)
570 delete mpNumImport;
571 mpNumImport = NULL;
573 if (mxImportInfo.is())
575 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
576 if (xPropertySetInfo.is())
578 if (mpProgressBarHelper)
580 OUString sProgressMax(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSMAX));
581 OUString sProgressCurrent(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSCURRENT));
582 OUString sRepeat(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSREPEAT));
583 if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
584 xPropertySetInfo->hasPropertyByName(sProgressCurrent))
586 sal_Int32 nProgressMax(mpProgressBarHelper->GetReference());
587 sal_Int32 nProgressCurrent(mpProgressBarHelper->GetValue());
588 uno::Any aAny;
589 aAny <<= nProgressMax;
590 mxImportInfo->setPropertyValue(sProgressMax, aAny);
591 aAny <<= nProgressCurrent;
592 mxImportInfo->setPropertyValue(sProgressCurrent, aAny);
594 if (xPropertySetInfo->hasPropertyByName(sRepeat))
595 mxImportInfo->setPropertyValue(sRepeat, cppu::bool2any(mpProgressBarHelper->GetRepeat()));
596 // pProgressBarHelper is deleted in dtor
598 OUString sNumberStyles(RTL_CONSTASCII_USTRINGPARAM(XML_NUMBERSTYLES));
599 if (mxNumberStyles.is() && xPropertySetInfo->hasPropertyByName(sNumberStyles))
601 uno::Any aAny;
602 aAny <<= mxNumberStyles;
603 mxImportInfo->setPropertyValue(sNumberStyles, aAny);
608 if( mxFontDecls.Is() )
609 ((SvXMLStylesContext *)&mxFontDecls)->Clear();
610 if( mxStyles.Is() )
611 ((SvXMLStylesContext *)&mxStyles)->Clear();
612 if( mxAutoStyles.Is() )
613 ((SvXMLStylesContext *)&mxAutoStyles)->Clear();
614 if( mxMasterStyles.Is() )
615 ((SvXMLStylesContext *)&mxMasterStyles)->Clear();
617 // possible form-layer related knittings which can only be done when
618 // the whole document exists
619 if ( mxFormImport.is() )
620 mxFormImport->documentDone();
622 // The shape import helper does the z-order sorting in the dtor,
623 // so it must be deleted here, too.
624 mxShapeImport = NULL;
626 if( mpImpl->mbOwnGraphicResolver )
628 Reference< lang::XComponent > xComp( mxGraphicResolver, UNO_QUERY );
629 xComp->dispose();
632 if( mpImpl->mbOwnEmbeddedResolver )
634 Reference< lang::XComponent > xComp( mxEmbeddedResolver, UNO_QUERY );
635 xComp->dispose();
637 if( mpStyleMap )
639 mpStyleMap->release();
640 mpStyleMap = 0;
643 if ( mpXMLErrors != NULL )
645 mpXMLErrors->ThrowErrorAsSAXException( XMLERROR_FLAG_SEVERE );
649 void SAL_CALL SvXMLImport::startElement( const OUString& rName,
650 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
651 throw(xml::sax::SAXException, uno::RuntimeException)
653 SvXMLNamespaceMap *pRewindMap = 0;
655 // Process namespace attributes. This must happen before creating the
656 // context, because namespace decaration apply to the element name itself.
657 INT16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
658 for( INT16 i=0; i < nAttrCount; i++ )
660 const OUString& rAttrName = xAttrList->getNameByIndex( i );
661 if ( rAttrName.equalsAscii("office:version") )
663 mpImpl->aODFVersion = xAttrList->getValueByIndex( i );
665 // the ODF version in content.xml and manifest.xml must be the same starting from ODF1.2
666 if ( mpImpl->mStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "content.xml" ) ) )
667 && !IsODFVersionConsistent( mpImpl->aODFVersion ) )
669 throw xml::sax::SAXException(
670 ::rtl::OUString(
671 RTL_CONSTASCII_USTRINGPARAM( "Inconsistent ODF versions in content.xml and manifest.xml!" ) ),
672 uno::Reference< uno::XInterface >(),
673 uno::makeAny(
674 packages::zip::ZipIOException(
675 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
676 "Inconsistent ODF versions in content.xml and manifest.xml!" ) ),
677 Reference< XInterface >() ) ) );
680 else if( ( rAttrName.getLength() >= 5 ) &&
681 ( rAttrName.compareToAscii( sXML_xmlns, 5 ) == 0 ) &&
682 ( rAttrName.getLength() == 5 || ':' == rAttrName[5] ) )
684 if( !pRewindMap )
686 pRewindMap = mpNamespaceMap;
687 mpNamespaceMap = new SvXMLNamespaceMap( *mpNamespaceMap );
689 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
691 OUString aPrefix( ( rAttrName.getLength() == 5 )
692 ? OUString()
693 : rAttrName.copy( 6 ) );
694 // Add namespace, but only if it is known.
695 sal_uInt16 nKey = mpNamespaceMap->AddIfKnown( aPrefix, rAttrValue );
696 // If namespace is unknwon, try to match a name with similar
697 // TC Id an version
698 if( XML_NAMESPACE_UNKNOWN == nKey )
700 OUString aTestName( rAttrValue );
701 if( SvXMLNamespaceMap::NormalizeURI( aTestName ) )
702 nKey = mpNamespaceMap->AddIfKnown( aPrefix, aTestName );
704 // If that namespace is not known, too, add it as unknown
705 if( XML_NAMESPACE_UNKNOWN == nKey )
706 mpNamespaceMap->Add( aPrefix, rAttrValue );
711 // Get element's namespace and local name.
712 OUString aLocalName;
713 USHORT nPrefix =
714 mpNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
716 // If there are contexts already, call a CreateChildContext at the topmost
717 // context. Otherwise, create a default context.
718 SvXMLImportContext *pContext;
719 USHORT nCount = mpContexts->Count();
720 if( nCount > 0 )
722 pContext = (*mpContexts)[nCount - 1]->CreateChildContext( nPrefix,
723 aLocalName,
724 xAttrList );
725 DBG_ASSERT( pContext && pContext->GetPrefix() == nPrefix,
726 "SvXMLImport::startElement: created context has wrong prefix" );
728 else
730 #ifdef TIMELOG
731 // If we do profiling, we want a trace message for the first element
732 // in order to identify the stream.
733 ByteString aString( (String)rName, RTL_TEXTENCODING_ASCII_US );
734 RTL_LOGFILE_TRACE_AUTHOR1( "xmloff", LOGFILE_AUTHOR,
735 "SvXMLImport::StartElement( \"%s\", ... )",
736 aString.GetBuffer() );
737 #endif
739 pContext = CreateContext( nPrefix, aLocalName, xAttrList );
740 if( (nPrefix & XML_NAMESPACE_UNKNOWN_FLAG) != 0 &&
741 IS_TYPE( SvXMLImportContext, pContext ) )
743 OUString aMsg( RTL_CONSTASCII_USTRINGPARAM( "Root element unknown" ) );
744 Reference<xml::sax::XLocator> xDummyLocator;
745 Sequence < OUString > aParams(1);
746 aParams.getArray()[0] = rName;
748 SetError( XMLERROR_FLAG_SEVERE|XMLERROR_UNKNWON_ROOT,
749 aParams, aMsg, xDummyLocator );
753 DBG_ASSERT( pContext, "SvXMLImport::startElement: missing context" );
754 if( !pContext )
755 pContext = new SvXMLImportContext( *this, nPrefix, aLocalName );
757 pContext->AddRef();
759 // Remeber old namespace map.
760 if( pRewindMap )
761 pContext->SetRewindMap( pRewindMap );
763 // Call a startElement at the new context.
764 pContext->StartElement( xAttrList );
766 // Push context on stack.
767 mpContexts->Insert( pContext, nCount );
770 SvXMLImportContext *SvXMLImport::getTopContext() {
771 USHORT nCount = mpContexts->Count();
772 if (nCount>0) {
773 SvXMLImportContext *pContext = (*mpContexts)[nCount-1];
774 return pContext;
775 } else {
776 return NULL;
780 SvXMLImportContext *SvXMLImport::createUnknownContext( USHORT nPrefix,
781 const ::rtl::OUString& rLocalName,
782 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
784 bool bProcessContent=true;
785 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
786 for(sal_Int16 a=0; a < nAttrCount; a++)
788 const OUString& rAttrName = xAttrList->getNameByIndex(a);
789 OUString aLocalName;
790 sal_uInt16 _nPrefix = GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
791 const OUString aValue( xAttrList->getValueByIndex(a) );
792 if (_nPrefix==XML_NAMESPACE_OFFICE && IsXMLToken( aLocalName, XML_PROCESS_CONTENT ) ) {
793 bProcessContent=!aValue.equalsIgnoreAsciiCaseAscii("false");
796 SvXMLImportContext *ret=NULL;
797 if (bProcessContent) {
798 ret=getTopContext();
800 if (ret==NULL) {
801 ret=new SvXMLImportContext( *this, nPrefix, rLocalName );
803 return ret;
806 void SAL_CALL SvXMLImport::endElement( const OUString&
807 #ifndef PRODUCT
808 rName
809 #endif
811 throw(xml::sax::SAXException, uno::RuntimeException)
813 USHORT nCount = mpContexts->Count();
814 DBG_ASSERT( nCount, "SvXMLImport::endElement: no context left" );
815 if( nCount > 0 )
817 // Get topmost context and remove it from the stack.
818 SvXMLImportContext *pContext = (*mpContexts)[nCount-1];
819 mpContexts->Remove( nCount-1, 1 );
821 #ifndef PRODUCT
822 // Non product only: check if endElement call matches startELement call.
823 OUString aLocalName;
824 USHORT nPrefix =
825 mpNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
826 DBG_ASSERT( pContext->GetPrefix() == nPrefix,
827 "SvXMLImport::endElement: popped context has wrong prefix" );
828 DBG_ASSERT( pContext->GetLocalName() == aLocalName,
829 "SvXMLImport::endElement: popped context has wrong lname" );
830 #endif
832 // Call a EndElement at the current context.
833 pContext->EndElement();
835 // Get a namespace map to rewind.
836 SvXMLNamespaceMap *pRewindMap = pContext->GetRewindMap();
838 // Delete the current context.
839 pContext->ReleaseRef();
840 pContext = 0;
842 // Rewind a namespace map.
843 if( pRewindMap )
845 delete mpNamespaceMap;
846 mpNamespaceMap = pRewindMap;
851 void SAL_CALL SvXMLImport::characters( const OUString& rChars )
852 throw(xml::sax::SAXException, uno::RuntimeException)
854 USHORT nCount = mpContexts->Count();
855 if( nCount > 0 )
857 (*mpContexts)[nCount - 1]->Characters( rChars );
861 void SAL_CALL SvXMLImport::ignorableWhitespace( const OUString& )
862 throw(xml::sax::SAXException, uno::RuntimeException)
866 void SAL_CALL SvXMLImport::processingInstruction( const OUString&,
867 const OUString& )
868 throw(xml::sax::SAXException, uno::RuntimeException)
872 void SAL_CALL SvXMLImport::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& rLocator )
873 throw(xml::sax::SAXException, uno::RuntimeException)
875 mxLocator = rLocator;
878 // XExtendedDocumentHandler
879 void SAL_CALL SvXMLImport::startCDATA( void ) throw(xml::sax::SAXException, uno::RuntimeException)
883 void SAL_CALL SvXMLImport::endCDATA( void ) throw(uno::RuntimeException)
887 void SAL_CALL SvXMLImport::comment( const OUString& )
888 throw(xml::sax::SAXException, uno::RuntimeException)
892 void SAL_CALL SvXMLImport::allowLineBreak( void )
893 throw(xml::sax::SAXException, uno::RuntimeException)
897 void SAL_CALL SvXMLImport::unknown( const OUString& )
898 throw(xml::sax::SAXException, uno::RuntimeException)
902 void SvXMLImport::SetStatistics(const uno::Sequence< beans::NamedValue> &)
904 GetProgressBarHelper()->SetRepeat(sal_False);
905 GetProgressBarHelper()->SetReference(0);
908 ///////////////////////////////////////////////////////////////////////
910 // XImporter
911 void SAL_CALL SvXMLImport::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
912 throw(lang::IllegalArgumentException, uno::RuntimeException)
914 mxModel = uno::Reference< frame::XModel >::query( xDoc );
915 if( !mxModel.is() )
916 throw lang::IllegalArgumentException();
917 if (mxModel.is() && !mxEventListener.is())
919 mxEventListener.set(new SvXMLImportEventListener(this));
920 mxModel->addEventListener(mxEventListener);
923 DBG_ASSERT( !mpNumImport, "number format import already exists." );
924 if( mpNumImport )
926 delete mpNumImport;
927 mpNumImport = 0;
931 // XFilter
932 sal_Bool SAL_CALL SvXMLImport::filter( const uno::Sequence< beans::PropertyValue >& )
933 throw (uno::RuntimeException)
935 return sal_False;
938 void SAL_CALL SvXMLImport::cancel( )
939 throw (uno::RuntimeException)
943 // XInitialize
944 void SAL_CALL SvXMLImport::initialize( const uno::Sequence< uno::Any >& aArguments )
945 throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
947 const sal_Int32 nAnyCount = aArguments.getLength();
948 const uno::Any* pAny = aArguments.getConstArray();
950 for( sal_Int32 nIndex = 0; nIndex < nAnyCount; nIndex++, pAny++ )
952 Reference<XInterface> xValue;
953 *pAny >>= xValue;
955 uno::Reference<task::XStatusIndicator> xTmpStatusIndicator(
956 xValue, UNO_QUERY );
957 if( xTmpStatusIndicator.is() )
958 mxStatusIndicator = xTmpStatusIndicator;
960 uno::Reference<document::XGraphicObjectResolver> xTmpGraphicResolver(
961 xValue, UNO_QUERY );
962 if( xTmpGraphicResolver.is() )
963 mxGraphicResolver = xTmpGraphicResolver;
965 uno::Reference<document::XEmbeddedObjectResolver> xTmpObjectResolver(
966 xValue, UNO_QUERY );
967 if( xTmpObjectResolver.is() )
968 mxEmbeddedResolver = xTmpObjectResolver;
970 uno::Reference<beans::XPropertySet> xTmpPropSet( xValue, UNO_QUERY );
971 if( xTmpPropSet.is() )
973 mxImportInfo = xTmpPropSet;
974 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
975 if (xPropertySetInfo.is())
977 OUString sPropName(RTL_CONSTASCII_USTRINGPARAM(XML_NUMBERSTYLES));
978 if (xPropertySetInfo->hasPropertyByName(sPropName))
980 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
981 aAny >>= mxNumberStyles;
984 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("PrivateData" ) );
985 if (xPropertySetInfo->hasPropertyByName(sPropName))
987 Reference < XInterface > xIfc;
988 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
989 aAny >>= xIfc;
991 StyleMap *pSMap = StyleMap::getImplementation( xIfc );
992 if( pSMap )
994 mpStyleMap = pSMap;
995 mpStyleMap->acquire();
998 OUString sBaseURI;
999 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("BaseURI" ) );
1000 if (xPropertySetInfo->hasPropertyByName(sPropName))
1002 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1003 aAny >>= sBaseURI;
1004 mpImpl->aBaseURL.SetURL( sBaseURI );
1005 mpImpl->aDocBase.SetURL( sBaseURI );
1007 OUString sRelPath;
1008 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("StreamRelPath" ) );
1009 if( xPropertySetInfo->hasPropertyByName(sPropName) )
1011 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1012 aAny >>= sRelPath;
1014 OUString sName;
1015 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("StreamName" ) );
1016 if( xPropertySetInfo->hasPropertyByName(sPropName) )
1018 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1019 aAny >>= sName;
1021 if( sBaseURI.getLength() && sName.getLength() )
1023 if( sRelPath.getLength() )
1024 mpImpl->aBaseURL.insertName( sRelPath );
1025 mpImpl->aBaseURL.insertName( sName );
1027 mpImpl->mStreamName = sName; // Note: may be empty (XSLT)
1028 // --> OD 2004-08-10 #i28749# - retrieve property <ShapePositionInHoriL2R>
1029 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("ShapePositionInHoriL2R" ) );
1030 if( xPropertySetInfo->hasPropertyByName(sPropName) )
1032 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1033 aAny >>= (mpImpl->mbShapePositionInHoriL2R);
1035 // <--
1036 // --> OD 2007-12-19 #152540#
1037 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("TextDocInOOoFileFormat" ) );
1038 if( xPropertySetInfo->hasPropertyByName(sPropName) )
1040 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1041 aAny >>= (mpImpl->mbTextDocInOOoFileFormat);
1043 // <--
1049 // XServiceInfo
1050 OUString SAL_CALL SvXMLImport::getImplementationName()
1051 throw(uno::RuntimeException)
1053 OUString aStr;
1054 return aStr;
1057 sal_Bool SAL_CALL SvXMLImport::supportsService( const OUString& rServiceName )
1058 throw(::com::sun::star::uno::RuntimeException)
1060 return
1061 rServiceName.equalsAsciiL(
1062 "com.sun.star.document.ImportFilter",
1063 sizeof("com.sun.star.document.ImportFilter")-1 ) ||
1064 rServiceName.equalsAsciiL(
1065 "com.sun.star.xml.XMLImportFilter",
1066 sizeof("com.sun.star.xml.XMLImportFilter")-1);
1069 uno::Sequence< OUString > SAL_CALL SvXMLImport::getSupportedServiceNames( )
1070 throw(uno::RuntimeException)
1072 uno::Sequence<OUString> aSeq(2);
1073 aSeq[0] = OUString(
1074 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ImportFilter"));
1075 aSeq[1] = OUString(
1076 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.XMLImportFilter"));
1077 return aSeq;
1080 ///////////////////////////////////////////////////////////////////////
1082 XMLTextImportHelper* SvXMLImport::CreateTextImport()
1084 return new XMLTextImportHelper( mxModel, *this );
1087 XMLShapeImportHelper* SvXMLImport::CreateShapeImport()
1089 return new XMLShapeImportHelper( *this, mxModel );
1092 #ifndef SVX_LIGHT
1093 SchXMLImportHelper* SvXMLImport::CreateChartImport()
1095 return new SchXMLImportHelper();
1097 #endif
1099 #ifndef SVX_LIGHT
1100 ::xmloff::OFormLayerXMLImport* SvXMLImport::CreateFormImport()
1102 return new ::xmloff::OFormLayerXMLImport(*this);
1104 #endif // #ifndef SVX_LIGHT
1107 ///////////////////////////////////////////////////////////////////////////////
1109 // Get or create fill/line/lineend-style-helper
1112 const Reference< container::XNameContainer > & SvXMLImport::GetGradientHelper()
1114 if( !mxGradientHelper.is() )
1116 if( mxModel.is() )
1118 Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1119 if( xServiceFact.is() )
1123 mxGradientHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1124 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.GradientTable" ) ) ), UNO_QUERY);
1126 catch( lang::ServiceNotRegisteredException& )
1132 return mxGradientHelper;
1135 const Reference< container::XNameContainer > & SvXMLImport::GetHatchHelper()
1137 if( !mxHatchHelper.is() )
1139 if( mxModel.is() )
1141 Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1142 if( xServiceFact.is() )
1146 mxHatchHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1147 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.HatchTable" ) ) ), UNO_QUERY);
1149 catch( lang::ServiceNotRegisteredException& )
1155 return mxHatchHelper;
1158 const Reference< container::XNameContainer > & SvXMLImport::GetBitmapHelper()
1160 if( !mxBitmapHelper.is() )
1162 if( mxModel.is() )
1164 Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1165 if( xServiceFact.is() )
1169 mxBitmapHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1170 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.BitmapTable" ) ) ), UNO_QUERY);
1172 catch( lang::ServiceNotRegisteredException& )
1178 return mxBitmapHelper;
1181 const Reference< container::XNameContainer > & SvXMLImport::GetTransGradientHelper()
1183 if( !mxTransGradientHelper.is() )
1185 if( mxModel.is() )
1187 Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1188 if( xServiceFact.is() )
1192 mxTransGradientHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1193 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.TransparencyGradientTable" ) ) ), UNO_QUERY);
1195 catch( lang::ServiceNotRegisteredException& )
1201 return mxTransGradientHelper;
1204 const Reference< container::XNameContainer > & SvXMLImport::GetMarkerHelper()
1206 if( !mxMarkerHelper.is() )
1208 if( mxModel.is() )
1210 Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1211 if( xServiceFact.is() )
1215 mxMarkerHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1216 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.MarkerTable" ) ) ), UNO_QUERY);
1218 catch( lang::ServiceNotRegisteredException& )
1224 return mxMarkerHelper;
1227 const Reference< container::XNameContainer > & SvXMLImport::GetDashHelper()
1229 if( !mxDashHelper.is() )
1231 if( mxModel.is() )
1233 Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1234 if( xServiceFact.is() )
1238 mxDashHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1239 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DashTable" ) ) ), UNO_QUERY);
1241 catch( lang::ServiceNotRegisteredException& )
1247 return mxDashHelper;
1250 sal_Bool SvXMLImport::IsPackageURL( const ::rtl::OUString& rURL ) const
1253 // if, and only if, only parts are imported, then we're in a package
1254 const sal_uInt32 nTest = IMPORT_META|IMPORT_STYLES|IMPORT_CONTENT|IMPORT_SETTINGS;
1255 if( (mnImportFlags & nTest) == nTest )
1256 return sal_False;
1258 // Some quick tests: Some may rely on the package structure!
1259 sal_Int32 nLen = rURL.getLength();
1260 if( (nLen > 0 && '/' == rURL[0]) )
1261 // RFC2396 net_path or abs_path
1262 return sal_False;
1263 else if( nLen > 1 && '.' == rURL[0] )
1265 if( '.' == rURL[1] )
1266 // ../: We are never going up one level, so we know
1267 // it's not an external URI
1268 return sal_False;
1269 else if( '/' == rURL[1] )
1270 // we are remaining on a level, so it's an package URI
1271 return sal_True;
1274 // Now check for a RFC2396 schema
1275 sal_Int32 nPos = 1;
1276 while( nPos < nLen )
1278 switch( rURL[nPos] )
1280 case '/':
1281 // a relative path segement
1282 return sal_True;
1283 case ':':
1284 // a schema
1285 return sal_False;
1286 default:
1287 break;
1288 // we don't care about any other characters
1290 ++nPos;
1293 return sal_True;
1296 ::rtl::OUString SvXMLImport::ResolveGraphicObjectURL( const ::rtl::OUString& rURL,
1297 sal_Bool bLoadOnDemand )
1299 ::rtl::OUString sRet;
1301 if( IsPackageURL( rURL ) )
1303 if( !bLoadOnDemand && mxGraphicResolver.is() )
1305 ::rtl::OUString aTmp( msPackageProtocol );
1306 aTmp += rURL;
1307 sRet = mxGraphicResolver->resolveGraphicObjectURL( aTmp );
1310 if( !sRet.getLength() )
1312 sRet = msPackageProtocol;
1313 sRet += rURL;
1317 if( !sRet.getLength() )
1318 sRet = GetAbsoluteReference( rURL );
1320 return sRet;
1323 Reference< XOutputStream > SvXMLImport::GetStreamForGraphicObjectURLFromBase64()
1325 Reference< XOutputStream > xOStm;
1326 Reference< document::XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
1328 if( xStmResolver.is() )
1329 xOStm = xStmResolver->createOutputStream();
1331 return xOStm;
1334 ::rtl::OUString SvXMLImport::ResolveGraphicObjectURLFromBase64(
1335 const Reference < XOutputStream >& rOut )
1337 OUString sURL;
1338 Reference< document::XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
1339 if( xStmResolver.is() )
1340 sURL = xStmResolver->resolveOutputStream( rOut );
1342 return sURL;
1345 ::rtl::OUString SvXMLImport::ResolveEmbeddedObjectURL(
1346 const ::rtl::OUString& rURL,
1347 const ::rtl::OUString& rClassId )
1349 ::rtl::OUString sRet;
1351 if( IsPackageURL( rURL ) )
1353 if ( mxEmbeddedResolver.is() )
1355 OUString sURL( rURL );
1356 if( rClassId.getLength() )
1358 sURL += OUString( sal_Unicode('!') );
1359 sURL += rClassId;
1361 sRet = mxEmbeddedResolver->resolveEmbeddedObjectURL( sURL );
1364 else
1365 sRet = GetAbsoluteReference( rURL );
1367 return sRet;
1370 Reference < XOutputStream >
1371 SvXMLImport::GetStreamForEmbeddedObjectURLFromBase64()
1373 Reference < XOutputStream > xOLEStream;
1375 if( mxEmbeddedResolver.is() )
1377 Reference< XNameAccess > xNA( mxEmbeddedResolver, UNO_QUERY );
1378 if( xNA.is() )
1380 OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "Obj12345678" ) );
1381 Any aAny = xNA->getByName( aURL );
1382 aAny >>= xOLEStream;
1386 return xOLEStream;
1389 ::rtl::OUString SvXMLImport::ResolveEmbeddedObjectURLFromBase64()
1391 ::rtl::OUString sRet;
1393 if( mxEmbeddedResolver.is() )
1395 OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "Obj12345678" ) );
1396 sRet = mxEmbeddedResolver->resolveEmbeddedObjectURL( aURL );
1399 return sRet;
1402 void SvXMLImport::AddStyleDisplayName( sal_uInt16 nFamily,
1403 const OUString& rName,
1404 const OUString& rDisplayName )
1406 if( !mpStyleMap )
1408 mpStyleMap = new StyleMap;
1409 mpStyleMap->acquire();
1410 if( mxImportInfo.is() )
1412 OUString sPrivateData(
1413 RTL_CONSTASCII_USTRINGPARAM("PrivateData" ) );
1414 Reference< beans::XPropertySetInfo > xPropertySetInfo =
1415 mxImportInfo->getPropertySetInfo();
1416 if( xPropertySetInfo.is() &&
1417 xPropertySetInfo->hasPropertyByName(sPrivateData) )
1419 Reference < XInterface > xIfc(
1420 static_cast< XUnoTunnel *>( mpStyleMap ) );
1421 Any aAny;
1422 aAny <<= xIfc;
1423 mxImportInfo->setPropertyValue( sPrivateData, aAny );
1428 StyleMap::key_type aKey( nFamily, rName );
1429 StyleMap::value_type aValue( aKey, rDisplayName );
1430 ::std::pair<StyleMap::iterator,bool> aRes( mpStyleMap->insert( aValue ) );
1431 OSL_ENSURE( aRes.second, "duplicate style name" );
1435 OUString SvXMLImport::GetStyleDisplayName( sal_uInt16 nFamily,
1436 const OUString& rName ) const
1438 OUString sName( rName );
1439 if( mpStyleMap && rName.getLength() )
1441 StyleMap::key_type aKey( nFamily, rName );
1442 StyleMap::const_iterator aIter = mpStyleMap->find( aKey );
1443 if( aIter != mpStyleMap->end() )
1444 sName = (*aIter).second;
1446 return sName;
1449 void SvXMLImport::SetViewSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&)
1453 void SvXMLImport::SetConfigurationSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&)
1457 void SvXMLImport::SetDocumentSpecificSettings(const ::rtl::OUString& _rSettingsGroupName, const uno::Sequence<beans::PropertyValue>& _rSettings)
1459 (void)_rSettingsGroupName;
1460 (void)_rSettings;
1463 ProgressBarHelper* SvXMLImport::GetProgressBarHelper()
1465 if (!mpProgressBarHelper)
1467 mpProgressBarHelper = new ProgressBarHelper(mxStatusIndicator, sal_False);
1469 if (mxImportInfo.is())
1471 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
1472 if (xPropertySetInfo.is())
1474 OUString sProgressRange(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSRANGE));
1475 OUString sProgressMax(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSMAX));
1476 OUString sProgressCurrent(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSCURRENT));
1477 OUString sRepeat(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSREPEAT));
1478 if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
1479 xPropertySetInfo->hasPropertyByName(sProgressCurrent) &&
1480 xPropertySetInfo->hasPropertyByName(sProgressRange))
1482 uno::Any aAny;
1483 sal_Int32 nProgressMax(0);
1484 sal_Int32 nProgressCurrent(0);
1485 sal_Int32 nProgressRange(0);
1486 aAny = mxImportInfo->getPropertyValue(sProgressRange);
1487 if (aAny >>= nProgressRange)
1488 mpProgressBarHelper->SetRange(nProgressRange);
1489 aAny = mxImportInfo->getPropertyValue(sProgressMax);
1490 if (aAny >>= nProgressMax)
1491 mpProgressBarHelper->SetReference(nProgressMax);
1492 aAny = mxImportInfo->getPropertyValue(sProgressCurrent);
1493 if (aAny >>= nProgressCurrent)
1494 mpProgressBarHelper->SetValue(nProgressCurrent);
1496 if (xPropertySetInfo->hasPropertyByName(sRepeat))
1498 uno::Any aAny = mxImportInfo->getPropertyValue(sRepeat);
1499 if (aAny.getValueType() == getBooleanCppuType())
1500 mpProgressBarHelper->SetRepeat(::cppu::any2bool(aAny));
1501 else {
1502 DBG_ERRORFILE("why is it no boolean?");
1508 return mpProgressBarHelper;
1511 void SvXMLImport::AddNumberStyle(sal_Int32 nKey, const OUString& rName)
1513 if (!mxNumberStyles.is())
1514 mxNumberStyles = uno::Reference< container::XNameContainer >( comphelper::NameContainer_createInstance( ::getCppuType((const sal_Int32*)0)) );
1515 if (mxNumberStyles.is())
1517 uno::Any aAny;
1518 aAny <<= nKey;
1521 mxNumberStyles->insertByName(rName, aAny);
1523 catch ( uno::Exception& )
1525 DBG_ERROR("Numberformat could not be inserted");
1528 else {
1529 DBG_ERROR("not possible to create NameContainer");
1533 XMLEventImportHelper& SvXMLImport::GetEventImport()
1535 #ifndef SVX_LIGHT
1536 if (!mpEventImportHelper)
1538 // construct event helper and register StarBasic handler and standard
1539 // event tables
1540 mpEventImportHelper = new XMLEventImportHelper();
1541 OUString sStarBasic(GetXMLToken(XML_STARBASIC));
1542 mpEventImportHelper->RegisterFactory(sStarBasic,
1543 new XMLStarBasicContextFactory());
1544 OUString sScript(GetXMLToken(XML_SCRIPT));
1545 mpEventImportHelper->RegisterFactory(sScript,
1546 new XMLScriptContextFactory());
1547 mpEventImportHelper->AddTranslationTable(aStandardEventTable);
1549 // register StarBasic event handler with capitalized spelling
1550 OUString sStarBasicCap(RTL_CONSTASCII_USTRINGPARAM("StarBasic"));
1551 mpEventImportHelper->RegisterFactory(sStarBasicCap,
1552 new XMLStarBasicContextFactory());
1554 #endif
1556 return *mpEventImportHelper;
1559 void SvXMLImport::SetFontDecls( XMLFontStylesContext *pFontDecls )
1561 mxFontDecls = pFontDecls;
1562 GetTextImport()->SetFontDecls( pFontDecls );
1565 void SvXMLImport::SetStyles( SvXMLStylesContext *pStyles )
1567 mxStyles = pStyles;
1570 void SvXMLImport::SetAutoStyles( SvXMLStylesContext *pAutoStyles )
1572 if (pAutoStyles && mxNumberStyles.is() && (mnImportFlags & IMPORT_CONTENT) )
1574 uno::Reference<xml::sax::XAttributeList> xAttrList;
1575 uno::Sequence< ::rtl::OUString > aNames = mxNumberStyles->getElementNames();
1576 sal_uInt32 nCount(aNames.getLength());
1577 if (nCount)
1579 const OUString* pNames = aNames.getConstArray();
1580 if ( pNames )
1582 SvXMLStyleContext* pContext;
1583 uno::Any aAny;
1584 sal_Int32 nKey(0);
1585 for (sal_uInt32 i = 0; i < nCount; i++, pNames++)
1587 aAny = mxNumberStyles->getByName(*pNames);
1588 if (aAny >>= nKey)
1590 pContext = new SvXMLNumFormatContext( *this, XML_NAMESPACE_NUMBER,
1591 *pNames, xAttrList, nKey, *pAutoStyles );
1592 pAutoStyles->AddStyle(*pContext);
1598 mxAutoStyles = pAutoStyles;
1599 GetTextImport()->SetAutoStyles( pAutoStyles );
1600 GetShapeImport()->SetAutoStylesContext( pAutoStyles );
1601 #ifndef SVX_LIGHT
1602 GetChartImport()->SetAutoStylesContext( pAutoStyles );
1603 GetFormImport()->setAutoStyleContext( pAutoStyles );
1604 #endif
1607 void SvXMLImport::SetMasterStyles( SvXMLStylesContext *pMasterStyles )
1609 mxMasterStyles = pMasterStyles;
1612 XMLFontStylesContext *SvXMLImport::GetFontDecls()
1614 return (XMLFontStylesContext *)&mxFontDecls;
1617 SvXMLStylesContext *SvXMLImport::GetStyles()
1619 return (SvXMLStylesContext *)&mxStyles;
1622 SvXMLStylesContext *SvXMLImport::GetAutoStyles()
1624 return (SvXMLStylesContext *)&mxAutoStyles;
1627 SvXMLStylesContext *SvXMLImport::GetMasterStyles()
1629 return (SvXMLStylesContext *)&mxMasterStyles;
1632 const XMLFontStylesContext *SvXMLImport::GetFontDecls() const
1634 return (const XMLFontStylesContext *)&mxFontDecls;
1637 const SvXMLStylesContext *SvXMLImport::GetStyles() const
1639 return (const SvXMLStylesContext *)&mxStyles;
1642 const SvXMLStylesContext *SvXMLImport::GetAutoStyles() const
1644 return (const SvXMLStylesContext *)&mxAutoStyles;
1647 const SvXMLStylesContext *SvXMLImport::GetMasterStyles() const
1649 return (const SvXMLStylesContext *)&mxMasterStyles;
1652 OUString SvXMLImport::GetAbsoluteReference(const OUString& rValue) const
1654 if( rValue.getLength() == 0 || rValue[0] == '#' )
1655 return rValue;
1657 INetURLObject aAbsURL;
1658 if( mpImpl->aBaseURL.GetNewAbsURL( rValue, &aAbsURL ) )
1659 return aAbsURL.GetMainURL( INetURLObject::DECODE_TO_IURI );
1660 else
1661 return rValue;
1664 sal_Bool SvXMLImport::IsODFVersionConsistent( const ::rtl::OUString& aODFVersion )
1666 // the check returns sal_False only if the storage version could be retrieved
1667 sal_Bool bResult = sal_True;
1669 if ( aODFVersion.getLength() && aODFVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
1671 // check the consistency only for the ODF1.2 and later ( according to content.xml )
1674 uno::Reference< document::XStorageBasedDocument > xDoc( mxModel, uno::UNO_QUERY_THROW );
1675 uno::Reference< embed::XStorage > xStor = xDoc->getDocumentStorage();
1676 uno::Reference< beans::XPropertySet > xStorProps( xStor, uno::UNO_QUERY_THROW );
1678 // the check should be done only for OASIS format
1679 ::rtl::OUString aMediaType;
1680 xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ) >>= aMediaType;
1681 if ( ::comphelper::OStorageHelper::GetXStorageFormat( xStor ) >= SOFFICE_FILEFORMAT_8 )
1683 sal_Bool bRepairPackage = sal_False;
1686 xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RepairPackage" ) ) )
1687 >>= bRepairPackage;
1688 } catch ( uno::Exception& )
1691 // check only if not in Repair mode
1692 if ( !bRepairPackage )
1694 ::rtl::OUString aStorVersion;
1695 xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) )
1696 >>= aStorVersion;
1697 bResult = aODFVersion.equals( aStorVersion );
1701 catch( uno::Exception& )
1705 return bResult;
1708 void SvXMLImport::_CreateNumberFormatsSupplier()
1710 DBG_ASSERT( !mxNumberFormatsSupplier.is(),
1711 "number formats supplier already exists!" );
1712 if(mxModel.is())
1713 mxNumberFormatsSupplier =
1714 uno::Reference< util::XNumberFormatsSupplier> (mxModel, uno::UNO_QUERY);
1718 void SvXMLImport::_CreateDataStylesImport()
1720 DBG_ASSERT( mpNumImport == NULL, "data styles import already exists!" );
1721 uno::Reference<util::XNumberFormatsSupplier> xNum =
1722 GetNumberFormatsSupplier();
1723 if ( xNum.is() )
1724 mpNumImport = new SvXMLNumFmtHelper(xNum, getServiceFactory());
1728 sal_Unicode SvXMLImport::ConvStarBatsCharToStarSymbol( sal_Unicode c )
1730 sal_Unicode cNew = c;
1731 if( !mpImpl->hBatsFontConv )
1733 OUString sStarBats( RTL_CONSTASCII_USTRINGPARAM( "StarBats" ) );
1734 mpImpl->hBatsFontConv = CreateFontToSubsFontConverter( sStarBats,
1735 FONTTOSUBSFONT_IMPORT|FONTTOSUBSFONT_ONLYOLDSOSYMBOLFONTS );
1736 OSL_ENSURE( mpImpl->hBatsFontConv, "Got no symbol font converter" );
1738 if( mpImpl->hBatsFontConv )
1740 cNew = ConvertFontToSubsFontChar( mpImpl->hBatsFontConv, c );
1743 return cNew;
1746 sal_Unicode SvXMLImport::ConvStarMathCharToStarSymbol( sal_Unicode c )
1748 sal_Unicode cNew = c;
1749 if( !mpImpl->hMathFontConv )
1751 OUString sStarMath( RTL_CONSTASCII_USTRINGPARAM( "StarMath" ) );
1752 mpImpl->hMathFontConv = CreateFontToSubsFontConverter( sStarMath,
1753 FONTTOSUBSFONT_IMPORT|FONTTOSUBSFONT_ONLYOLDSOSYMBOLFONTS );
1754 OSL_ENSURE( mpImpl->hMathFontConv, "Got no symbol font converter" );
1756 if( mpImpl->hMathFontConv )
1758 cNew = ConvertFontToSubsFontChar( mpImpl->hMathFontConv, c );
1761 return cNew;
1766 void SvXMLImport::SetError(
1767 sal_Int32 nId,
1768 const Sequence<OUString>& rMsgParams,
1769 const OUString& rExceptionMessage,
1770 const Reference<xml::sax::XLocator>& rLocator )
1772 // maintain error flags
1773 if ( ( nId & XMLERROR_FLAG_ERROR ) != 0 )
1774 mnErrorFlags |= ERROR_ERROR_OCCURED;
1775 if ( ( nId & XMLERROR_FLAG_WARNING ) != 0 )
1776 mnErrorFlags |= ERROR_WARNING_OCCURED;
1777 if ( ( nId & XMLERROR_FLAG_SEVERE ) != 0 )
1778 mnErrorFlags |= ERROR_DO_NOTHING;
1780 // create error list on demand
1781 if ( mpXMLErrors == NULL )
1782 mpXMLErrors = new XMLErrors();
1784 // save error information
1785 // use document locator (if none supplied)
1786 mpXMLErrors->AddRecord( nId, rMsgParams, rExceptionMessage,
1787 rLocator.is() ? rLocator : mxLocator );
1790 void SvXMLImport::SetError(
1791 sal_Int32 nId,
1792 const Sequence<OUString>& rMsgParams)
1794 OUString sEmpty;
1795 SetError( nId, rMsgParams, sEmpty, NULL );
1798 void SvXMLImport::SetError(
1799 sal_Int32 nId)
1801 Sequence<OUString> aSeq(0);
1802 SetError( nId, aSeq );
1805 void SvXMLImport::SetError(
1806 sal_Int32 nId,
1807 const OUString& rMsg1)
1809 Sequence<OUString> aSeq(1);
1810 OUString* pSeq = aSeq.getArray();
1811 pSeq[0] = rMsg1;
1812 SetError( nId, aSeq );
1815 void SvXMLImport::SetError(
1816 sal_Int32 nId,
1817 const OUString& rMsg1,
1818 const OUString& rMsg2)
1820 Sequence<OUString> aSeq(2);
1821 OUString* pSeq = aSeq.getArray();
1822 pSeq[0] = rMsg1;
1823 pSeq[1] = rMsg2;
1824 SetError( nId, aSeq );
1827 void SvXMLImport::SetError(
1828 sal_Int32 nId,
1829 const OUString& rMsg1,
1830 const OUString& rMsg2,
1831 const OUString& rMsg3)
1833 Sequence<OUString> aSeq(3);
1834 OUString* pSeq = aSeq.getArray();
1835 pSeq[0] = rMsg1;
1836 pSeq[1] = rMsg2;
1837 pSeq[2] = rMsg3;
1838 SetError( nId, aSeq );
1841 void SvXMLImport::SetError(
1842 sal_Int32 nId,
1843 const OUString& rMsg1,
1844 const OUString& rMsg2,
1845 const OUString& rMsg3,
1846 const OUString& rMsg4)
1848 Sequence<OUString> aSeq(4);
1849 OUString* pSeq = aSeq.getArray();
1850 pSeq[0] = rMsg1;
1851 pSeq[1] = rMsg2;
1852 pSeq[2] = rMsg3;
1853 pSeq[3] = rMsg4;
1854 SetError( nId, aSeq );
1857 XMLErrors* SvXMLImport::GetErrors()
1859 return mpXMLErrors;
1862 void SvXMLImport::DisposingModel()
1864 if( mxFontDecls.Is() )
1865 ((SvXMLStylesContext *)&mxFontDecls)->Clear();
1866 if( mxStyles.Is() )
1867 ((SvXMLStylesContext *)&mxStyles)->Clear();
1868 if( mxAutoStyles.Is() )
1869 ((SvXMLStylesContext *)&mxAutoStyles)->Clear();
1870 if( mxMasterStyles.Is() )
1871 ((SvXMLStylesContext *)&mxMasterStyles)->Clear();
1873 mxModel.set(0);
1874 mxEventListener.set(NULL);
1877 ::comphelper::UnoInterfaceToUniqueIdentifierMapper& SvXMLImport::getInterfaceToIdentifierMapper()
1879 return mpImpl->maInterfaceToIdentifierMapper;
1882 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > SvXMLImport::getServiceFactory()
1884 // #110680#
1885 return mxServiceFactory;
1888 uno::Reference< uno::XComponentContext >
1889 SvXMLImport::GetComponentContext() const
1891 return mpImpl->mxComponentContext;
1894 String SvXMLImport::GetBaseURL() const
1896 return mpImpl->aBaseURL.GetMainURL( INetURLObject::NO_DECODE );
1899 String SvXMLImport::GetDocumentBase() const
1901 return mpImpl->aDocBase.GetMainURL( INetURLObject::NO_DECODE );
1904 ::rtl::OUString SvXMLImport::GetStreamName() const
1906 return mpImpl->mStreamName;
1909 // --> OD 2004-08-10 #i28749#
1910 sal_Bool SvXMLImport::IsShapePositionInHoriL2R() const
1912 return mpImpl->mbShapePositionInHoriL2R;
1914 // <--
1916 // --> OD 2007-12-19 #152540#
1917 sal_Bool SvXMLImport::IsTextDocInOOoFileFormat() const
1919 return mpImpl->mbTextDocInOOoFileFormat;
1922 // <--
1924 void SvXMLImport::initXForms()
1926 // dummy method; to be implemented by derived classes supporting XForms
1929 bool SvXMLImport::getBuildIds( sal_Int32& rUPD, sal_Int32& rBuild ) const
1931 bool bRet = false;
1932 if( mxImportInfo.is() ) try
1934 const OUString aPropName(RTL_CONSTASCII_USTRINGPARAM("BuildId"));
1935 Reference< XPropertySetInfo > xSetInfo( mxImportInfo->getPropertySetInfo() );
1936 if( xSetInfo.is() && xSetInfo->hasPropertyByName( aPropName ) )
1938 OUString aBuildId;
1939 mxImportInfo->getPropertyValue( aPropName ) >>= aBuildId;
1940 if( aBuildId.getLength() )
1942 sal_Int32 nIndex = aBuildId.indexOf('$');
1943 if( nIndex != -1 )
1945 rUPD = aBuildId.copy( 0, nIndex ).toInt32();
1946 rBuild = aBuildId.copy( nIndex+1 ).toInt32();
1947 bRet = true;
1952 catch( Exception& )
1955 return bRet;
1958 sal_uInt16 SvXMLImport::getGeneratorVersion() const
1960 sal_Int32 nUPD, nBuild;
1962 if( getBuildIds( nUPD, nBuild ) )
1964 if( nUPD == 680 )
1965 return OOo_2x;
1967 if( nUPD >= 640 && nUPD <= 645 )
1968 return OOo_1x;
1971 return OOo_Current;
1974 bool SvXMLImport::isGraphicLoadOnDemandSupported() const
1976 return mbIsGraphicLoadOnDemandSupported;
1979 ::rtl::OUString SvXMLImport::GetODFVersion() const
1981 return mpImpl->aODFVersion;
1984 // xml:id for RDF metadata
1985 void SvXMLImport::SetXmlId(uno::Reference<uno::XInterface> const & i_xIfc,
1986 ::rtl::OUString const & i_rXmlId)
1988 if (i_rXmlId.getLength() > 0) {
1989 try {
1990 const uno::Reference<rdf::XMetadatable> xMeta(i_xIfc,
1991 uno::UNO_QUERY);
1992 //FIXME: not yet
1993 // OSL_ENSURE(xMeta.is(), "xml:id: not XMetadatable");
1994 if (xMeta.is()) {
1995 const beans::StringPair mdref( GetStreamName(), i_rXmlId );
1996 try {
1997 xMeta->setMetadataReference(mdref);
1998 } catch (lang::IllegalArgumentException &) {
1999 // probably duplicate; ignore
2000 OSL_TRACE("SvXMLImport::SetXmlId: cannot set xml:id");
2003 } catch (uno::Exception &) {
2004 OSL_ENSURE(false, "SvXMLImport::SetXmlId: exception?");
2009 void
2010 SvXMLImport::AddRDFa(uno::Reference<rdf::XMetadatable> i_xObject,
2011 ::rtl::OUString const & i_rAbout,
2012 ::rtl::OUString const & i_rProperty,
2013 ::rtl::OUString const & i_rContent,
2014 ::rtl::OUString const & i_rDatatype)
2016 // N.B.: we only get called if i_xObject had xhtml:about attribute
2017 // (an empty attribute value is valid)
2018 if (!mpImpl->mpRDFaHelper.get())
2020 mpImpl->mpRDFaHelper.reset( new ::xmloff::RDFaImportHelper(*this) );
2022 mpImpl->mpRDFaHelper->AddRDFa(i_xObject,
2023 i_rAbout, i_rProperty, i_rContent, i_rDatatype);