Bump for 3.6-28
[LibreOffice.git] / xmloff / source / core / xmlimp.cxx
blobd2567a75ec6632966e35c2f411ab0d59201b578c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/beans/XPropertySetInfo.hpp>
30 #include <tools/debug.hxx>
31 #include <tools/urlobj.hxx>
32 #include <osl/mutex.hxx>
33 #include <rtl/memory.h>
34 #include <svl/svarray.hxx>
35 #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include <xmloff/xmluconv.hxx>
38 #include "xmloff/xmlnmspe.hxx"
39 #include <xmloff/xmltoken.hxx>
40 #include <xmloff/XMLFontStylesContext.hxx>
41 #include <xmloff/xmlictxt.hxx>
42 #include <xmloff/xmlimp.hxx>
43 #include <xmloff/xmlnumfi.hxx>
44 #include "XMLEventImportHelper.hxx"
45 #include "XMLStarBasicContextFactory.hxx"
46 #include "XMLScriptContextFactory.hxx"
47 #include "StyleMap.hxx"
48 #include <xmloff/ProgressBarHelper.hxx>
49 #include "xmloff/xmlerror.hxx"
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
52 #include <com/sun/star/io/XOutputStream.hpp>
53 #include <com/sun/star/util/MeasureUnit.hpp>
54 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
55 #include <com/sun/star/document/XStorageBasedDocument.hpp>
56 #include <com/sun/star/xml/sax/XLocator.hpp>
57 #include <com/sun/star/packages/zip/ZipIOException.hpp>
58 #include <comphelper/namecontainer.hxx>
59 #include <comphelper/servicehelper.hxx>
60 #include <rtl/logfile.hxx>
61 #include <cppuhelper/implbase1.hxx>
62 #include <comphelper/extract.hxx>
63 #include <comphelper/processfactory.hxx>
64 #include <comphelper/documentconstants.hxx>
65 #include <comphelper/storagehelper.hxx>
66 #include <unotools/fontcvt.hxx>
68 #include <com/sun/star/rdf/XMetadatable.hpp>
69 #include <com/sun/star/rdf/XRepositorySupplier.hpp>
70 #include "RDFaImportHelper.hxx"
72 #define LOGFILE_AUTHOR "unknown"
74 using ::com::sun::star::beans::XPropertySetInfo;
76 using ::rtl::OUString;
77 using ::rtl::OUStringBuffer;
79 using namespace ::osl;
80 using namespace ::com::sun::star;
81 using namespace ::com::sun::star::frame;
82 using namespace ::com::sun::star::uno;
83 using namespace ::com::sun::star::util;
84 using namespace ::com::sun::star::io;
85 using namespace ::com::sun::star::container;
86 using namespace ::com::sun::star::document;
87 using namespace ::xmloff::token;
89 sal_Char const sXML_np__office[] = "_office";
90 sal_Char const sXML_np__office_ext[] = "_office_ooo";
91 sal_Char const sXML_np__ooo[] = "_ooo";
92 sal_Char const sXML_np__ooow[] = "_ooow";
93 sal_Char const sXML_np__oooc[] = "_oooc";
94 sal_Char const sXML_np__of[] = "_of";
95 sal_Char const sXML_np__style[] = "_style";
96 sal_Char const sXML_np__text[] = "_text";
97 sal_Char const sXML_np__table[] = "_table";
98 sal_Char const sXML_np__table_ext[] = "_table_ooo";
99 sal_Char const sXML_np__draw[] = "_draw";
100 sal_Char const sXML_np__draw_ext[] = "_draw_ooo";
101 sal_Char const sXML_np__dr3d[] = "_dr3d";
102 sal_Char const sXML_np__fo[] = "_fo";
103 sal_Char const sXML_np__xlink[] = "_xlink";
104 sal_Char const sXML_np__dc[] = "_dc";
105 sal_Char const sXML_np__dom[] = "_dom";
106 sal_Char const sXML_np__meta[] = "_meta";
107 sal_Char const sXML_np__number[] = "_number";
108 sal_Char const sXML_np__svg[] = "_svg";
109 sal_Char const sXML_np__chart[] = "_chart";
110 sal_Char const sXML_np__math[] = "_math";
111 sal_Char const sXML_np__form[] = "_form";
112 sal_Char const sXML_np__script[] = "_script";
113 sal_Char const sXML_np__config[] = "_config";
114 sal_Char const sXML_np__db[] = "_db";
115 sal_Char const sXML_np__xforms[] = "_xforms";
116 sal_Char const sXML_np__formx[] = "_formx";
117 sal_Char const sXML_np__xsd[] = "_xsd";
118 sal_Char const sXML_np__xsi[] = "_xsi";
119 sal_Char const sXML_np__field[] = "_field";
120 sal_Char const sXML_np__xhtml[] = "_xhtml";
121 sal_Char const sXML_np__css3text[] = "_css3text";
123 sal_Char const sXML_np__fo_old[] = "__fo";
124 sal_Char const sXML_np__xlink_old[] = "__xlink";
125 sal_Char const sXML_np__office_old[] = "__office";
126 sal_Char const sXML_np__style_old[] = "__style";
127 sal_Char const sXML_np__text_old[] = "__text";
128 sal_Char const sXML_np__table_old[] = "__table";
129 sal_Char const sXML_np__meta_old[] = "__meta";
133 class SvXMLImportEventListener : public cppu::WeakImplHelper1<
134 com::sun::star::lang::XEventListener >
136 private:
137 SvXMLImport* pImport;
139 public:
140 SvXMLImportEventListener(SvXMLImport* pImport);
141 virtual ~SvXMLImportEventListener();
143 // XEventListener
144 virtual void SAL_CALL disposing(const lang::EventObject& rEventObject) throw(::com::sun::star::uno::RuntimeException);
147 SvXMLImportEventListener::SvXMLImportEventListener(SvXMLImport* pTempImport)
148 : pImport(pTempImport)
152 SvXMLImportEventListener::~SvXMLImportEventListener()
156 // XEventListener
157 void SAL_CALL SvXMLImportEventListener::disposing( const lang::EventObject& )
158 throw(uno::RuntimeException)
160 if (pImport)
162 pImport->DisposingModel();
163 pImport = NULL;
167 //==============================================================================
169 class SAL_DLLPRIVATE SvXMLImport_Impl
171 public:
172 FontToSubsFontConverter hBatsFontConv;
173 FontToSubsFontConverter hMathFontConv;
175 bool mbOwnGraphicResolver;
176 bool mbOwnEmbeddedResolver;
177 INetURLObject aBaseURL;
178 INetURLObject aDocBase;
180 /// name of stream in package, e.g., "content.xml"
181 ::rtl::OUString mStreamName;
183 ::rtl::OUString aODFVersion;
185 // Boolean, indicating that position attributes
186 // of shapes are given in horizontal left-to-right layout. This is the case
187 // for the OpenOffice.org file format. (#i28749#)
188 sal_Bool mbShapePositionInHoriL2R;
189 sal_Bool mbTextDocInOOoFileFormat;
191 const uno::Reference< uno::XComponentContext > mxComponentContext;
193 uno::Reference< embed::XStorage > mxSourceStorage;
195 std::auto_ptr< xmloff::RDFaImportHelper > mpRDFaHelper;
197 SvXMLImport_Impl() :
198 hBatsFontConv( 0 ), hMathFontConv( 0 ),
199 mbOwnGraphicResolver( false ),
200 mbOwnEmbeddedResolver( false ),
201 mStreamName(),
202 // Convert drawing object positions from OOo file format to OASIS (#i28749#)
203 mbShapePositionInHoriL2R( sal_False ),
204 mbTextDocInOOoFileFormat( sal_False ),
205 mxComponentContext( ::comphelper::getProcessComponentContext() ),
206 mpRDFaHelper() // lazy
208 OSL_ENSURE(mxComponentContext.is(), "SvXMLImport: no ComponentContext");
209 if (!mxComponentContext.is()) throw uno::RuntimeException();
212 ~SvXMLImport_Impl()
214 if( hBatsFontConv )
215 DestroyFontToSubsFontConverter( hBatsFontConv );
216 if( hMathFontConv )
217 DestroyFontToSubsFontConverter( hMathFontConv );
220 ::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper;
223 class SvXMLImportContexts_Impl : public std::vector<SvXMLImportContext *> {};
225 SvXMLImportContext *SvXMLImport::CreateContext( sal_uInt16 nPrefix,
226 const OUString& rLocalName,
227 const uno::Reference< xml::sax::XAttributeList >& )
229 return new SvXMLImportContext( *this, nPrefix, rLocalName );
232 void SvXMLImport::_InitCtor()
234 if( mnImportFlags != 0 )
236 // implicit "xml" namespace prefix
237 mpNamespaceMap->Add( GetXMLToken(XML_XML), GetXMLToken(XML_N_XML),
238 XML_NAMESPACE_XML );
239 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office ) ),
240 GetXMLToken(XML_N_OFFICE),
241 XML_NAMESPACE_OFFICE );
242 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office_ext ) ),
243 GetXMLToken(XML_N_OFFICE_EXT),
244 XML_NAMESPACE_OFFICE_EXT );
245 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__ooo ) ), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
246 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__style) ),
247 GetXMLToken(XML_N_STYLE),
248 XML_NAMESPACE_STYLE );
249 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__text) ),
250 GetXMLToken(XML_N_TEXT),
251 XML_NAMESPACE_TEXT );
252 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__table ) ),
253 GetXMLToken(XML_N_TABLE),
254 XML_NAMESPACE_TABLE );
255 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__table_ext ) ),
256 GetXMLToken(XML_N_TABLE_EXT),
257 XML_NAMESPACE_TABLE_EXT );
258 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__draw ) ),
259 GetXMLToken(XML_N_DRAW),
260 XML_NAMESPACE_DRAW );
261 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__draw_ext ) ),
262 GetXMLToken(XML_N_DRAW_EXT),
263 XML_NAMESPACE_DRAW_EXT );
264 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM (sXML_np__dr3d ) ),
265 GetXMLToken(XML_N_DR3D),
266 XML_NAMESPACE_DR3D );
267 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__fo) ),
268 GetXMLToken(XML_N_FO_COMPAT),
269 XML_NAMESPACE_FO );
270 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xlink) ),
271 GetXMLToken(XML_N_XLINK),
272 XML_NAMESPACE_XLINK );
273 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__dc) ),
274 GetXMLToken(XML_N_DC),
275 XML_NAMESPACE_DC );
276 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__dom ) ),
277 GetXMLToken(XML_N_DOM),
278 XML_NAMESPACE_DOM );
279 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__meta) ),
280 GetXMLToken(XML_N_META),
281 XML_NAMESPACE_META );
282 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__number) ),
283 GetXMLToken(XML_N_NUMBER),
284 XML_NAMESPACE_NUMBER );
285 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__svg) ),
286 GetXMLToken(XML_N_SVG_COMPAT),
287 XML_NAMESPACE_SVG );
288 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__chart) ),
289 GetXMLToken(XML_N_CHART),
290 XML_NAMESPACE_CHART );
291 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__math) ),
292 GetXMLToken(XML_N_MATH),
293 XML_NAMESPACE_MATH );
294 mpNamespaceMap->Add(OUString(RTL_CONSTASCII_USTRINGPARAM( sXML_np__form )),
295 GetXMLToken(XML_N_FORM),
296 XML_NAMESPACE_FORM );
297 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__script) ),
298 GetXMLToken(XML_N_SCRIPT),
299 XML_NAMESPACE_SCRIPT );
300 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__config) ),
301 GetXMLToken(XML_N_CONFIG),
302 XML_NAMESPACE_CONFIG );
303 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xforms) ),
304 GetXMLToken(XML_N_XFORMS_1_0),
305 XML_NAMESPACE_XFORMS );
306 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__formx) ),
307 GetXMLToken( XML_N_FORMX ),
308 XML_NAMESPACE_FORMX );
309 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xsd) ),
310 GetXMLToken(XML_N_XSD),
311 XML_NAMESPACE_XSD );
312 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xsi) ),
313 GetXMLToken(XML_N_XSI),
314 XML_NAMESPACE_XFORMS );
315 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__ooow ) ), GetXMLToken(XML_N_OOOW), XML_NAMESPACE_OOOW );
316 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__oooc ) ), GetXMLToken(XML_N_OOOC), XML_NAMESPACE_OOOC );
317 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__field ) ), GetXMLToken(XML_N_FIELD), XML_NAMESPACE_FIELD );
318 mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__of ) ),
319 GetXMLToken(XML_N_OF), XML_NAMESPACE_OF );
320 mpNamespaceMap->Add(
321 OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xhtml ) ),
322 GetXMLToken(XML_N_XHTML), XML_NAMESPACE_XHTML );
323 mpNamespaceMap->Add(
324 OUString( RTL_CONSTASCII_USTRINGPARAM( sXML_np__css3text ) ),
325 GetXMLToken(XML_N_CSS3TEXT), XML_NAMESPACE_CSS3TEXT );
327 mpNamespaceMap->Add( OUString("_calc_libo"), GetXMLToken(XML_N_CALC_EXT), XML_NAMESPACE_CALC_EXT);
330 msPackageProtocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package:" ) );
332 if (mxNumberFormatsSupplier.is())
333 mpNumImport = new SvXMLNumFmtHelper(mxNumberFormatsSupplier, getServiceFactory());
335 if (mxModel.is() && !mxEventListener.is())
337 mxEventListener.set(new SvXMLImportEventListener(this));
338 mxModel->addEventListener(mxEventListener);
341 ::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper;
345 // #110680#
346 SvXMLImport::SvXMLImport(
347 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
348 sal_uInt16 nImportFlags ) throw ()
349 : mpImpl( new SvXMLImport_Impl() ),
350 mpNamespaceMap( new SvXMLNamespaceMap ),
352 mpUnitConv( new SvXMLUnitConverter( xServiceFactory,
353 util::MeasureUnit::MM_100TH, util::MeasureUnit::MM_100TH) ),
355 mpContexts( new SvXMLImportContexts_Impl ),
356 mpNumImport( NULL ),
357 mpProgressBarHelper( NULL ),
358 mpEventImportHelper( NULL ),
359 mpXMLErrors( NULL ),
360 mpStyleMap(0),
361 mnImportFlags( nImportFlags ),
362 mnErrorFlags(0),
363 // #110680#
364 mxServiceFactory(xServiceFactory),
365 mbIsFormsSupported( sal_True ),
366 mbIsTableShapeSupported( false ),
367 mbIsGraphicLoadOnDemandSupported( true )
369 DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
370 _InitCtor();
373 SvXMLImport::~SvXMLImport() throw ()
375 delete mpXMLErrors;
376 delete mpNamespaceMap;
377 delete mpUnitConv;
378 delete mpEventImportHelper;
379 if( mpContexts )
381 while( !mpContexts->empty() )
383 SvXMLImportContext *pContext = mpContexts->back();
384 mpContexts->pop_back();
385 if( pContext )
386 pContext->ReleaseRef();
388 delete mpContexts;
391 // #i9518# the import component might not be deleted until after the document has been closed,
392 // so the stuff that accesses the document has been moved to endDocument.
394 // pNumImport is allocated in the ctor, so it must also be deleted here in case the component
395 // is created and deleted without actually importing.
396 delete mpNumImport;
397 delete mpProgressBarHelper;
399 xmloff::token::ResetTokens();
401 if( mpImpl )
402 delete mpImpl;
404 if (mxEventListener.is() && mxModel.is())
405 mxModel->removeEventListener(mxEventListener);
408 namespace
410 class theSvXMLImportUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvXMLImportUnoTunnelId> {};
413 // XUnoTunnel & co
414 const uno::Sequence< sal_Int8 > & SvXMLImport::getUnoTunnelId() throw()
416 return theSvXMLImportUnoTunnelId::get().getSeq();
419 // XUnoTunnel
420 sal_Int64 SAL_CALL SvXMLImport::getSomething( const uno::Sequence< sal_Int8 >& rId )
421 throw( uno::RuntimeException )
423 if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
424 rId.getConstArray(), 16 ) )
426 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
428 return 0;
431 void SAL_CALL SvXMLImport::startDocument( void )
432 throw( xml::sax::SAXException, uno::RuntimeException )
434 RTL_LOGFILE_TRACE_AUTHOR( "xmloff", LOGFILE_AUTHOR, "{ SvXMLImport::startDocument" );
436 if( !mxGraphicResolver.is() || !mxEmbeddedResolver.is() )
438 Reference< lang::XMultiServiceFactory > xFactory( mxModel, UNO_QUERY );
439 if( xFactory.is() )
443 if( !mxGraphicResolver.is() )
445 mxGraphicResolver = Reference< XGraphicObjectResolver >::query(
446 xFactory->createInstance(
447 OUString(RTL_CONSTASCII_USTRINGPARAM(
448 // #99870# Import... instead of Export...
449 "com.sun.star.document.ImportGraphicObjectResolver"))));
450 mpImpl->mbOwnGraphicResolver = mxGraphicResolver.is();
453 if( !mxEmbeddedResolver.is() )
455 mxEmbeddedResolver = Reference< XEmbeddedObjectResolver >::query(
456 xFactory->createInstance(
457 OUString(RTL_CONSTASCII_USTRINGPARAM(
458 // #99870# Import... instead of Export...
459 "com.sun.star.document.ImportEmbeddedObjectResolver"))));
460 mpImpl->mbOwnEmbeddedResolver = mxEmbeddedResolver.is();
463 catch( com::sun::star::uno::Exception& )
470 void SAL_CALL SvXMLImport::endDocument( void )
471 throw( xml::sax::SAXException, uno::RuntimeException)
473 RTL_LOGFILE_TRACE_AUTHOR( "xmloff", LOGFILE_AUTHOR, "} SvXMLImport::startDocument" );
475 // #i9518# All the stuff that accesses the document has to be done here, not in the dtor,
476 // because the SvXMLImport dtor might not be called until after the document has been closed.
478 if (mpImpl->mpRDFaHelper.get())
480 const uno::Reference<rdf::XRepositorySupplier> xRS(mxModel,
481 uno::UNO_QUERY);
482 if (xRS.is())
484 mpImpl->mpRDFaHelper->InsertRDFa( xRS );
488 if (mpNumImport)
490 delete mpNumImport;
491 mpNumImport = NULL;
493 if (mxImportInfo.is())
495 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
496 if (xPropertySetInfo.is())
498 if (mpProgressBarHelper)
500 OUString sProgressMax(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSMAX));
501 OUString sProgressCurrent(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSCURRENT));
502 OUString sRepeat(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSREPEAT));
503 if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
504 xPropertySetInfo->hasPropertyByName(sProgressCurrent))
506 sal_Int32 nProgressMax(mpProgressBarHelper->GetReference());
507 sal_Int32 nProgressCurrent(mpProgressBarHelper->GetValue());
508 uno::Any aAny;
509 aAny <<= nProgressMax;
510 mxImportInfo->setPropertyValue(sProgressMax, aAny);
511 aAny <<= nProgressCurrent;
512 mxImportInfo->setPropertyValue(sProgressCurrent, aAny);
514 if (xPropertySetInfo->hasPropertyByName(sRepeat))
515 mxImportInfo->setPropertyValue(sRepeat, cppu::bool2any(mpProgressBarHelper->GetRepeat()));
516 // pProgressBarHelper is deleted in dtor
518 OUString sNumberStyles(RTL_CONSTASCII_USTRINGPARAM(XML_NUMBERSTYLES));
519 if (mxNumberStyles.is() && xPropertySetInfo->hasPropertyByName(sNumberStyles))
521 uno::Any aAny;
522 aAny <<= mxNumberStyles;
523 mxImportInfo->setPropertyValue(sNumberStyles, aAny);
528 if( mxFontDecls.Is() )
529 ((SvXMLStylesContext *)&mxFontDecls)->Clear();
530 if( mxStyles.Is() )
531 ((SvXMLStylesContext *)&mxStyles)->Clear();
532 if( mxAutoStyles.Is() )
533 ((SvXMLStylesContext *)&mxAutoStyles)->Clear();
534 if( mxMasterStyles.Is() )
535 ((SvXMLStylesContext *)&mxMasterStyles)->Clear();
537 // possible form-layer related knittings which can only be done when
538 // the whole document exists
539 if ( mxFormImport.is() )
540 mxFormImport->documentDone();
542 // The shape import helper does the z-order sorting in the dtor,
543 // so it must be deleted here, too.
544 mxShapeImport = NULL;
546 if( mpImpl->mbOwnGraphicResolver )
548 Reference< lang::XComponent > xComp( mxGraphicResolver, UNO_QUERY );
549 xComp->dispose();
552 if( mpImpl->mbOwnEmbeddedResolver )
554 Reference< lang::XComponent > xComp( mxEmbeddedResolver, UNO_QUERY );
555 xComp->dispose();
557 if( mpStyleMap )
559 mpStyleMap->release();
560 mpStyleMap = 0;
563 if ( mpXMLErrors != NULL )
565 mpXMLErrors->ThrowErrorAsSAXException( XMLERROR_FLAG_SEVERE );
569 void SAL_CALL SvXMLImport::startElement( const OUString& rName,
570 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
571 throw(xml::sax::SAXException, uno::RuntimeException)
573 SvXMLNamespaceMap *pRewindMap = 0;
575 // Process namespace attributes. This must happen before creating the
576 // context, because namespace decaration apply to the element name itself.
577 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
578 for( sal_Int16 i=0; i < nAttrCount; i++ )
580 const OUString& rAttrName = xAttrList->getNameByIndex( i );
581 if ( rAttrName == "office:version" )
583 mpImpl->aODFVersion = xAttrList->getValueByIndex( i );
585 // the ODF version in content.xml and manifest.xml must be the same starting from ODF1.2
586 if ( mpImpl->mStreamName == "content.xml" && !IsODFVersionConsistent( mpImpl->aODFVersion ) )
588 throw xml::sax::SAXException(
589 ::rtl::OUString(
590 RTL_CONSTASCII_USTRINGPARAM( "Inconsistent ODF versions in content.xml and manifest.xml!" ) ),
591 uno::Reference< uno::XInterface >(),
592 uno::makeAny(
593 packages::zip::ZipIOException(
594 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
595 "Inconsistent ODF versions in content.xml and manifest.xml!" ) ),
596 Reference< XInterface >() ) ) );
599 else if( ( rAttrName.getLength() >= 5 ) &&
600 ( rAttrName.compareTo( GetXMLToken(XML_XMLNS), 5 ) == 0 ) &&
601 ( rAttrName.getLength() == 5 || ':' == rAttrName[5] ) )
603 if( !pRewindMap )
605 pRewindMap = mpNamespaceMap;
606 mpNamespaceMap = new SvXMLNamespaceMap( *mpNamespaceMap );
608 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
610 OUString aPrefix( ( rAttrName.getLength() == 5 )
611 ? OUString()
612 : rAttrName.copy( 6 ) );
613 // Add namespace, but only if it is known.
614 sal_uInt16 nKey = mpNamespaceMap->AddIfKnown( aPrefix, rAttrValue );
615 // If namespace is unknwon, try to match a name with similar
616 // TC Id an version
617 if( XML_NAMESPACE_UNKNOWN == nKey )
619 OUString aTestName( rAttrValue );
620 if( SvXMLNamespaceMap::NormalizeURI( aTestName ) )
621 nKey = mpNamespaceMap->AddIfKnown( aPrefix, aTestName );
623 // If that namespace is not known, too, add it as unknown
624 if( XML_NAMESPACE_UNKNOWN == nKey )
625 mpNamespaceMap->Add( aPrefix, rAttrValue );
630 // Get element's namespace and local name.
631 OUString aLocalName;
632 sal_uInt16 nPrefix =
633 mpNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
635 // If there are contexts already, call a CreateChildContext at the topmost
636 // context. Otherwise, create a default context.
637 SvXMLImportContext *pContext;
638 sal_uInt16 nCount = mpContexts->size();
639 if( nCount > 0 )
641 pContext = (*mpContexts)[nCount - 1]->CreateChildContext( nPrefix,
642 aLocalName,
643 xAttrList );
644 DBG_ASSERT( pContext && pContext->GetPrefix() == nPrefix,
645 "SvXMLImport::startElement: created context has wrong prefix" );
647 else
649 #ifdef TIMELOG
650 // If we do profiling, we want a trace message for the first element
651 // in order to identify the stream.
652 rtl::OString aString(rtl::OUStringToOString(rName, RTL_TEXTENCODING_ASCII_US));
653 RTL_LOGFILE_TRACE_AUTHOR1( "xmloff", LOGFILE_AUTHOR,
654 "SvXMLImport::StartElement( \"%s\", ... )",
655 aString.getStr() );
656 #endif
658 pContext = CreateContext( nPrefix, aLocalName, xAttrList );
659 if( (nPrefix & XML_NAMESPACE_UNKNOWN_FLAG) != 0 &&
660 IS_TYPE( SvXMLImportContext, pContext ) )
662 OUString aMsg( RTL_CONSTASCII_USTRINGPARAM( "Root element unknown" ) );
663 Reference<xml::sax::XLocator> xDummyLocator;
664 Sequence < OUString > aParams(1);
665 aParams.getArray()[0] = rName;
667 SetError( XMLERROR_FLAG_SEVERE|XMLERROR_UNKNWON_ROOT,
668 aParams, aMsg, xDummyLocator );
672 DBG_ASSERT( pContext, "SvXMLImport::startElement: missing context" );
673 if( !pContext )
674 pContext = new SvXMLImportContext( *this, nPrefix, aLocalName );
676 pContext->AddRef();
678 // Remeber old namespace map.
679 if( pRewindMap )
680 pContext->SetRewindMap( pRewindMap );
682 // Call a startElement at the new context.
683 pContext->StartElement( xAttrList );
685 // Push context on stack.
686 mpContexts->push_back( pContext );
689 void SAL_CALL SvXMLImport::endElement( const OUString&
690 #ifdef DBG_UTIL
691 rName
692 #endif
694 throw(xml::sax::SAXException, uno::RuntimeException)
696 sal_uInt16 nCount = mpContexts->size();
697 DBG_ASSERT( nCount, "SvXMLImport::endElement: no context left" );
698 if( nCount > 0 )
700 // Get topmost context and remove it from the stack.
701 SvXMLImportContext *pContext = mpContexts->back();
702 mpContexts->pop_back();
704 #ifdef DBG_UTIL
705 // Non product only: check if endElement call matches startELement call.
706 OUString aLocalName;
707 sal_uInt16 nPrefix =
708 mpNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
709 DBG_ASSERT( pContext->GetPrefix() == nPrefix,
710 "SvXMLImport::endElement: popped context has wrong prefix" );
711 DBG_ASSERT( pContext->GetLocalName() == aLocalName,
712 "SvXMLImport::endElement: popped context has wrong lname" );
713 #endif
715 // Call a EndElement at the current context.
716 pContext->EndElement();
718 // Get a namespace map to rewind.
719 SvXMLNamespaceMap *pRewindMap = pContext->GetRewindMap();
721 // Delete the current context.
722 pContext->ReleaseRef();
723 pContext = 0;
725 // Rewind a namespace map.
726 if( pRewindMap )
728 delete mpNamespaceMap;
729 mpNamespaceMap = pRewindMap;
734 void SAL_CALL SvXMLImport::characters( const OUString& rChars )
735 throw(xml::sax::SAXException, uno::RuntimeException)
737 if( !mpContexts->empty() )
739 mpContexts->back()->Characters( rChars );
743 void SAL_CALL SvXMLImport::ignorableWhitespace( const OUString& )
744 throw(xml::sax::SAXException, uno::RuntimeException)
748 void SAL_CALL SvXMLImport::processingInstruction( const OUString&,
749 const OUString& )
750 throw(xml::sax::SAXException, uno::RuntimeException)
754 void SAL_CALL SvXMLImport::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& rLocator )
755 throw(xml::sax::SAXException, uno::RuntimeException)
757 mxLocator = rLocator;
760 // XExtendedDocumentHandler
761 void SAL_CALL SvXMLImport::startCDATA( void ) throw(xml::sax::SAXException, uno::RuntimeException)
765 void SAL_CALL SvXMLImport::endCDATA( void ) throw(uno::RuntimeException)
769 void SAL_CALL SvXMLImport::comment( const OUString& )
770 throw(xml::sax::SAXException, uno::RuntimeException)
774 void SAL_CALL SvXMLImport::allowLineBreak( void )
775 throw(xml::sax::SAXException, uno::RuntimeException)
779 void SAL_CALL SvXMLImport::unknown( const OUString& )
780 throw(xml::sax::SAXException, uno::RuntimeException)
784 void SvXMLImport::SetStatistics(const uno::Sequence< beans::NamedValue> &)
786 GetProgressBarHelper()->SetRepeat(sal_False);
787 GetProgressBarHelper()->SetReference(0);
790 ///////////////////////////////////////////////////////////////////////
792 // XImporter
793 void SAL_CALL SvXMLImport::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
794 throw(lang::IllegalArgumentException, uno::RuntimeException)
796 mxModel = uno::Reference< frame::XModel >::query( xDoc );
797 if( !mxModel.is() )
798 throw lang::IllegalArgumentException();
799 if (mxModel.is() && !mxEventListener.is())
801 mxEventListener.set(new SvXMLImportEventListener(this));
802 mxModel->addEventListener(mxEventListener);
805 DBG_ASSERT( !mpNumImport, "number format import already exists." );
806 if( mpNumImport )
808 delete mpNumImport;
809 mpNumImport = 0;
813 // XFilter
814 sal_Bool SAL_CALL SvXMLImport::filter( const uno::Sequence< beans::PropertyValue >& )
815 throw (uno::RuntimeException)
817 return sal_False;
820 void SAL_CALL SvXMLImport::cancel( )
821 throw (uno::RuntimeException)
825 // XInitialize
826 void SAL_CALL SvXMLImport::initialize( const uno::Sequence< uno::Any >& aArguments )
827 throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
829 const sal_Int32 nAnyCount = aArguments.getLength();
830 const uno::Any* pAny = aArguments.getConstArray();
832 for( sal_Int32 nIndex = 0; nIndex < nAnyCount; nIndex++, pAny++ )
834 Reference<XInterface> xValue;
835 *pAny >>= xValue;
837 uno::Reference<task::XStatusIndicator> xTmpStatusIndicator(
838 xValue, UNO_QUERY );
839 if( xTmpStatusIndicator.is() )
840 mxStatusIndicator = xTmpStatusIndicator;
842 uno::Reference<document::XGraphicObjectResolver> xTmpGraphicResolver(
843 xValue, UNO_QUERY );
844 if( xTmpGraphicResolver.is() )
845 mxGraphicResolver = xTmpGraphicResolver;
847 uno::Reference<document::XEmbeddedObjectResolver> xTmpObjectResolver(
848 xValue, UNO_QUERY );
849 if( xTmpObjectResolver.is() )
850 mxEmbeddedResolver = xTmpObjectResolver;
852 uno::Reference<beans::XPropertySet> xTmpPropSet( xValue, UNO_QUERY );
853 if( xTmpPropSet.is() )
855 mxImportInfo = xTmpPropSet;
856 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
857 if (xPropertySetInfo.is())
859 OUString sPropName(RTL_CONSTASCII_USTRINGPARAM(XML_NUMBERSTYLES));
860 if (xPropertySetInfo->hasPropertyByName(sPropName))
862 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
863 aAny >>= mxNumberStyles;
866 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("PrivateData" ) );
867 if (xPropertySetInfo->hasPropertyByName(sPropName))
869 Reference < XInterface > xIfc;
870 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
871 aAny >>= xIfc;
873 StyleMap *pSMap = StyleMap::getImplementation( xIfc );
874 if( pSMap )
876 mpStyleMap = pSMap;
877 mpStyleMap->acquire();
880 OUString sBaseURI;
881 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("BaseURI" ) );
882 if (xPropertySetInfo->hasPropertyByName(sPropName))
884 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
885 aAny >>= sBaseURI;
886 mpImpl->aBaseURL.SetURL( sBaseURI );
887 mpImpl->aDocBase.SetURL( sBaseURI );
889 OUString sRelPath;
890 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("StreamRelPath" ) );
891 if( xPropertySetInfo->hasPropertyByName(sPropName) )
893 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
894 aAny >>= sRelPath;
896 OUString sName;
897 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("StreamName" ) );
898 if( xPropertySetInfo->hasPropertyByName(sPropName) )
900 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
901 aAny >>= sName;
903 if( !sBaseURI.isEmpty() && !sName.isEmpty() )
905 if( !sRelPath.isEmpty() )
906 mpImpl->aBaseURL.insertName( sRelPath );
907 mpImpl->aBaseURL.insertName( sName );
909 mpImpl->mStreamName = sName; // Note: may be empty (XSLT)
910 // Retrieve property <ShapePositionInHoriL2R> (#i28749#)
911 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("ShapePositionInHoriL2R" ) );
912 if( xPropertySetInfo->hasPropertyByName(sPropName) )
914 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
915 aAny >>= (mpImpl->mbShapePositionInHoriL2R);
917 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("TextDocInOOoFileFormat" ) );
918 if( xPropertySetInfo->hasPropertyByName(sPropName) )
920 uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
921 aAny >>= (mpImpl->mbTextDocInOOoFileFormat);
924 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("SourceStorage" ) );
925 if( xPropertySetInfo->hasPropertyByName(sPropName) )
926 mxImportInfo->getPropertyValue(sPropName) >>= mpImpl->mxSourceStorage;
932 // XServiceInfo
933 OUString SAL_CALL SvXMLImport::getImplementationName()
934 throw(uno::RuntimeException)
936 OUString aStr;
937 return aStr;
940 sal_Bool SAL_CALL SvXMLImport::supportsService( const OUString& rServiceName )
941 throw(::com::sun::star::uno::RuntimeException)
943 return
944 rServiceName.equalsAsciiL(
945 "com.sun.star.document.ImportFilter",
946 sizeof("com.sun.star.document.ImportFilter")-1 ) ||
947 rServiceName.equalsAsciiL(
948 "com.sun.star.xml.XMLImportFilter",
949 sizeof("com.sun.star.xml.XMLImportFilter")-1);
952 uno::Sequence< OUString > SAL_CALL SvXMLImport::getSupportedServiceNames( )
953 throw(uno::RuntimeException)
955 uno::Sequence<OUString> aSeq(2);
956 aSeq[0] = OUString(
957 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ImportFilter"));
958 aSeq[1] = OUString(
959 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.XMLImportFilter"));
960 return aSeq;
963 ///////////////////////////////////////////////////////////////////////
965 XMLTextImportHelper* SvXMLImport::CreateTextImport()
967 return new XMLTextImportHelper( mxModel, *this );
970 XMLShapeImportHelper* SvXMLImport::CreateShapeImport()
972 return new XMLShapeImportHelper( *this, mxModel );
975 SchXMLImportHelper* SvXMLImport::CreateChartImport()
977 return new SchXMLImportHelper();
980 ::xmloff::OFormLayerXMLImport* SvXMLImport::CreateFormImport()
982 return new ::xmloff::OFormLayerXMLImport(*this);
986 ///////////////////////////////////////////////////////////////////////////////
988 // Get or create fill/line/lineend-style-helper
991 const Reference< container::XNameContainer > & SvXMLImport::GetGradientHelper()
993 if( !mxGradientHelper.is() )
995 if( mxModel.is() )
997 Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
998 if( xServiceFact.is() )
1002 mxGradientHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1003 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.GradientTable" ) ) ), UNO_QUERY);
1005 catch( lang::ServiceNotRegisteredException& )
1011 return mxGradientHelper;
1014 const Reference< container::XNameContainer > & SvXMLImport::GetHatchHelper()
1016 if( !mxHatchHelper.is() )
1018 if( mxModel.is() )
1020 Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1021 if( xServiceFact.is() )
1025 mxHatchHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1026 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.HatchTable" ) ) ), UNO_QUERY);
1028 catch( lang::ServiceNotRegisteredException& )
1034 return mxHatchHelper;
1037 const Reference< container::XNameContainer > & SvXMLImport::GetBitmapHelper()
1039 if( !mxBitmapHelper.is() )
1041 if( mxModel.is() )
1043 Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1044 if( xServiceFact.is() )
1048 mxBitmapHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1049 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.BitmapTable" ) ) ), UNO_QUERY);
1051 catch( lang::ServiceNotRegisteredException& )
1057 return mxBitmapHelper;
1060 const Reference< container::XNameContainer > & SvXMLImport::GetTransGradientHelper()
1062 if( !mxTransGradientHelper.is() )
1064 if( mxModel.is() )
1066 Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1067 if( xServiceFact.is() )
1071 mxTransGradientHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1072 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.TransparencyGradientTable" ) ) ), UNO_QUERY);
1074 catch( lang::ServiceNotRegisteredException& )
1080 return mxTransGradientHelper;
1083 const Reference< container::XNameContainer > & SvXMLImport::GetMarkerHelper()
1085 if( !mxMarkerHelper.is() )
1087 if( mxModel.is() )
1089 Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1090 if( xServiceFact.is() )
1094 mxMarkerHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1095 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.MarkerTable" ) ) ), UNO_QUERY);
1097 catch( lang::ServiceNotRegisteredException& )
1103 return mxMarkerHelper;
1106 const Reference< container::XNameContainer > & SvXMLImport::GetDashHelper()
1108 if( !mxDashHelper.is() )
1110 if( mxModel.is() )
1112 Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1113 if( xServiceFact.is() )
1117 mxDashHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1118 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DashTable" ) ) ), UNO_QUERY);
1120 catch( lang::ServiceNotRegisteredException& )
1126 return mxDashHelper;
1129 sal_Bool SvXMLImport::IsPackageURL( const ::rtl::OUString& rURL ) const
1132 // if, and only if, only parts are imported, then we're in a package
1133 const sal_uInt32 nTest = IMPORT_META|IMPORT_STYLES|IMPORT_CONTENT|IMPORT_SETTINGS;
1134 if( (mnImportFlags & nTest) == nTest )
1135 return sal_False;
1137 // Some quick tests: Some may rely on the package structure!
1138 sal_Int32 nLen = rURL.getLength();
1139 if( (nLen > 0 && '/' == rURL[0]) )
1140 // RFC2396 net_path or abs_path
1141 return sal_False;
1142 else if( nLen > 1 && '.' == rURL[0] )
1144 if( '.' == rURL[1] )
1145 // ../: We are never going up one level, so we know
1146 // it's not an external URI
1147 return sal_False;
1148 else if( '/' == rURL[1] )
1149 // we are remaining on a level, so it's an package URI
1150 return sal_True;
1153 // Now check for a RFC2396 schema
1154 sal_Int32 nPos = 1;
1155 while( nPos < nLen )
1157 switch( rURL[nPos] )
1159 case '/':
1160 // a relative path segement
1161 return sal_True;
1162 case ':':
1163 // a schema
1164 return sal_False;
1165 default:
1166 break;
1167 // we don't care about any other characters
1169 ++nPos;
1172 return sal_True;
1175 ::rtl::OUString SvXMLImport::ResolveGraphicObjectURL( const ::rtl::OUString& rURL,
1176 sal_Bool bLoadOnDemand )
1178 ::rtl::OUString sRet;
1180 if( IsPackageURL( rURL ) )
1182 if( !bLoadOnDemand && mxGraphicResolver.is() )
1184 ::rtl::OUString aTmp( msPackageProtocol );
1185 aTmp += rURL;
1186 sRet = mxGraphicResolver->resolveGraphicObjectURL( aTmp );
1189 if( sRet.isEmpty() )
1191 sRet = msPackageProtocol;
1192 sRet += rURL;
1196 if( sRet.isEmpty() )
1197 sRet = GetAbsoluteReference( rURL );
1199 return sRet;
1202 Reference< XOutputStream > SvXMLImport::GetStreamForGraphicObjectURLFromBase64()
1204 Reference< XOutputStream > xOStm;
1205 Reference< document::XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
1207 if( xStmResolver.is() )
1208 xOStm = xStmResolver->createOutputStream();
1210 return xOStm;
1213 ::rtl::OUString SvXMLImport::ResolveGraphicObjectURLFromBase64(
1214 const Reference < XOutputStream >& rOut )
1216 OUString sURL;
1217 Reference< document::XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
1218 if( xStmResolver.is() )
1219 sURL = xStmResolver->resolveOutputStream( rOut );
1221 return sURL;
1224 ::rtl::OUString SvXMLImport::ResolveEmbeddedObjectURL(
1225 const ::rtl::OUString& rURL,
1226 const ::rtl::OUString& rClassId )
1228 ::rtl::OUString sRet;
1230 if( IsPackageURL( rURL ) )
1232 if ( mxEmbeddedResolver.is() )
1234 OUString sURL( rURL );
1235 if( !rClassId.isEmpty() )
1237 sURL += OUString( sal_Unicode('!') );
1238 sURL += rClassId;
1240 sRet = mxEmbeddedResolver->resolveEmbeddedObjectURL( sURL );
1243 else
1244 sRet = GetAbsoluteReference( rURL );
1246 return sRet;
1249 Reference< embed::XStorage > SvXMLImport::GetSourceStorage()
1251 return mpImpl->mxSourceStorage;
1254 Reference < XOutputStream >
1255 SvXMLImport::GetStreamForEmbeddedObjectURLFromBase64()
1257 Reference < XOutputStream > xOLEStream;
1259 if( mxEmbeddedResolver.is() )
1261 Reference< XNameAccess > xNA( mxEmbeddedResolver, UNO_QUERY );
1262 if( xNA.is() )
1264 OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "Obj12345678" ) );
1265 Any aAny = xNA->getByName( aURL );
1266 aAny >>= xOLEStream;
1270 return xOLEStream;
1273 ::rtl::OUString SvXMLImport::ResolveEmbeddedObjectURLFromBase64()
1275 ::rtl::OUString sRet;
1277 if( mxEmbeddedResolver.is() )
1279 OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "Obj12345678" ) );
1280 sRet = mxEmbeddedResolver->resolveEmbeddedObjectURL( aURL );
1283 return sRet;
1286 void SvXMLImport::AddStyleDisplayName( sal_uInt16 nFamily,
1287 const OUString& rName,
1288 const OUString& rDisplayName )
1290 if( !mpStyleMap )
1292 mpStyleMap = new StyleMap;
1293 mpStyleMap->acquire();
1294 if( mxImportInfo.is() )
1296 OUString sPrivateData(
1297 RTL_CONSTASCII_USTRINGPARAM("PrivateData" ) );
1298 Reference< beans::XPropertySetInfo > xPropertySetInfo =
1299 mxImportInfo->getPropertySetInfo();
1300 if( xPropertySetInfo.is() &&
1301 xPropertySetInfo->hasPropertyByName(sPrivateData) )
1303 Reference < XInterface > xIfc(
1304 static_cast< XUnoTunnel *>( mpStyleMap ) );
1305 Any aAny;
1306 aAny <<= xIfc;
1307 mxImportInfo->setPropertyValue( sPrivateData, aAny );
1312 StyleMap::key_type aKey( nFamily, rName );
1313 StyleMap::value_type aValue( aKey, rDisplayName );
1314 ::std::pair<StyleMap::iterator,bool> aRes( mpStyleMap->insert( aValue ) );
1315 OSL_ENSURE( aRes.second, "duplicate style name" );
1319 OUString SvXMLImport::GetStyleDisplayName( sal_uInt16 nFamily,
1320 const OUString& rName ) const
1322 OUString sName( rName );
1323 if( mpStyleMap && !rName.isEmpty() )
1325 StyleMap::key_type aKey( nFamily, rName );
1326 StyleMap::const_iterator aIter = mpStyleMap->find( aKey );
1327 if( aIter != mpStyleMap->end() )
1328 sName = (*aIter).second;
1330 return sName;
1333 void SvXMLImport::SetViewSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&)
1337 void SvXMLImport::SetConfigurationSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&)
1341 void SvXMLImport::SetDocumentSpecificSettings(const ::rtl::OUString& _rSettingsGroupName, const uno::Sequence<beans::PropertyValue>& _rSettings)
1343 (void)_rSettingsGroupName;
1344 (void)_rSettings;
1347 ProgressBarHelper* SvXMLImport::GetProgressBarHelper()
1349 if (!mpProgressBarHelper)
1351 mpProgressBarHelper = new ProgressBarHelper(mxStatusIndicator, sal_False);
1353 if (mxImportInfo.is())
1355 uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
1356 if (xPropertySetInfo.is())
1358 OUString sProgressRange(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSRANGE));
1359 OUString sProgressMax(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSMAX));
1360 OUString sProgressCurrent(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSCURRENT));
1361 OUString sRepeat(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSREPEAT));
1362 if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
1363 xPropertySetInfo->hasPropertyByName(sProgressCurrent) &&
1364 xPropertySetInfo->hasPropertyByName(sProgressRange))
1366 uno::Any aAny;
1367 sal_Int32 nProgressMax(0);
1368 sal_Int32 nProgressCurrent(0);
1369 sal_Int32 nProgressRange(0);
1370 aAny = mxImportInfo->getPropertyValue(sProgressRange);
1371 if (aAny >>= nProgressRange)
1372 mpProgressBarHelper->SetRange(nProgressRange);
1373 aAny = mxImportInfo->getPropertyValue(sProgressMax);
1374 if (aAny >>= nProgressMax)
1375 mpProgressBarHelper->SetReference(nProgressMax);
1376 aAny = mxImportInfo->getPropertyValue(sProgressCurrent);
1377 if (aAny >>= nProgressCurrent)
1378 mpProgressBarHelper->SetValue(nProgressCurrent);
1380 if (xPropertySetInfo->hasPropertyByName(sRepeat))
1382 uno::Any aAny = mxImportInfo->getPropertyValue(sRepeat);
1383 if (aAny.getValueType() == getBooleanCppuType())
1384 mpProgressBarHelper->SetRepeat(::cppu::any2bool(aAny));
1385 else {
1386 SAL_WARN( "xmloff.core", "why is it no boolean?" );
1392 return mpProgressBarHelper;
1395 void SvXMLImport::AddNumberStyle(sal_Int32 nKey, const OUString& rName)
1397 if (!mxNumberStyles.is())
1398 mxNumberStyles = uno::Reference< container::XNameContainer >( comphelper::NameContainer_createInstance( ::getCppuType((const sal_Int32*)0)) );
1399 if (mxNumberStyles.is())
1401 uno::Any aAny;
1402 aAny <<= nKey;
1405 mxNumberStyles->insertByName(rName, aAny);
1407 catch ( uno::Exception& )
1409 OSL_FAIL("Numberformat could not be inserted");
1412 else {
1413 OSL_FAIL("not possible to create NameContainer");
1417 XMLEventImportHelper& SvXMLImport::GetEventImport()
1419 if (!mpEventImportHelper)
1421 // construct event helper and register StarBasic handler and standard
1422 // event tables
1423 mpEventImportHelper = new XMLEventImportHelper();
1424 OUString sStarBasic(GetXMLToken(XML_STARBASIC));
1425 mpEventImportHelper->RegisterFactory(sStarBasic,
1426 new XMLStarBasicContextFactory());
1427 OUString sScript(GetXMLToken(XML_SCRIPT));
1428 mpEventImportHelper->RegisterFactory(sScript,
1429 new XMLScriptContextFactory());
1430 mpEventImportHelper->AddTranslationTable(aStandardEventTable);
1432 // register StarBasic event handler with capitalized spelling
1433 OUString sStarBasicCap(RTL_CONSTASCII_USTRINGPARAM("StarBasic"));
1434 mpEventImportHelper->RegisterFactory(sStarBasicCap,
1435 new XMLStarBasicContextFactory());
1438 return *mpEventImportHelper;
1441 void SvXMLImport::SetFontDecls( XMLFontStylesContext *pFontDecls )
1443 mxFontDecls = pFontDecls;
1444 GetTextImport()->SetFontDecls( pFontDecls );
1447 void SvXMLImport::SetStyles( SvXMLStylesContext *pStyles )
1449 mxStyles = pStyles;
1452 void SvXMLImport::SetAutoStyles( SvXMLStylesContext *pAutoStyles )
1454 if (pAutoStyles && mxNumberStyles.is() && (mnImportFlags & IMPORT_CONTENT) )
1456 uno::Reference<xml::sax::XAttributeList> xAttrList;
1457 uno::Sequence< ::rtl::OUString > aNames = mxNumberStyles->getElementNames();
1458 sal_uInt32 nCount(aNames.getLength());
1459 if (nCount)
1461 const OUString* pNames = aNames.getConstArray();
1462 if ( pNames )
1464 SvXMLStyleContext* pContext;
1465 uno::Any aAny;
1466 sal_Int32 nKey(0);
1467 for (sal_uInt32 i = 0; i < nCount; i++, pNames++)
1469 aAny = mxNumberStyles->getByName(*pNames);
1470 if (aAny >>= nKey)
1472 pContext = new SvXMLNumFormatContext( *this, XML_NAMESPACE_NUMBER,
1473 *pNames, xAttrList, nKey, *pAutoStyles );
1474 pAutoStyles->AddStyle(*pContext);
1480 mxAutoStyles = pAutoStyles;
1481 GetTextImport()->SetAutoStyles( pAutoStyles );
1482 GetShapeImport()->SetAutoStylesContext( pAutoStyles );
1483 GetChartImport()->SetAutoStylesContext( pAutoStyles );
1484 GetFormImport()->setAutoStyleContext( pAutoStyles );
1487 void SvXMLImport::SetMasterStyles( SvXMLStylesContext *pMasterStyles )
1489 mxMasterStyles = pMasterStyles;
1492 XMLFontStylesContext *SvXMLImport::GetFontDecls()
1494 return (XMLFontStylesContext *)&mxFontDecls;
1497 SvXMLStylesContext *SvXMLImport::GetStyles()
1499 return (SvXMLStylesContext *)&mxStyles;
1502 SvXMLStylesContext *SvXMLImport::GetAutoStyles()
1504 return (SvXMLStylesContext *)&mxAutoStyles;
1507 const XMLFontStylesContext *SvXMLImport::GetFontDecls() const
1509 return (const XMLFontStylesContext *)&mxFontDecls;
1512 const SvXMLStylesContext *SvXMLImport::GetStyles() const
1514 return (const SvXMLStylesContext *)&mxStyles;
1517 const SvXMLStylesContext *SvXMLImport::GetAutoStyles() const
1519 return (const SvXMLStylesContext *)&mxAutoStyles;
1522 OUString SvXMLImport::GetAbsoluteReference(const OUString& rValue) const
1524 if( rValue.isEmpty() || rValue[0] == '#' )
1525 return rValue;
1527 INetURLObject aAbsURL;
1528 if( mpImpl->aBaseURL.GetNewAbsURL( rValue, &aAbsURL ) )
1529 return aAbsURL.GetMainURL( INetURLObject::DECODE_TO_IURI );
1530 else
1531 return rValue;
1534 sal_Bool SvXMLImport::IsODFVersionConsistent( const ::rtl::OUString& aODFVersion )
1536 // the check returns sal_False only if the storage version could be retrieved
1537 sal_Bool bResult = sal_True;
1539 if ( !aODFVersion.isEmpty() && aODFVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
1541 // check the consistency only for the ODF1.2 and later ( according to content.xml )
1542 // manifest.xml might have no version, it should be checked here and the correct version should be set
1545 uno::Reference< document::XStorageBasedDocument > xDoc( mxModel, uno::UNO_QUERY_THROW );
1546 uno::Reference< embed::XStorage > xStor = xDoc->getDocumentStorage();
1547 uno::Reference< beans::XPropertySet > xStorProps( xStor, uno::UNO_QUERY_THROW );
1549 // the check should be done only for OASIS format
1550 ::rtl::OUString aMediaType;
1551 xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ) >>= aMediaType;
1552 if ( ::comphelper::OStorageHelper::GetXStorageFormat( xStor ) >= SOFFICE_FILEFORMAT_8 )
1554 sal_Bool bRepairPackage = sal_False;
1557 xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RepairPackage" ) ) )
1558 >>= bRepairPackage;
1559 } catch ( uno::Exception& )
1562 // check only if not in Repair mode
1563 if ( !bRepairPackage )
1565 ::rtl::OUString aStorVersion;
1566 xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) )
1567 >>= aStorVersion;
1569 // if the storage version is set in manifest.xml, it must be the same as in content.xml
1570 // if not, set it explicitly to be used further ( it will work even for readonly storage )
1571 // This workaround is not nice, but I see no other way to handle it, since there are
1572 // ODF1.2 documents without version in manifest.xml
1573 if ( !aStorVersion.isEmpty() )
1574 bResult = aODFVersion.equals( aStorVersion );
1575 else
1576 xStorProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ),
1577 uno::makeAny( aODFVersion ) );
1579 if ( bResult )
1581 sal_Bool bInconsistent = sal_False;
1582 xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsInconsistent" ) ) )
1583 >>= bInconsistent;
1584 bResult = !bInconsistent;
1589 catch( uno::Exception& )
1593 return bResult;
1596 void SvXMLImport::_CreateNumberFormatsSupplier()
1598 DBG_ASSERT( !mxNumberFormatsSupplier.is(),
1599 "number formats supplier already exists!" );
1600 if(mxModel.is())
1601 mxNumberFormatsSupplier =
1602 uno::Reference< util::XNumberFormatsSupplier> (mxModel, uno::UNO_QUERY);
1606 void SvXMLImport::_CreateDataStylesImport()
1608 DBG_ASSERT( mpNumImport == NULL, "data styles import already exists!" );
1609 uno::Reference<util::XNumberFormatsSupplier> xNum =
1610 GetNumberFormatsSupplier();
1611 if ( xNum.is() )
1612 mpNumImport = new SvXMLNumFmtHelper(xNum, getServiceFactory());
1616 sal_Unicode SvXMLImport::ConvStarBatsCharToStarSymbol( sal_Unicode c )
1618 sal_Unicode cNew = c;
1619 if( !mpImpl->hBatsFontConv )
1621 OUString sStarBats( RTL_CONSTASCII_USTRINGPARAM( "StarBats" ) );
1622 mpImpl->hBatsFontConv = CreateFontToSubsFontConverter( sStarBats,
1623 FONTTOSUBSFONT_IMPORT|FONTTOSUBSFONT_ONLYOLDSOSYMBOLFONTS );
1624 OSL_ENSURE( mpImpl->hBatsFontConv, "Got no symbol font converter" );
1626 if( mpImpl->hBatsFontConv )
1628 cNew = ConvertFontToSubsFontChar( mpImpl->hBatsFontConv, c );
1631 return cNew;
1634 sal_Unicode SvXMLImport::ConvStarMathCharToStarSymbol( sal_Unicode c )
1636 sal_Unicode cNew = c;
1637 if( !mpImpl->hMathFontConv )
1639 OUString sStarMath( RTL_CONSTASCII_USTRINGPARAM( "StarMath" ) );
1640 mpImpl->hMathFontConv = CreateFontToSubsFontConverter( sStarMath,
1641 FONTTOSUBSFONT_IMPORT|FONTTOSUBSFONT_ONLYOLDSOSYMBOLFONTS );
1642 OSL_ENSURE( mpImpl->hMathFontConv, "Got no symbol font converter" );
1644 if( mpImpl->hMathFontConv )
1646 cNew = ConvertFontToSubsFontChar( mpImpl->hMathFontConv, c );
1649 return cNew;
1654 void SvXMLImport::SetError(
1655 sal_Int32 nId,
1656 const Sequence<OUString>& rMsgParams,
1657 const OUString& rExceptionMessage,
1658 const Reference<xml::sax::XLocator>& rLocator )
1660 // maintain error flags
1661 if ( ( nId & XMLERROR_FLAG_ERROR ) != 0 )
1662 mnErrorFlags |= ERROR_ERROR_OCCURRED;
1663 if ( ( nId & XMLERROR_FLAG_WARNING ) != 0 )
1664 mnErrorFlags |= ERROR_WARNING_OCCURRED;
1665 if ( ( nId & XMLERROR_FLAG_SEVERE ) != 0 )
1666 mnErrorFlags |= ERROR_DO_NOTHING;
1668 // create error list on demand
1669 if ( mpXMLErrors == NULL )
1670 mpXMLErrors = new XMLErrors();
1672 // save error information
1673 // use document locator (if none supplied)
1674 mpXMLErrors->AddRecord( nId, rMsgParams, rExceptionMessage,
1675 rLocator.is() ? rLocator : mxLocator );
1678 void SvXMLImport::SetError(
1679 sal_Int32 nId,
1680 const Sequence<OUString>& rMsgParams)
1682 OUString sEmpty;
1683 SetError( nId, rMsgParams, sEmpty, NULL );
1686 void SvXMLImport::SetError(
1687 sal_Int32 nId)
1689 Sequence<OUString> aSeq(0);
1690 SetError( nId, aSeq );
1693 void SvXMLImport::SetError(
1694 sal_Int32 nId,
1695 const OUString& rMsg1)
1697 Sequence<OUString> aSeq(1);
1698 OUString* pSeq = aSeq.getArray();
1699 pSeq[0] = rMsg1;
1700 SetError( nId, aSeq );
1703 void SvXMLImport::SetError(
1704 sal_Int32 nId,
1705 const OUString& rMsg1,
1706 const OUString& rMsg2)
1708 Sequence<OUString> aSeq(2);
1709 OUString* pSeq = aSeq.getArray();
1710 pSeq[0] = rMsg1;
1711 pSeq[1] = rMsg2;
1712 SetError( nId, aSeq );
1715 void SvXMLImport::DisposingModel()
1717 if( mxFontDecls.Is() )
1718 ((SvXMLStylesContext *)&mxFontDecls)->Clear();
1719 if( mxStyles.Is() )
1720 ((SvXMLStylesContext *)&mxStyles)->Clear();
1721 if( mxAutoStyles.Is() )
1722 ((SvXMLStylesContext *)&mxAutoStyles)->Clear();
1723 if( mxMasterStyles.Is() )
1724 ((SvXMLStylesContext *)&mxMasterStyles)->Clear();
1726 mxModel.set(0);
1727 mxEventListener.set(NULL);
1730 ::comphelper::UnoInterfaceToUniqueIdentifierMapper& SvXMLImport::getInterfaceToIdentifierMapper()
1732 return mpImpl->maInterfaceToIdentifierMapper;
1735 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > SvXMLImport::getServiceFactory()
1737 // #110680#
1738 return mxServiceFactory;
1741 uno::Reference< uno::XComponentContext >
1742 SvXMLImport::GetComponentContext() const
1744 return mpImpl->mxComponentContext;
1747 ::rtl::OUString SvXMLImport::GetBaseURL() const
1749 return mpImpl->aBaseURL.GetMainURL( INetURLObject::NO_DECODE );
1752 ::rtl::OUString SvXMLImport::GetDocumentBase() const
1754 return mpImpl->aDocBase.GetMainURL( INetURLObject::NO_DECODE );
1757 ::rtl::OUString SvXMLImport::GetStreamName() const
1759 return mpImpl->mStreamName;
1762 // Convert drawing object positions from OOo file format to OASIS (#i28749#)
1763 sal_Bool SvXMLImport::IsShapePositionInHoriL2R() const
1765 return mpImpl->mbShapePositionInHoriL2R;
1768 sal_Bool SvXMLImport::IsTextDocInOOoFileFormat() const
1770 return mpImpl->mbTextDocInOOoFileFormat;
1773 void SvXMLImport::initXForms()
1775 // dummy method; to be implemented by derived classes supporting XForms
1778 bool SvXMLImport::getBuildIds( sal_Int32& rUPD, sal_Int32& rBuild ) const
1780 bool bRet = false;
1781 if( mxImportInfo.is() ) try
1783 const OUString aPropName(RTL_CONSTASCII_USTRINGPARAM("BuildId"));
1784 Reference< XPropertySetInfo > xSetInfo( mxImportInfo->getPropertySetInfo() );
1785 if( xSetInfo.is() && xSetInfo->hasPropertyByName( aPropName ) )
1787 OUString aBuildId;
1788 mxImportInfo->getPropertyValue( aPropName ) >>= aBuildId;
1789 if( !aBuildId.isEmpty() )
1791 sal_Int32 nIndex = aBuildId.indexOf('$');
1792 if( nIndex != -1 )
1794 rUPD = aBuildId.copy( 0, nIndex ).toInt32();
1795 rBuild = aBuildId.copy( nIndex+1 ).toInt32();
1796 bRet = true;
1801 catch( Exception& )
1804 return bRet;
1807 sal_uInt16 SvXMLImport::getGeneratorVersion() const
1809 sal_Int32 nUPD, nBuild;
1811 if( getBuildIds( nUPD, nBuild ) )
1813 if( nUPD == 680 )
1814 return OOo_2x;
1816 if( nUPD >= 640 && nUPD <= 645 )
1817 return OOo_1x;
1820 return OOo_Current;
1823 bool SvXMLImport::isGraphicLoadOnDemandSupported() const
1825 return mbIsGraphicLoadOnDemandSupported;
1828 ::rtl::OUString SvXMLImport::GetODFVersion() const
1830 return mpImpl->aODFVersion;
1833 // xml:id for RDF metadata
1834 void SvXMLImport::SetXmlId(uno::Reference<uno::XInterface> const & i_xIfc,
1835 ::rtl::OUString const & i_rXmlId)
1837 if (!i_rXmlId.isEmpty()) {
1838 try {
1839 const uno::Reference<rdf::XMetadatable> xMeta(i_xIfc,
1840 uno::UNO_QUERY);
1841 //FIXME: not yet
1842 if (xMeta.is()) {
1843 const beans::StringPair mdref( GetStreamName(), i_rXmlId );
1844 try {
1845 xMeta->setMetadataReference(mdref);
1846 } catch (lang::IllegalArgumentException &) {
1847 // probably duplicate; ignore
1848 OSL_TRACE("SvXMLImport::SetXmlId: cannot set xml:id");
1851 } catch (uno::Exception &) {
1852 OSL_FAIL("SvXMLImport::SetXmlId: exception?");
1857 SAL_DLLPRIVATE ::xmloff::RDFaImportHelper &
1858 SvXMLImport::GetRDFaImportHelper()
1860 if (!mpImpl->mpRDFaHelper.get())
1862 mpImpl->mpRDFaHelper.reset( new ::xmloff::RDFaImportHelper(*this) );
1864 return *mpImpl->mpRDFaHelper;
1867 void
1868 SvXMLImport::AddRDFa(uno::Reference<rdf::XMetadatable> i_xObject,
1869 ::rtl::OUString const & i_rAbout,
1870 ::rtl::OUString const & i_rProperty,
1871 ::rtl::OUString const & i_rContent,
1872 ::rtl::OUString const & i_rDatatype)
1874 // N.B.: we only get called if i_xObject had xhtml:about attribute
1875 // (an empty attribute value is valid)
1876 ::xmloff::RDFaImportHelper & rRDFaHelper( GetRDFaImportHelper() );
1877 rRDFaHelper.ParseAndAddRDFa(i_xObject,
1878 i_rAbout, i_rProperty, i_rContent, i_rDatatype);
1881 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */