1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <tools/diagnose_ex.h>
23 #include <com/sun/star/beans/XPropertySetInfo.hpp>
24 #include <tools/urlobj.hxx>
25 #include <osl/mutex.hxx>
26 #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
27 #include <xmloff/nmspmap.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <xmloff/xmlnmspe.hxx>
30 #include <xmloff/xmltoken.hxx>
31 #include <xmloff/XMLFontStylesContext.hxx>
32 #include <xmloff/xmlictxt.hxx>
33 #include <xmloff/xmlimp.hxx>
34 #include <xmloff/xmlnumfi.hxx>
35 #include "XMLEventImportHelper.hxx"
36 #include "XMLStarBasicContextFactory.hxx"
37 #include "XMLScriptContextFactory.hxx"
38 #include "StyleMap.hxx"
39 #include <xmloff/ProgressBarHelper.hxx>
40 #include <xmloff/xmlerror.hxx>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
43 #include <com/sun/star/io/XOutputStream.hpp>
44 #include <com/sun/star/util/MeasureUnit.hpp>
45 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
46 #include <com/sun/star/document/XStorageBasedDocument.hpp>
47 #include <com/sun/star/xml/sax/XLocator.hpp>
48 #include <com/sun/star/packages/zip/ZipIOException.hpp>
49 #include <comphelper/namecontainer.hxx>
50 #include <comphelper/servicehelper.hxx>
51 #include <cppuhelper/implbase1.hxx>
52 #include <cppuhelper/supportsservice.hxx>
53 #include <comphelper/extract.hxx>
54 #include <comphelper/processfactory.hxx>
55 #include <comphelper/documentconstants.hxx>
56 #include <comphelper/storagehelper.hxx>
57 #include <unotools/fontcvt.hxx>
59 #include <com/sun/star/rdf/XMetadatable.hpp>
60 #include <com/sun/star/rdf/XRepositorySupplier.hpp>
61 #include "RDFaImportHelper.hxx"
63 using ::com::sun::star::beans::XPropertySetInfo
;
65 using namespace ::osl
;
66 using namespace ::com::sun::star
;
67 using namespace ::com::sun::star::frame
;
68 using namespace ::com::sun::star::uno
;
69 using namespace ::com::sun::star::util
;
70 using namespace ::com::sun::star::io
;
71 using namespace ::com::sun::star::container
;
72 using namespace ::com::sun::star::document
;
73 using namespace ::xmloff::token
;
75 sal_Char
const sXML_np__office
[] = "_office";
76 sal_Char
const sXML_np__office_ext
[] = "_office_ooo";
77 sal_Char
const sXML_np__ooo
[] = "_ooo";
78 sal_Char
const sXML_np__ooow
[] = "_ooow";
79 sal_Char
const sXML_np__oooc
[] = "_oooc";
80 sal_Char
const sXML_np__of
[] = "_of";
81 sal_Char
const sXML_np__style
[] = "_style";
82 sal_Char
const sXML_np__text
[] = "_text";
83 sal_Char
const sXML_np__table
[] = "_table";
84 sal_Char
const sXML_np__table_ext
[] = "_table_ooo";
85 sal_Char
const sXML_np__draw
[] = "_draw";
86 sal_Char
const sXML_np__draw_ext
[] = "_draw_ooo";
87 sal_Char
const sXML_np__dr3d
[] = "_dr3d";
88 sal_Char
const sXML_np__fo
[] = "_fo";
89 sal_Char
const sXML_np__xlink
[] = "_xlink";
90 sal_Char
const sXML_np__dc
[] = "_dc";
91 sal_Char
const sXML_np__dom
[] = "_dom";
92 sal_Char
const sXML_np__meta
[] = "_meta";
93 sal_Char
const sXML_np__number
[] = "_number";
94 sal_Char
const sXML_np__svg
[] = "_svg";
95 sal_Char
const sXML_np__chart
[] = "_chart";
96 sal_Char
const sXML_np__math
[] = "_math";
97 sal_Char
const sXML_np__form
[] = "_form";
98 sal_Char
const sXML_np__script
[] = "_script";
99 sal_Char
const sXML_np__config
[] = "_config";
100 sal_Char
const sXML_np__xforms
[] = "_xforms";
101 sal_Char
const sXML_np__formx
[] = "_formx";
102 sal_Char
const sXML_np__xsd
[] = "_xsd";
103 sal_Char
const sXML_np__xsi
[] = "_xsi";
104 sal_Char
const sXML_np__field
[] = "_field";
105 sal_Char
const sXML_np__xhtml
[] = "_xhtml";
106 sal_Char
const sXML_np__css3text
[] = "_css3text";
108 class SvXMLImportEventListener
: public cppu::WeakImplHelper1
<
109 com::sun::star::lang::XEventListener
>
112 SvXMLImport
* pImport
;
115 SvXMLImportEventListener(SvXMLImport
* pImport
);
116 virtual ~SvXMLImportEventListener();
119 virtual void SAL_CALL
disposing(const lang::EventObject
& rEventObject
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
122 SvXMLImportEventListener::SvXMLImportEventListener(SvXMLImport
* pTempImport
)
123 : pImport(pTempImport
)
127 SvXMLImportEventListener::~SvXMLImportEventListener()
132 void SAL_CALL
SvXMLImportEventListener::disposing( const lang::EventObject
& )
133 throw(uno::RuntimeException
, std::exception
)
137 pImport
->DisposingModel();
146 getBuildIdsProperty(uno::Reference
<beans::XPropertySet
> const& xImportInfo
)
148 if (xImportInfo
.is())
152 Reference
< XPropertySetInfo
> const xSetInfo(
153 xImportInfo
->getPropertySetInfo());
154 if (xSetInfo
.is() && xSetInfo
->hasPropertyByName("BuildId"))
157 xImportInfo
->getPropertyValue("BuildId") >>= aBuildId
;
161 catch (Exception
const&)
163 SAL_WARN("xmloff.core", "exception getting BuildId");
164 DBG_UNHANDLED_EXCEPTION();
173 sal_uInt16 mnGeneratorVersion
;
176 DocumentInfo( const SvXMLImport
& rImport
)
177 : mnGeneratorVersion( SvXMLImport::ProductVersionUnknown
)
179 OUString
const buildIds(
180 getBuildIdsProperty(rImport
.getImportInfo()));
181 if (!buildIds
.isEmpty())
183 sal_Int32
const ix
= buildIds
.indexOf(';');
186 OUString
const loVersion(buildIds
.copy(ix
+ 1));
187 if (!loVersion
.isEmpty())
189 if ('3' == loVersion
[0])
191 mnGeneratorVersion
= SvXMLImport::LO_3x
;
193 else if ('4' == loVersion
[0])
195 if (loVersion
.getLength() > 1
196 && (loVersion
[1] == '0' || loVersion
[1] == '1'))
198 mnGeneratorVersion
= SvXMLImport::LO_41x
; // 4.0/4.1
200 else if (loVersion
.getLength() > 1 && '2' == loVersion
[1])
202 mnGeneratorVersion
= SvXMLImport::LO_42x
; // 4.2
204 else if (loVersion
.getLength() > 1 && '3' == loVersion
[1])
206 mnGeneratorVersion
= SvXMLImport::LO_43x
; // 4.3
208 else if (loVersion
.getLength() > 1 && '4' == loVersion
[1])
210 mnGeneratorVersion
= SvXMLImport::LO_44x
; // 4.4
215 SAL_INFO_IF('5' != loVersion
[0], "xmloff.core", "unknown LO version: " << loVersion
);
216 mnGeneratorVersion
= SvXMLImport::LO_5x
;
218 return; // ignore buildIds
222 sal_Int32 nUPD
, nBuild
;
223 if ( rImport
.getBuildIds( nUPD
, nBuild
) )
225 if ( nUPD
>= 640 && nUPD
<= 645 )
227 mnGeneratorVersion
= SvXMLImport::OOo_1x
;
229 else if ( nUPD
== 680 )
231 mnGeneratorVersion
= SvXMLImport::OOo_2x
;
233 else if ( nUPD
== 300 && nBuild
<= 9379 )
235 mnGeneratorVersion
= SvXMLImport::OOo_30x
;
237 else if ( nUPD
== 310 )
239 mnGeneratorVersion
= SvXMLImport::OOo_31x
;
241 else if ( nUPD
== 320 )
243 mnGeneratorVersion
= SvXMLImport::OOo_32x
;
245 else if ( nUPD
== 330 )
247 mnGeneratorVersion
= SvXMLImport::OOo_33x
;
249 else if ( nUPD
== 340 )
251 mnGeneratorVersion
= SvXMLImport::OOo_34x
;
253 else if (nUPD
== 400)
255 mnGeneratorVersion
= SvXMLImport::AOO_40x
;
257 else if (nUPD
>= 410)
259 // effectively this means "latest", see use
260 // in XMLGraphicsDefaultStyle::SetDefaults()!
261 mnGeneratorVersion
= SvXMLImport::AOO_4x
;
269 sal_uInt16
getGeneratorVersion() const
271 return mnGeneratorVersion
;
276 class SvXMLImport_Impl
279 FontToSubsFontConverter hBatsFontConv
;
280 FontToSubsFontConverter hMathFontConv
;
282 bool mbOwnGraphicResolver
;
283 bool mbOwnEmbeddedResolver
;
284 INetURLObject aBaseURL
;
285 INetURLObject aDocBase
;
287 /// name of stream in package, e.g., "content.xml"
288 OUString mStreamName
;
290 OUString aODFVersion
;
294 // Boolean, indicating that position attributes
295 // of shapes are given in horizontal left-to-right layout. This is the case
296 // for the OpenOffice.org file format. (#i28749#)
297 bool mbShapePositionInHoriL2R
;
298 bool mbTextDocInOOoFileFormat
;
300 const uno::Reference
< uno::XComponentContext
> mxComponentContext
;
301 OUString implementationName
;
303 uno::Reference
< embed::XStorage
> mxSourceStorage
;
305 std::unique_ptr
< xmloff::RDFaImportHelper
> mpRDFaHelper
;
307 std::unique_ptr
< DocumentInfo
> mpDocumentInfo
;
309 SvXMLImport_Impl( const uno::Reference
< uno::XComponentContext
>& rxContext
,
310 OUString
const & theImplementationName
)
313 , mbOwnGraphicResolver( false )
314 , mbOwnEmbeddedResolver( false )
316 // Convert drawing object positions from OOo file format to OASIS (#i28749#)
317 , mbShapePositionInHoriL2R( false )
318 , mbTextDocInOOoFileFormat( false )
319 , mxComponentContext( rxContext
)
320 , implementationName(theImplementationName
)
321 , mpRDFaHelper() // lazy
322 , mpDocumentInfo() // lazy
324 SAL_WARN_IF(!mxComponentContext
.is(), "xmloff.core", "SvXMLImport: no ComponentContext");
325 if (!mxComponentContext
.is()) throw uno::RuntimeException();
331 DestroyFontToSubsFontConverter( hBatsFontConv
);
333 DestroyFontToSubsFontConverter( hMathFontConv
);
336 sal_uInt16
getGeneratorVersion( const SvXMLImport
& rImport
)
338 if ( !mpDocumentInfo
.get() )
340 mpDocumentInfo
.reset( new DocumentInfo( rImport
) );
343 return mpDocumentInfo
->getGeneratorVersion();
346 ::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper
;
349 SvXMLImportContext
*SvXMLImport::CreateContext( sal_uInt16 nPrefix
,
350 const OUString
& rLocalName
,
351 const uno::Reference
< xml::sax::XAttributeList
>& )
353 return new SvXMLImportContext( *this, nPrefix
, rLocalName
);
356 SvXMLImportContext
*SvXMLImport::CreateFastContext( sal_Int32
/*Element*/,
357 const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
359 return new SvXMLImportContext( *this );
362 void SvXMLImport::_InitCtor()
364 if( mnImportFlags
!= SvXMLImportFlags::NONE
)
366 // implicit "xml" namespace prefix
367 mpNamespaceMap
->Add( GetXMLToken(XML_XML
), GetXMLToken(XML_N_XML
), XML_NAMESPACE_XML
);
368 mpNamespaceMap
->Add( OUString( sXML_np__office
), GetXMLToken(XML_N_OFFICE
), XML_NAMESPACE_OFFICE
);
369 mpNamespaceMap
->Add( OUString( sXML_np__office_ext
), GetXMLToken(XML_N_OFFICE_EXT
), XML_NAMESPACE_OFFICE_EXT
);
370 mpNamespaceMap
->Add( OUString( sXML_np__ooo
), GetXMLToken(XML_N_OOO
), XML_NAMESPACE_OOO
);
371 mpNamespaceMap
->Add( OUString( sXML_np__style
), GetXMLToken(XML_N_STYLE
), XML_NAMESPACE_STYLE
);
372 mpNamespaceMap
->Add( OUString( sXML_np__text
), GetXMLToken(XML_N_TEXT
), XML_NAMESPACE_TEXT
);
373 mpNamespaceMap
->Add( OUString( sXML_np__table
), GetXMLToken(XML_N_TABLE
), XML_NAMESPACE_TABLE
);
374 mpNamespaceMap
->Add( OUString( sXML_np__table_ext
), GetXMLToken(XML_N_TABLE_EXT
), XML_NAMESPACE_TABLE_EXT
);
375 mpNamespaceMap
->Add( OUString( sXML_np__draw
), GetXMLToken(XML_N_DRAW
), XML_NAMESPACE_DRAW
);
376 mpNamespaceMap
->Add( OUString( sXML_np__draw_ext
), GetXMLToken(XML_N_DRAW_EXT
), XML_NAMESPACE_DRAW_EXT
);
377 mpNamespaceMap
->Add( OUString( sXML_np__dr3d
), GetXMLToken(XML_N_DR3D
), XML_NAMESPACE_DR3D
);
378 mpNamespaceMap
->Add( OUString( sXML_np__fo
), GetXMLToken(XML_N_FO_COMPAT
), XML_NAMESPACE_FO
);
379 mpNamespaceMap
->Add( OUString( sXML_np__xlink
), GetXMLToken(XML_N_XLINK
), XML_NAMESPACE_XLINK
);
380 mpNamespaceMap
->Add( OUString( sXML_np__dc
), GetXMLToken(XML_N_DC
), XML_NAMESPACE_DC
);
381 mpNamespaceMap
->Add( OUString( sXML_np__dom
), GetXMLToken(XML_N_DOM
), XML_NAMESPACE_DOM
);
382 mpNamespaceMap
->Add( OUString( sXML_np__meta
), GetXMLToken(XML_N_META
), XML_NAMESPACE_META
);
383 mpNamespaceMap
->Add( OUString( sXML_np__number
), GetXMLToken(XML_N_NUMBER
), XML_NAMESPACE_NUMBER
);
384 mpNamespaceMap
->Add( OUString( sXML_np__svg
), GetXMLToken(XML_N_SVG_COMPAT
), XML_NAMESPACE_SVG
);
385 mpNamespaceMap
->Add( OUString( sXML_np__chart
), GetXMLToken(XML_N_CHART
), XML_NAMESPACE_CHART
);
386 mpNamespaceMap
->Add( OUString( sXML_np__math
), GetXMLToken(XML_N_MATH
), XML_NAMESPACE_MATH
);
387 mpNamespaceMap
->Add(OUString( sXML_np__form
), GetXMLToken(XML_N_FORM
), XML_NAMESPACE_FORM
);
388 mpNamespaceMap
->Add( OUString( sXML_np__script
), GetXMLToken(XML_N_SCRIPT
), XML_NAMESPACE_SCRIPT
);
389 mpNamespaceMap
->Add( OUString( sXML_np__config
), GetXMLToken(XML_N_CONFIG
), XML_NAMESPACE_CONFIG
);
390 mpNamespaceMap
->Add( OUString( sXML_np__xforms
), GetXMLToken(XML_N_XFORMS_1_0
), XML_NAMESPACE_XFORMS
);
391 mpNamespaceMap
->Add( OUString( sXML_np__formx
), GetXMLToken( XML_N_FORMX
), XML_NAMESPACE_FORMX
);
392 mpNamespaceMap
->Add( OUString( sXML_np__xsd
), GetXMLToken(XML_N_XSD
), XML_NAMESPACE_XSD
);
393 mpNamespaceMap
->Add( OUString( sXML_np__xsi
), GetXMLToken(XML_N_XSI
), XML_NAMESPACE_XFORMS
);
394 mpNamespaceMap
->Add( OUString( sXML_np__ooow
), GetXMLToken(XML_N_OOOW
), XML_NAMESPACE_OOOW
);
395 mpNamespaceMap
->Add( OUString( sXML_np__oooc
), GetXMLToken(XML_N_OOOC
), XML_NAMESPACE_OOOC
);
396 mpNamespaceMap
->Add( OUString( sXML_np__field
), GetXMLToken(XML_N_FIELD
), XML_NAMESPACE_FIELD
);
397 mpNamespaceMap
->Add( OUString( sXML_np__of
), GetXMLToken(XML_N_OF
), XML_NAMESPACE_OF
);
398 mpNamespaceMap
->Add( OUString( sXML_np__xhtml
), GetXMLToken(XML_N_XHTML
), XML_NAMESPACE_XHTML
);
399 mpNamespaceMap
->Add( OUString( sXML_np__css3text
), GetXMLToken(XML_N_CSS3TEXT
), XML_NAMESPACE_CSS3TEXT
);
401 mpNamespaceMap
->Add( "_calc_libo", GetXMLToken(XML_N_CALC_EXT
), XML_NAMESPACE_CALC_EXT
);
402 mpNamespaceMap
->Add( "_office_libo",
403 GetXMLToken(XML_N_LO_EXT
), XML_NAMESPACE_LO_EXT
);
406 msPackageProtocol
= "vnd.sun.star.Package:";
408 if (mxNumberFormatsSupplier
.is())
409 mpNumImport
= new SvXMLNumFmtHelper(mxNumberFormatsSupplier
, GetComponentContext());
411 if (mxModel
.is() && !mxEventListener
.is())
413 mxEventListener
.set(new SvXMLImportEventListener(this));
414 mxModel
->addEventListener(mxEventListener
);
417 ::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper
;
421 SvXMLImport::SvXMLImport(
422 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& xContext
,
423 OUString
const & implementationName
, SvXMLImportFlags nImportFlags
) throw ()
424 : mpImpl( new SvXMLImport_Impl(xContext
, implementationName
) ),
425 mpNamespaceMap( new SvXMLNamespaceMap
),
427 mpUnitConv( new SvXMLUnitConverter( xContext
,
428 util::MeasureUnit::MM_100TH
, util::MeasureUnit::MM_100TH
) ),
430 mpContexts( new SvXMLImportContexts_Impl
),
431 mpFastContexts( new FastSvXMLImportContexts_Impl
),
433 mpProgressBarHelper( NULL
),
434 mpEventImportHelper( NULL
),
437 mnImportFlags( nImportFlags
),
438 mnErrorFlags(SvXMLErrorFlags::NO
),
439 mbIsFormsSupported( true ),
440 mbIsTableShapeSupported( false ),
441 mbIsGraphicLoadOnDemandSupported( true )
443 SAL_WARN_IF( !xContext
.is(), "xmloff.core", "got no service manager" );
447 SvXMLImport::~SvXMLImport() throw ()
450 delete mpNamespaceMap
;
452 delete mpEventImportHelper
;
453 delete mpFastContexts
;
456 while( !mpContexts
->empty() )
458 SvXMLImportContext
*pContext
= mpContexts
->back();
459 mpContexts
->pop_back();
461 pContext
->ReleaseRef();
466 // #i9518# the import component might not be deleted until after the document has been closed,
467 // so the stuff that accesses the document has been moved to endDocument.
469 // pNumImport is allocated in the ctor, so it must also be deleted here in case the component
470 // is created and deleted without actually importing.
472 delete mpProgressBarHelper
;
476 if (mxEventListener
.is() && mxModel
.is())
477 mxModel
->removeEventListener(mxEventListener
);
482 class theSvXMLImportUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theSvXMLImportUnoTunnelId
> {};
486 const uno::Sequence
< sal_Int8
> & SvXMLImport::getUnoTunnelId() throw()
488 return theSvXMLImportUnoTunnelId::get().getSeq();
492 sal_Int64 SAL_CALL
SvXMLImport::getSomething( const uno::Sequence
< sal_Int8
>& rId
)
493 throw( uno::RuntimeException
, std::exception
)
495 if( rId
.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
496 rId
.getConstArray(), 16 ) )
498 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_uIntPtr
>(this));
503 void SAL_CALL
SvXMLImport::startDocument()
504 throw (xml::sax::SAXException
,
505 uno::RuntimeException
,
508 SAL_INFO( "xmloff.core", "{ SvXMLImport::startDocument" );
509 if( !mxGraphicResolver
.is() || !mxEmbeddedResolver
.is() )
511 Reference
< lang::XMultiServiceFactory
> xFactory( mxModel
, UNO_QUERY
);
516 if( !mxGraphicResolver
.is() )
518 mxGraphicResolver
= Reference
< XGraphicObjectResolver
>::query(
519 xFactory
->createInstance(
520 // #99870# Import... instead of Export...
521 "com.sun.star.document.ImportGraphicObjectResolver"));
522 mpImpl
->mbOwnGraphicResolver
= mxGraphicResolver
.is();
525 if( !mxEmbeddedResolver
.is() )
527 mxEmbeddedResolver
= Reference
< XEmbeddedObjectResolver
>::query(
528 xFactory
->createInstance(
529 // #99870# Import... instead of Export...
530 "com.sun.star.document.ImportEmbeddedObjectResolver"));
531 mpImpl
->mbOwnEmbeddedResolver
= mxEmbeddedResolver
.is();
534 catch( com::sun::star::uno::Exception
& )
541 void SAL_CALL
SvXMLImport::endDocument()
542 throw(xml::sax::SAXException
,
543 uno::RuntimeException
,
546 SAL_INFO( "xmloff.core", "} SvXMLImport::startDocument" );
547 // #i9518# All the stuff that accesses the document has to be done here, not in the dtor,
548 // because the SvXMLImport dtor might not be called until after the document has been closed.
550 if (mpImpl
->mpRDFaHelper
.get())
552 const uno::Reference
<rdf::XRepositorySupplier
> xRS(mxModel
,
556 mpImpl
->mpRDFaHelper
->InsertRDFa( xRS
);
565 if (mxImportInfo
.is())
567 uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo
= mxImportInfo
->getPropertySetInfo();
568 if (xPropertySetInfo
.is())
570 if (mpProgressBarHelper
)
572 OUString
sProgressMax(XML_PROGRESSMAX
);
573 OUString
sProgressCurrent(XML_PROGRESSCURRENT
);
574 OUString
sRepeat(XML_PROGRESSREPEAT
);
575 if (xPropertySetInfo
->hasPropertyByName(sProgressMax
) &&
576 xPropertySetInfo
->hasPropertyByName(sProgressCurrent
))
578 sal_Int32
nProgressMax(mpProgressBarHelper
->GetReference());
579 sal_Int32
nProgressCurrent(mpProgressBarHelper
->GetValue());
581 aAny
<<= nProgressMax
;
582 mxImportInfo
->setPropertyValue(sProgressMax
, aAny
);
583 aAny
<<= nProgressCurrent
;
584 mxImportInfo
->setPropertyValue(sProgressCurrent
, aAny
);
586 if (xPropertySetInfo
->hasPropertyByName(sRepeat
))
587 mxImportInfo
->setPropertyValue(sRepeat
, css::uno::makeAny(mpProgressBarHelper
->GetRepeat()));
588 // pProgressBarHelper is deleted in dtor
590 OUString
sNumberStyles(XML_NUMBERSTYLES
);
591 if (mxNumberStyles
.is() && xPropertySetInfo
->hasPropertyByName(sNumberStyles
))
594 aAny
<<= mxNumberStyles
;
595 mxImportInfo
->setPropertyValue(sNumberStyles
, aAny
);
600 if( mxFontDecls
.Is() )
601 static_cast<SvXMLStylesContext
*>(&mxFontDecls
)->Clear();
603 static_cast<SvXMLStylesContext
*>(&mxStyles
)->Clear();
604 if( mxAutoStyles
.Is() )
605 static_cast<SvXMLStylesContext
*>(&mxAutoStyles
)->Clear();
606 if( mxMasterStyles
.Is() )
607 static_cast<SvXMLStylesContext
*>(&mxMasterStyles
)->Clear();
609 // possible form-layer related knittings which can only be done when
610 // the whole document exists
611 if ( mxFormImport
.is() )
612 mxFormImport
->documentDone();
614 // The shape import helper does the z-order sorting in the dtor,
615 // so it must be deleted here, too.
616 mxShapeImport
= NULL
;
618 if( mpImpl
->mbOwnGraphicResolver
)
620 Reference
< lang::XComponent
> xComp( mxGraphicResolver
, UNO_QUERY
);
624 if( mpImpl
->mbOwnEmbeddedResolver
)
626 Reference
< lang::XComponent
> xComp( mxEmbeddedResolver
, UNO_QUERY
);
631 mpStyleMap
->release();
635 if ( mpXMLErrors
!= NULL
)
637 mpXMLErrors
->ThrowErrorAsSAXException( XMLERROR_FLAG_SEVERE
);
641 void SAL_CALL
SvXMLImport::startElement( const OUString
& rName
,
642 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
643 throw(xml::sax::SAXException
, uno::RuntimeException
, std::exception
)
645 SvXMLNamespaceMap
*pRewindMap
= 0;
646 // SAL_INFO("svg", "startElement " << rName);
647 // Process namespace attributes. This must happen before creating the
648 // context, because namespace decaration apply to the element name itself.
649 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
650 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
652 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
653 if ( rAttrName
== "office:version" )
655 mpImpl
->aODFVersion
= xAttrList
->getValueByIndex( i
);
657 // the ODF version in content.xml and manifest.xml must be the same starting from ODF1.2
658 if ( mpImpl
->mStreamName
== "content.xml" && !IsODFVersionConsistent( mpImpl
->aODFVersion
) )
660 throw xml::sax::SAXException("Inconsistent ODF versions in content.xml and manifest.xml!",
661 uno::Reference
< uno::XInterface
>(),
663 packages::zip::ZipIOException("Inconsistent ODF versions in content.xml and manifest.xml!" ) ) );
666 else if( ( rAttrName
.getLength() >= 5 ) &&
667 ( rAttrName
.startsWith( GetXMLToken(XML_XMLNS
) ) ) &&
668 ( rAttrName
.getLength() == 5 || ':' == rAttrName
[5] ) )
672 pRewindMap
= mpNamespaceMap
;
673 mpNamespaceMap
= new SvXMLNamespaceMap( *mpNamespaceMap
);
675 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
677 OUString
aPrefix( ( rAttrName
.getLength() == 5 )
679 : rAttrName
.copy( 6 ) );
680 // Add namespace, but only if it is known.
681 sal_uInt16 nKey
= mpNamespaceMap
->AddIfKnown( aPrefix
, rAttrValue
);
682 // If namespace is unknown, try to match a name with similar
684 if( XML_NAMESPACE_UNKNOWN
== nKey
)
686 OUString
aTestName( rAttrValue
);
687 if( SvXMLNamespaceMap::NormalizeURI( aTestName
) )
688 nKey
= mpNamespaceMap
->AddIfKnown( aPrefix
, aTestName
);
690 // If that namespace is not known, too, add it as unknown
691 if( XML_NAMESPACE_UNKNOWN
== nKey
)
692 mpNamespaceMap
->Add( aPrefix
, rAttrValue
);
697 // Get element's namespace and local name.
700 mpNamespaceMap
->GetKeyByAttrName( rName
, &aLocalName
);
702 // If there are contexts already, call a CreateChildContext at the topmost
703 // context. Otherwise, create a default context.
704 SvXMLImportContext
*pContext
;
705 sal_uInt16 nCount
= mpContexts
->size();
708 pContext
= (*mpContexts
)[nCount
- 1]->CreateChildContext( nPrefix
,
711 SAL_WARN_IF( !pContext
|| (pContext
->GetPrefix() != nPrefix
), "xmloff.core",
712 "SvXMLImport::startElement: created context has wrong prefix" );
716 pContext
= CreateContext( nPrefix
, aLocalName
, xAttrList
);
717 if( (nPrefix
& XML_NAMESPACE_UNKNOWN_FLAG
) != 0 &&
718 IS_TYPE( SvXMLImportContext
, pContext
) )
720 OUString
aMsg( "Root element unknown" );
721 Reference
<xml::sax::XLocator
> xDummyLocator
;
722 Sequence
< OUString
> aParams(1);
723 aParams
.getArray()[0] = rName
;
725 SetError( XMLERROR_FLAG_SEVERE
|XMLERROR_UNKNOWN_ROOT
,
726 aParams
, aMsg
, xDummyLocator
);
730 SAL_WARN_IF( !pContext
, "xmloff.core", "SvXMLImport::startElement: missing context" );
732 pContext
= new SvXMLImportContext( *this, nPrefix
, aLocalName
);
734 pContext
->AddFirstRef();
736 // Remember old namespace map.
738 pContext
->SetRewindMap( pRewindMap
);
740 // Call a startElement at the new context.
741 pContext
->StartElement( xAttrList
);
743 // Push context on stack.
744 mpContexts
->push_back( pContext
);
747 void SAL_CALL
SvXMLImport::endElement( const OUString
&
752 throw(xml::sax::SAXException
, uno::RuntimeException
, std::exception
)
754 sal_uInt16 nCount
= mpContexts
->size();
755 SAL_WARN_IF( nCount
== 0, "xmloff.core", "SvXMLImport::endElement: no context left" );
758 // Get topmost context and remove it from the stack.
759 SvXMLImportContext
*pContext
= mpContexts
->back();
760 mpContexts
->pop_back();
763 // Non product only: check if endElement call matches startELement call.
766 mpNamespaceMap
->GetKeyByAttrName( rName
, &aLocalName
);
767 SAL_WARN_IF( pContext
->GetPrefix() != nPrefix
, "xmloff.core", "SvXMLImport::endElement: popped context has wrong prefix" );
768 SAL_WARN_IF( pContext
->GetLocalName() != aLocalName
, "xmloff.core", "SvXMLImport::endElement: popped context has wrong lname" );
771 // Call a EndElement at the current context.
772 pContext
->EndElement();
774 // Get a namespace map to rewind.
775 SvXMLNamespaceMap
*pRewindMap
= pContext
->GetRewindMap();
777 // Delete the current context.
778 pContext
->ReleaseRef();
781 // Rewind a namespace map.
784 delete mpNamespaceMap
;
785 mpNamespaceMap
= pRewindMap
;
790 void SAL_CALL
SvXMLImport::characters( const OUString
& rChars
)
791 throw(xml::sax::SAXException
, uno::RuntimeException
, std::exception
)
793 if( !mpContexts
->empty() )
795 mpContexts
->back()->Characters( rChars
);
797 else if ( !mpFastContexts
->empty() )
799 mpFastContexts
->back()->characters( rChars
);
803 void SAL_CALL
SvXMLImport::ignorableWhitespace( const OUString
& )
804 throw(xml::sax::SAXException
, uno::RuntimeException
, std::exception
)
808 void SAL_CALL
SvXMLImport::processingInstruction( const OUString
&,
810 throw(xml::sax::SAXException
, uno::RuntimeException
, std::exception
)
814 void SAL_CALL
SvXMLImport::setDocumentLocator( const uno::Reference
< xml::sax::XLocator
>& rLocator
)
815 throw(xml::sax::SAXException
, uno::RuntimeException
, std::exception
)
817 mxLocator
= rLocator
;
820 // XFastContextHandler
821 void SAL_CALL
SvXMLImport::startFastElement (sal_Int32 Element
,
822 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
823 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
825 //Namespace handling is unnecessary. It is done by the fastparser itself.
826 uno::Reference
<XFastContextHandler
> xContext
;
827 sal_uInt16 nCount
= mpFastContexts
->size();
830 uno::Reference
< XFastContextHandler
> pHandler
= (*mpFastContexts
)[nCount
- 1];
831 xContext
= pHandler
->createFastChildContext( Element
, Attribs
);
834 xContext
.set( CreateFastContext( Element
, Attribs
) );
836 if ( !xContext
.is() )
837 xContext
.set( new SvXMLImportContext( *this ) );
839 // Call a startElement at the new context.
840 xContext
->startFastElement( Element
, Attribs
);
842 // Push context on stack.
843 mpFastContexts
->push_back( xContext
);
846 void SAL_CALL
SvXMLImport::startUnknownElement (const OUString
&, const OUString
&,
847 const uno::Reference
< xml::sax::XFastAttributeList
> &)
848 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
852 void SAL_CALL
SvXMLImport::endFastElement (sal_Int32 Element
)
853 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
855 sal_uInt16 nCount
= mpFastContexts
->size();
858 uno::Reference
< XFastContextHandler
> xContext
= mpFastContexts
->back();
859 mpFastContexts
->pop_back();
860 xContext
->endFastElement( Element
);
865 void SAL_CALL
SvXMLImport::endUnknownElement (const OUString
&, const OUString
&)
866 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
870 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
871 SvXMLImport::createFastChildContext (sal_Int32
,
872 const uno::Reference
< xml::sax::XFastAttributeList
> &)
873 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
878 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
879 SvXMLImport::createUnknownChildContext (const OUString
&, const OUString
&,
880 const uno::Reference
< xml::sax::XFastAttributeList
> &)
881 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
886 // XExtendedDocumentHandler
887 void SAL_CALL
SvXMLImport::startCDATA() throw(xml::sax::SAXException
, uno::RuntimeException
, std::exception
)
891 void SAL_CALL
SvXMLImport::endCDATA() throw(uno::RuntimeException
, std::exception
)
895 void SAL_CALL
SvXMLImport::comment( const OUString
& )
896 throw(xml::sax::SAXException
, uno::RuntimeException
, std::exception
)
900 void SAL_CALL
SvXMLImport::allowLineBreak()
901 throw(xml::sax::SAXException
, uno::RuntimeException
, std::exception
)
905 void SAL_CALL
SvXMLImport::unknown( const OUString
& )
906 throw(xml::sax::SAXException
, uno::RuntimeException
, std::exception
)
910 void SvXMLImport::SetStatistics(const uno::Sequence
< beans::NamedValue
> &)
912 GetProgressBarHelper()->SetRepeat(false);
913 GetProgressBarHelper()->SetReference(0);
917 void SAL_CALL
SvXMLImport::setTargetDocument( const uno::Reference
< lang::XComponent
>& xDoc
)
918 throw(lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
920 mxModel
= uno::Reference
< frame::XModel
>::query( xDoc
);
922 throw lang::IllegalArgumentException();
926 uno::Reference
<document::XStorageBasedDocument
> const xSBDoc(mxModel
,
927 uno::UNO_QUERY_THROW
);
928 uno::Reference
<embed::XStorage
> const xStor(
929 xSBDoc
->getDocumentStorage());
933 ::comphelper::OStorageHelper::GetXStorageFormat(xStor
)
934 < SOFFICE_FILEFORMAT_8
;
937 catch (uno::Exception
const&)
939 SAL_WARN("xmloff.core", "exception caught");
940 DBG_UNHANDLED_EXCEPTION();
942 if (!mxEventListener
.is())
944 mxEventListener
.set(new SvXMLImportEventListener(this));
945 mxModel
->addEventListener(mxEventListener
);
948 SAL_WARN_IF( mpNumImport
, "xmloff.core", "number format import already exists." );
957 sal_Bool SAL_CALL
SvXMLImport::filter( const uno::Sequence
< beans::PropertyValue
>& )
958 throw (uno::RuntimeException
, std::exception
)
963 void SAL_CALL
SvXMLImport::cancel( )
964 throw (uno::RuntimeException
, std::exception
)
969 void SAL_CALL
SvXMLImport::initialize( const uno::Sequence
< uno::Any
>& aArguments
)
970 throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
, std::exception
)
972 const sal_Int32 nAnyCount
= aArguments
.getLength();
973 const uno::Any
* pAny
= aArguments
.getConstArray();
975 for( sal_Int32 nIndex
= 0; nIndex
< nAnyCount
; nIndex
++, pAny
++ )
977 Reference
<XInterface
> xValue
;
980 uno::Reference
<task::XStatusIndicator
> xTmpStatusIndicator(
982 if( xTmpStatusIndicator
.is() )
983 mxStatusIndicator
= xTmpStatusIndicator
;
985 uno::Reference
<document::XGraphicObjectResolver
> xTmpGraphicResolver(
987 if( xTmpGraphicResolver
.is() )
988 mxGraphicResolver
= xTmpGraphicResolver
;
990 uno::Reference
<document::XEmbeddedObjectResolver
> xTmpObjectResolver(
992 if( xTmpObjectResolver
.is() )
993 mxEmbeddedResolver
= xTmpObjectResolver
;
995 uno::Reference
<beans::XPropertySet
> xTmpPropSet( xValue
, UNO_QUERY
);
996 if( xTmpPropSet
.is() )
998 mxImportInfo
= xTmpPropSet
;
999 uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo
= mxImportInfo
->getPropertySetInfo();
1000 if (xPropertySetInfo
.is())
1002 OUString
sPropName(XML_NUMBERSTYLES
);
1003 if (xPropertySetInfo
->hasPropertyByName(sPropName
))
1005 uno::Any aAny
= mxImportInfo
->getPropertyValue(sPropName
);
1006 aAny
>>= mxNumberStyles
;
1009 sPropName
= "PrivateData";
1010 if (xPropertySetInfo
->hasPropertyByName(sPropName
))
1012 Reference
< XInterface
> xIfc
;
1013 uno::Any aAny
= mxImportInfo
->getPropertyValue(sPropName
);
1016 StyleMap
*pSMap
= StyleMap::getImplementation( xIfc
);
1020 mpStyleMap
->acquire();
1024 sPropName
= "BaseURI";
1025 if (xPropertySetInfo
->hasPropertyByName(sPropName
))
1027 uno::Any aAny
= mxImportInfo
->getPropertyValue(sPropName
);
1029 mpImpl
->aBaseURL
.SetURL( sBaseURI
);
1030 mpImpl
->aDocBase
.SetURL( sBaseURI
);
1033 sPropName
= "StreamRelPath";
1034 if( xPropertySetInfo
->hasPropertyByName(sPropName
) )
1036 uno::Any aAny
= mxImportInfo
->getPropertyValue(sPropName
);
1040 sPropName
= "StreamName";
1041 if( xPropertySetInfo
->hasPropertyByName(sPropName
) )
1043 uno::Any aAny
= mxImportInfo
->getPropertyValue(sPropName
);
1046 if( !sBaseURI
.isEmpty() && !sName
.isEmpty() )
1048 if( !sRelPath
.isEmpty() )
1049 mpImpl
->aBaseURL
.insertName( sRelPath
);
1050 mpImpl
->aBaseURL
.insertName( sName
);
1052 mpImpl
->mStreamName
= sName
; // Note: may be empty (XSLT)
1053 // Retrieve property <ShapePositionInHoriL2R> (#i28749#)
1054 sPropName
= "ShapePositionInHoriL2R";
1055 if( xPropertySetInfo
->hasPropertyByName(sPropName
) )
1057 uno::Any aAny
= mxImportInfo
->getPropertyValue(sPropName
);
1058 aAny
>>= (mpImpl
->mbShapePositionInHoriL2R
);
1060 sPropName
= "TextDocInOOoFileFormat";
1061 if( xPropertySetInfo
->hasPropertyByName(sPropName
) )
1063 uno::Any aAny
= mxImportInfo
->getPropertyValue(sPropName
);
1064 aAny
>>= (mpImpl
->mbTextDocInOOoFileFormat
);
1067 sPropName
= "SourceStorage";
1068 if( xPropertySetInfo
->hasPropertyByName(sPropName
) )
1069 mxImportInfo
->getPropertyValue(sPropName
) >>= mpImpl
->mxSourceStorage
;
1076 OUString SAL_CALL
SvXMLImport::getImplementationName()
1077 throw(uno::RuntimeException
, std::exception
)
1079 return mpImpl
->implementationName
;
1082 sal_Bool SAL_CALL
SvXMLImport::supportsService( const OUString
& rServiceName
)
1083 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
1085 return cppu::supportsService(this, rServiceName
);
1088 uno::Sequence
< OUString
> SAL_CALL
SvXMLImport::getSupportedServiceNames( )
1089 throw(uno::RuntimeException
, std::exception
)
1091 uno::Sequence
<OUString
> aSeq(2);
1092 aSeq
[0] = "com.sun.star.document.ImportFilter";
1093 aSeq
[1] = "com.sun.star.xml.XMLImportFilter";
1097 XMLTextImportHelper
* SvXMLImport::CreateTextImport()
1099 return new XMLTextImportHelper( mxModel
, *this );
1102 XMLShapeImportHelper
* SvXMLImport::CreateShapeImport()
1104 return new XMLShapeImportHelper( *this, mxModel
);
1107 SchXMLImportHelper
* SvXMLImport::CreateChartImport()
1109 return new SchXMLImportHelper();
1112 ::xmloff::OFormLayerXMLImport
* SvXMLImport::CreateFormImport()
1114 return new ::xmloff::OFormLayerXMLImport(*this);
1118 // Get or create fill/line/lineend-style-helper
1121 const Reference
< container::XNameContainer
> & SvXMLImport::GetGradientHelper()
1123 if( !mxGradientHelper
.is() )
1127 Reference
< lang::XMultiServiceFactory
> xServiceFact( mxModel
, UNO_QUERY
);
1128 if( xServiceFact
.is() )
1132 mxGradientHelper
= Reference
< container::XNameContainer
>( xServiceFact
->createInstance(
1133 "com.sun.star.drawing.GradientTable" ), UNO_QUERY
);
1135 catch( lang::ServiceNotRegisteredException
& )
1141 return mxGradientHelper
;
1144 const Reference
< container::XNameContainer
> & SvXMLImport::GetHatchHelper()
1146 if( !mxHatchHelper
.is() )
1150 Reference
< lang::XMultiServiceFactory
> xServiceFact( mxModel
, UNO_QUERY
);
1151 if( xServiceFact
.is() )
1155 mxHatchHelper
= Reference
< container::XNameContainer
>( xServiceFact
->createInstance(
1156 "com.sun.star.drawing.HatchTable" ), UNO_QUERY
);
1158 catch( lang::ServiceNotRegisteredException
& )
1164 return mxHatchHelper
;
1167 const Reference
< container::XNameContainer
> & SvXMLImport::GetBitmapHelper()
1169 if( !mxBitmapHelper
.is() )
1173 Reference
< lang::XMultiServiceFactory
> xServiceFact( mxModel
, UNO_QUERY
);
1174 if( xServiceFact
.is() )
1178 mxBitmapHelper
= Reference
< container::XNameContainer
>( xServiceFact
->createInstance(
1179 "com.sun.star.drawing.BitmapTable" ), UNO_QUERY
);
1181 catch( lang::ServiceNotRegisteredException
& )
1187 return mxBitmapHelper
;
1190 const Reference
< container::XNameContainer
> & SvXMLImport::GetTransGradientHelper()
1192 if( !mxTransGradientHelper
.is() )
1196 Reference
< lang::XMultiServiceFactory
> xServiceFact( mxModel
, UNO_QUERY
);
1197 if( xServiceFact
.is() )
1201 mxTransGradientHelper
= Reference
< container::XNameContainer
>( xServiceFact
->createInstance(
1202 "com.sun.star.drawing.TransparencyGradientTable" ), UNO_QUERY
);
1204 catch( lang::ServiceNotRegisteredException
& )
1210 return mxTransGradientHelper
;
1213 const Reference
< container::XNameContainer
> & SvXMLImport::GetMarkerHelper()
1215 if( !mxMarkerHelper
.is() )
1219 Reference
< lang::XMultiServiceFactory
> xServiceFact( mxModel
, UNO_QUERY
);
1220 if( xServiceFact
.is() )
1224 mxMarkerHelper
= Reference
< container::XNameContainer
>( xServiceFact
->createInstance(
1225 "com.sun.star.drawing.MarkerTable" ), UNO_QUERY
);
1227 catch( lang::ServiceNotRegisteredException
& )
1233 return mxMarkerHelper
;
1236 const Reference
< container::XNameContainer
> & SvXMLImport::GetDashHelper()
1238 if( !mxDashHelper
.is() )
1242 Reference
< lang::XMultiServiceFactory
> xServiceFact( mxModel
, UNO_QUERY
);
1243 if( xServiceFact
.is() )
1247 mxDashHelper
= Reference
< container::XNameContainer
>( xServiceFact
->createInstance(
1248 "com.sun.star.drawing.DashTable" ), UNO_QUERY
);
1250 catch( lang::ServiceNotRegisteredException
& )
1256 return mxDashHelper
;
1259 bool SvXMLImport::IsPackageURL( const OUString
& rURL
) const
1262 // if, and only if, only parts are imported, then we're in a package
1263 const SvXMLImportFlags nTest
= SvXMLImportFlags::META
|SvXMLImportFlags::STYLES
|SvXMLImportFlags::CONTENT
|SvXMLImportFlags::SETTINGS
;
1264 if( (mnImportFlags
& nTest
) == nTest
)
1267 // Some quick tests: Some may rely on the package structure!
1268 sal_Int32 nLen
= rURL
.getLength();
1269 if( (nLen
> 0 && '/' == rURL
[0]) )
1270 // RFC2396 net_path or abs_path
1272 else if( nLen
> 1 && '.' == rURL
[0] )
1274 if( '.' == rURL
[1] )
1275 // ../: We are never going up one level, so we know
1276 // it's not an external URI
1278 else if( '/' == rURL
[1] )
1279 // we are remaining on a level, so it's an package URI
1283 // Now check for a RFC2396 schema
1285 while( nPos
< nLen
)
1287 switch( rURL
[nPos
] )
1290 // a relative path segement
1297 // we don't care about any other characters
1305 OUString
SvXMLImport::ResolveGraphicObjectURL( const OUString
& rURL
,
1306 bool bLoadOnDemand
)
1310 if( IsPackageURL( rURL
) )
1312 if( !bLoadOnDemand
&& mxGraphicResolver
.is() )
1314 OUString
aTmp( msPackageProtocol
);
1316 sRet
= mxGraphicResolver
->resolveGraphicObjectURL( aTmp
);
1319 if( sRet
.isEmpty() )
1321 sRet
= msPackageProtocol
;
1326 if( sRet
.isEmpty() )
1327 sRet
= GetAbsoluteReference( rURL
);
1332 Reference
< XOutputStream
> SvXMLImport::GetStreamForGraphicObjectURLFromBase64()
1334 Reference
< XOutputStream
> xOStm
;
1335 Reference
< document::XBinaryStreamResolver
> xStmResolver( mxGraphicResolver
, UNO_QUERY
);
1337 if( xStmResolver
.is() )
1338 xOStm
= xStmResolver
->createOutputStream();
1343 OUString
SvXMLImport::ResolveGraphicObjectURLFromBase64(
1344 const Reference
< XOutputStream
>& rOut
)
1347 Reference
< document::XBinaryStreamResolver
> xStmResolver( mxGraphicResolver
, UNO_QUERY
);
1348 if( xStmResolver
.is() )
1349 sURL
= xStmResolver
->resolveOutputStream( rOut
);
1354 OUString
SvXMLImport::ResolveEmbeddedObjectURL(
1355 const OUString
& rURL
,
1356 const OUString
& rClassId
)
1360 if( IsPackageURL( rURL
) )
1362 if ( mxEmbeddedResolver
.is() )
1364 OUString
sURL( rURL
);
1365 if( !rClassId
.isEmpty() )
1367 sURL
+= "!" + rClassId
;
1369 sRet
= mxEmbeddedResolver
->resolveEmbeddedObjectURL( sURL
);
1373 sRet
= GetAbsoluteReference( rURL
);
1378 Reference
< embed::XStorage
> SvXMLImport::GetSourceStorage()
1380 return mpImpl
->mxSourceStorage
;
1383 Reference
< XOutputStream
>
1384 SvXMLImport::GetStreamForEmbeddedObjectURLFromBase64()
1386 Reference
< XOutputStream
> xOLEStream
;
1388 if( mxEmbeddedResolver
.is() )
1390 Reference
< XNameAccess
> xNA( mxEmbeddedResolver
, UNO_QUERY
);
1393 OUString
aURL( "Obj12345678" );
1394 Any aAny
= xNA
->getByName( aURL
);
1395 aAny
>>= xOLEStream
;
1402 OUString
SvXMLImport::ResolveEmbeddedObjectURLFromBase64()
1406 if( mxEmbeddedResolver
.is() )
1408 OUString
aURL( "Obj12345678" );
1409 sRet
= mxEmbeddedResolver
->resolveEmbeddedObjectURL( aURL
);
1415 void SvXMLImport::AddStyleDisplayName( sal_uInt16 nFamily
,
1416 const OUString
& rName
,
1417 const OUString
& rDisplayName
)
1421 mpStyleMap
= new StyleMap
;
1422 mpStyleMap
->acquire();
1423 if( mxImportInfo
.is() )
1425 OUString
sPrivateData( "PrivateData" );
1426 Reference
< beans::XPropertySetInfo
> xPropertySetInfo
=
1427 mxImportInfo
->getPropertySetInfo();
1428 if( xPropertySetInfo
.is() &&
1429 xPropertySetInfo
->hasPropertyByName(sPrivateData
) )
1431 Reference
< XInterface
> xIfc(
1432 static_cast< XUnoTunnel
*>( mpStyleMap
) );
1435 mxImportInfo
->setPropertyValue( sPrivateData
, aAny
);
1440 StyleMap::key_type
aKey( nFamily
, rName
);
1441 StyleMap::value_type
aValue( aKey
, rDisplayName
);
1442 ::std::pair
<StyleMap::iterator
,bool> aRes( mpStyleMap
->insert( aValue
) );
1443 SAL_WARN_IF( !aRes
.second
,
1445 "duplicate style name of family " << nFamily
<< ": \"" << rName
<< "\"");
1449 OUString
SvXMLImport::GetStyleDisplayName( sal_uInt16 nFamily
,
1450 const OUString
& rName
) const
1452 OUString
sName( rName
);
1453 if( mpStyleMap
&& !rName
.isEmpty() )
1455 StyleMap::key_type
aKey( nFamily
, rName
);
1456 StyleMap::const_iterator aIter
= mpStyleMap
->find( aKey
);
1457 if( aIter
!= mpStyleMap
->end() )
1458 sName
= (*aIter
).second
;
1463 void SvXMLImport::SetViewSettings(const com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
>&)
1467 void SvXMLImport::SetConfigurationSettings(const com::sun::star::uno::Sequence
<com::sun::star::beans::PropertyValue
>&)
1471 void SvXMLImport::SetDocumentSpecificSettings(const OUString
& _rSettingsGroupName
, const uno::Sequence
<beans::PropertyValue
>& _rSettings
)
1473 (void)_rSettingsGroupName
;
1477 ProgressBarHelper
* SvXMLImport::GetProgressBarHelper()
1479 if (!mpProgressBarHelper
)
1481 mpProgressBarHelper
= new ProgressBarHelper(mxStatusIndicator
, false);
1483 if (mxImportInfo
.is())
1485 uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo
= mxImportInfo
->getPropertySetInfo();
1486 if (xPropertySetInfo
.is())
1488 OUString
sProgressRange(XML_PROGRESSRANGE
);
1489 OUString
sProgressMax(XML_PROGRESSMAX
);
1490 OUString
sProgressCurrent(XML_PROGRESSCURRENT
);
1491 OUString
sRepeat(XML_PROGRESSREPEAT
);
1492 if (xPropertySetInfo
->hasPropertyByName(sProgressMax
) &&
1493 xPropertySetInfo
->hasPropertyByName(sProgressCurrent
) &&
1494 xPropertySetInfo
->hasPropertyByName(sProgressRange
))
1497 sal_Int32
nProgressMax(0);
1498 sal_Int32
nProgressCurrent(0);
1499 sal_Int32
nProgressRange(0);
1500 aAny
= mxImportInfo
->getPropertyValue(sProgressRange
);
1501 if (aAny
>>= nProgressRange
)
1502 mpProgressBarHelper
->SetRange(nProgressRange
);
1503 aAny
= mxImportInfo
->getPropertyValue(sProgressMax
);
1504 if (aAny
>>= nProgressMax
)
1505 mpProgressBarHelper
->SetReference(nProgressMax
);
1506 aAny
= mxImportInfo
->getPropertyValue(sProgressCurrent
);
1507 if (aAny
>>= nProgressCurrent
)
1508 mpProgressBarHelper
->SetValue(nProgressCurrent
);
1510 if (xPropertySetInfo
->hasPropertyByName(sRepeat
))
1512 uno::Any aAny
= mxImportInfo
->getPropertyValue(sRepeat
);
1513 if (aAny
.getValueType() == cppu::UnoType
<bool>::get())
1514 mpProgressBarHelper
->SetRepeat(::cppu::any2bool(aAny
));
1516 SAL_WARN( "xmloff.core", "why is it no boolean?" );
1522 return mpProgressBarHelper
;
1525 void SvXMLImport::AddNumberStyle(sal_Int32 nKey
, const OUString
& rName
)
1527 if (!mxNumberStyles
.is())
1528 mxNumberStyles
= uno::Reference
< container::XNameContainer
>( comphelper::NameContainer_createInstance( ::cppu::UnoType
<sal_Int32
>::get()) );
1529 if (mxNumberStyles
.is())
1535 mxNumberStyles
->insertByName(rName
, aAny
);
1537 catch ( uno::Exception
& )
1539 SAL_WARN( "xmloff.core", "Numberformat could not be inserted");
1540 DBG_UNHANDLED_EXCEPTION();
1544 SAL_WARN( "xmloff.core", "not possible to create NameContainer");
1545 DBG_UNHANDLED_EXCEPTION();
1549 XMLEventImportHelper
& SvXMLImport::GetEventImport()
1551 if (!mpEventImportHelper
)
1553 // construct event helper and register StarBasic handler and standard
1555 mpEventImportHelper
= new XMLEventImportHelper();
1556 OUString
sStarBasic(GetXMLToken(XML_STARBASIC
));
1557 mpEventImportHelper
->RegisterFactory(sStarBasic
,
1558 new XMLStarBasicContextFactory());
1559 OUString
sScript(GetXMLToken(XML_SCRIPT
));
1560 mpEventImportHelper
->RegisterFactory(sScript
,
1561 new XMLScriptContextFactory());
1562 mpEventImportHelper
->AddTranslationTable(aStandardEventTable
);
1564 // register StarBasic event handler with capitalized spelling
1565 OUString
sStarBasicCap( "StarBasic" );
1566 mpEventImportHelper
->RegisterFactory(sStarBasicCap
,
1567 new XMLStarBasicContextFactory());
1570 return *mpEventImportHelper
;
1573 void SvXMLImport::SetFontDecls( XMLFontStylesContext
*pFontDecls
)
1575 mxFontDecls
= pFontDecls
;
1578 void SvXMLImport::SetStyles( SvXMLStylesContext
*pStyles
)
1583 void SvXMLImport::SetAutoStyles( SvXMLStylesContext
*pAutoStyles
)
1585 if (pAutoStyles
&& mxNumberStyles
.is() && (mnImportFlags
& SvXMLImportFlags::CONTENT
) )
1587 uno::Reference
<xml::sax::XAttributeList
> xAttrList
;
1588 uno::Sequence
< OUString
> aNames
= mxNumberStyles
->getElementNames();
1589 sal_uInt32
nCount(aNames
.getLength());
1592 const OUString
* pNames
= aNames
.getConstArray();
1595 SvXMLStyleContext
* pContext
;
1598 for (sal_uInt32 i
= 0; i
< nCount
; i
++, pNames
++)
1600 aAny
= mxNumberStyles
->getByName(*pNames
);
1603 pContext
= new SvXMLNumFormatContext( *this, XML_NAMESPACE_NUMBER
,
1604 *pNames
, xAttrList
, nKey
, *pAutoStyles
);
1605 pAutoStyles
->AddStyle(*pContext
);
1611 mxAutoStyles
= pAutoStyles
;
1612 GetTextImport()->SetAutoStyles( pAutoStyles
);
1613 GetShapeImport()->SetAutoStylesContext( pAutoStyles
);
1614 GetChartImport()->SetAutoStylesContext( pAutoStyles
);
1615 GetFormImport()->setAutoStyleContext( pAutoStyles
);
1618 void SvXMLImport::SetMasterStyles( SvXMLStylesContext
*pMasterStyles
)
1620 mxMasterStyles
= pMasterStyles
;
1623 XMLFontStylesContext
*SvXMLImport::GetFontDecls()
1625 return static_cast<XMLFontStylesContext
*>(&mxFontDecls
);
1628 SvXMLStylesContext
*SvXMLImport::GetStyles()
1630 return static_cast<SvXMLStylesContext
*>(&mxStyles
);
1633 SvXMLStylesContext
*SvXMLImport::GetAutoStyles()
1635 return static_cast<SvXMLStylesContext
*>(&mxAutoStyles
);
1638 const XMLFontStylesContext
*SvXMLImport::GetFontDecls() const
1640 return static_cast<const XMLFontStylesContext
*>(&mxFontDecls
);
1643 const SvXMLStylesContext
*SvXMLImport::GetStyles() const
1645 return static_cast<const SvXMLStylesContext
*>(&mxStyles
);
1648 const SvXMLStylesContext
*SvXMLImport::GetAutoStyles() const
1650 return static_cast<const SvXMLStylesContext
*>(&mxAutoStyles
);
1653 OUString
SvXMLImport::GetAbsoluteReference(const OUString
& rValue
) const
1655 if( rValue
.isEmpty() || rValue
[0] == '#' )
1658 INetURLObject aAbsURL
;
1659 if( mpImpl
->aBaseURL
.GetNewAbsURL( rValue
, &aAbsURL
) )
1660 return aAbsURL
.GetMainURL( INetURLObject::DECODE_TO_IURI
);
1665 bool SvXMLImport::IsODFVersionConsistent( const OUString
& aODFVersion
)
1667 // the check returns sal_False only if the storage version could be retrieved
1668 bool bResult
= true;
1670 if ( !aODFVersion
.isEmpty() && aODFVersion
.compareTo( ODFVER_012_TEXT
) >= 0 )
1672 // check the consistency only for the ODF1.2 and later ( according to content.xml )
1673 // manifest.xml might have no version, it should be checked here and the correct version should be set
1676 uno::Reference
< document::XStorageBasedDocument
> xDoc( mxModel
, uno::UNO_QUERY_THROW
);
1677 uno::Reference
< embed::XStorage
> xStor
= xDoc
->getDocumentStorage();
1678 uno::Reference
< beans::XPropertySet
> xStorProps( xStor
, uno::UNO_QUERY_THROW
);
1680 // the check should be done only for OASIS format
1683 bool bRepairPackage
= false;
1686 xStorProps
->getPropertyValue( "RepairPackage" )
1688 } catch ( uno::Exception
& )
1691 // check only if not in Repair mode
1692 if ( !bRepairPackage
)
1694 OUString aStorVersion
;
1695 xStorProps
->getPropertyValue( "Version" )
1698 // if the storage version is set in manifest.xml, it must be the same as in content.xml
1699 // if not, set it explicitly to be used further ( it will work even for readonly storage )
1700 // This workaround is not nice, but I see no other way to handle it, since there are
1701 // ODF1.2 documents without version in manifest.xml
1702 if ( !aStorVersion
.isEmpty() )
1703 bResult
= aODFVersion
.equals( aStorVersion
);
1705 xStorProps
->setPropertyValue( "Version",
1706 uno::makeAny( aODFVersion
) );
1710 bool bInconsistent
= false;
1711 xStorProps
->getPropertyValue( "IsInconsistent" )
1713 bResult
= !bInconsistent
;
1718 catch( uno::Exception
& )
1725 void SvXMLImport::_CreateNumberFormatsSupplier()
1727 SAL_WARN_IF( mxNumberFormatsSupplier
.is(), "xmloff.core", "number formats supplier already exists!" );
1729 mxNumberFormatsSupplier
=
1730 uno::Reference
< util::XNumberFormatsSupplier
> (mxModel
, uno::UNO_QUERY
);
1733 void SvXMLImport::_CreateDataStylesImport()
1735 SAL_WARN_IF( mpNumImport
!= NULL
, "xmloff.core", "data styles import already exists!" );
1736 uno::Reference
<util::XNumberFormatsSupplier
> xNum
=
1737 GetNumberFormatsSupplier();
1739 mpNumImport
= new SvXMLNumFmtHelper(xNum
, GetComponentContext() );
1742 sal_Unicode
SvXMLImport::ConvStarBatsCharToStarSymbol( sal_Unicode c
)
1744 sal_Unicode cNew
= c
;
1745 if( !mpImpl
->hBatsFontConv
)
1747 OUString
sStarBats( "StarBats" );
1748 mpImpl
->hBatsFontConv
= CreateFontToSubsFontConverter( sStarBats
,
1749 FontToSubsFontFlags::IMPORT
|FontToSubsFontFlags::ONLYOLDSOSYMBOLFONTS
);
1750 SAL_WARN_IF( !mpImpl
->hBatsFontConv
, "xmloff.core", "Got no symbol font converter" );
1752 if( mpImpl
->hBatsFontConv
)
1754 cNew
= ConvertFontToSubsFontChar( mpImpl
->hBatsFontConv
, c
);
1760 sal_Unicode
SvXMLImport::ConvStarMathCharToStarSymbol( sal_Unicode c
)
1762 sal_Unicode cNew
= c
;
1763 if( !mpImpl
->hMathFontConv
)
1765 OUString
sStarMath( "StarMath" );
1766 mpImpl
->hMathFontConv
= CreateFontToSubsFontConverter( sStarMath
,
1767 FontToSubsFontFlags::IMPORT
|FontToSubsFontFlags::ONLYOLDSOSYMBOLFONTS
);
1768 SAL_WARN_IF( !mpImpl
->hMathFontConv
, "xmloff.core", "Got no symbol font converter" );
1770 if( mpImpl
->hMathFontConv
)
1772 cNew
= ConvertFontToSubsFontChar( mpImpl
->hMathFontConv
, c
);
1778 void SvXMLImport::SetError(
1780 const Sequence
<OUString
>& rMsgParams
,
1781 const OUString
& rExceptionMessage
,
1782 const Reference
<xml::sax::XLocator
>& rLocator
)
1784 // maintain error flags
1785 if ( ( nId
& XMLERROR_FLAG_ERROR
) != 0 )
1786 mnErrorFlags
|= SvXMLErrorFlags::ERROR_OCCURRED
;
1787 if ( ( nId
& XMLERROR_FLAG_WARNING
) != 0 )
1788 mnErrorFlags
|= SvXMLErrorFlags::WARNING_OCCURRED
;
1789 if ( ( nId
& XMLERROR_FLAG_SEVERE
) != 0 )
1790 mnErrorFlags
|= SvXMLErrorFlags::DO_NOTHING
;
1792 // create error list on demand
1793 if ( mpXMLErrors
== NULL
)
1794 mpXMLErrors
= new XMLErrors();
1796 // save error information
1797 // use document locator (if none supplied)
1798 mpXMLErrors
->AddRecord( nId
, rMsgParams
, rExceptionMessage
,
1799 rLocator
.is() ? rLocator
: mxLocator
);
1802 void SvXMLImport::SetError(
1804 const Sequence
<OUString
>& rMsgParams
)
1807 SetError( nId
, rMsgParams
, sEmpty
, NULL
);
1810 void SvXMLImport::SetError(
1813 Sequence
<OUString
> aSeq(0);
1814 SetError( nId
, aSeq
);
1817 void SvXMLImport::SetError(
1819 const OUString
& rMsg1
)
1821 Sequence
<OUString
> aSeq(1);
1822 OUString
* pSeq
= aSeq
.getArray();
1824 SetError( nId
, aSeq
);
1827 void SvXMLImport::SetError(
1829 const OUString
& rMsg1
,
1830 const OUString
& rMsg2
)
1832 Sequence
<OUString
> aSeq(2);
1833 OUString
* pSeq
= aSeq
.getArray();
1836 SetError( nId
, aSeq
);
1839 void SvXMLImport::DisposingModel()
1841 if( mxFontDecls
.Is() )
1842 static_cast<SvXMLStylesContext
*>(&mxFontDecls
)->Clear();
1844 static_cast<SvXMLStylesContext
*>(&mxStyles
)->Clear();
1845 if( mxAutoStyles
.Is() )
1846 static_cast<SvXMLStylesContext
*>(&mxAutoStyles
)->Clear();
1847 if( mxMasterStyles
.Is() )
1848 static_cast<SvXMLStylesContext
*>(&mxMasterStyles
)->Clear();
1851 mxEventListener
.set(NULL
);
1854 ::comphelper::UnoInterfaceToUniqueIdentifierMapper
& SvXMLImport::getInterfaceToIdentifierMapper()
1856 return mpImpl
->maInterfaceToIdentifierMapper
;
1859 uno::Reference
< uno::XComponentContext
>
1860 SvXMLImport::GetComponentContext() const
1862 return mpImpl
->mxComponentContext
;
1865 OUString
SvXMLImport::GetBaseURL() const
1867 return mpImpl
->aBaseURL
.GetMainURL( INetURLObject::NO_DECODE
);
1870 OUString
SvXMLImport::GetDocumentBase() const
1872 return mpImpl
->aDocBase
.GetMainURL( INetURLObject::NO_DECODE
);
1875 OUString
SvXMLImport::GetStreamName() const
1877 return mpImpl
->mStreamName
;
1880 // Convert drawing object positions from OOo file format to OASIS (#i28749#)
1881 bool SvXMLImport::IsShapePositionInHoriL2R() const
1883 return mpImpl
->mbShapePositionInHoriL2R
;
1886 bool SvXMLImport::IsTextDocInOOoFileFormat() const
1888 return mpImpl
->mbTextDocInOOoFileFormat
;
1891 void SvXMLImport::initXForms()
1893 // dummy method; to be implemented by derived classes supporting XForms
1896 bool SvXMLImport::getBuildIds( sal_Int32
& rUPD
, sal_Int32
& rBuild
) const
1899 OUString
const aBuildId(getBuildIdsProperty(mxImportInfo
));
1900 if (!aBuildId
.isEmpty())
1902 sal_Int32 nIndex
= aBuildId
.indexOf('$');
1905 rUPD
= aBuildId
.copy( 0, nIndex
).toInt32();
1906 sal_Int32 nIndexEnd
= aBuildId
.indexOf(';', nIndex
);
1907 rBuild
= (nIndexEnd
== -1)
1908 ? aBuildId
.copy(nIndex
+ 1).toInt32()
1909 : aBuildId
.copy(nIndex
+ 1, nIndexEnd
- nIndex
- 1).toInt32();
1916 sal_uInt16
SvXMLImport::getGeneratorVersion() const
1919 return mpImpl
->getGeneratorVersion( *this );
1923 bool SvXMLImport::isGeneratorVersionOlderThan(
1924 sal_uInt16
const nOOoVersion
, sal_uInt16
const nLOVersion
)
1926 assert( (nLOVersion
& LO_flag
));
1927 assert(!(nOOoVersion
& LO_flag
));
1928 const sal_uInt16
nGeneratorVersion(getGeneratorVersion());
1929 return (nGeneratorVersion
& LO_flag
)
1930 ? nGeneratorVersion
< nLOVersion
1931 : nGeneratorVersion
< nOOoVersion
;
1935 OUString
SvXMLImport::GetODFVersion() const
1937 return mpImpl
->aODFVersion
;
1940 bool SvXMLImport::IsOOoXML() const
1942 return mpImpl
->mbIsOOoXML
;
1945 // xml:id for RDF metadata
1946 void SvXMLImport::SetXmlId(uno::Reference
<uno::XInterface
> const & i_xIfc
,
1947 OUString
const & i_rXmlId
)
1949 if (!i_rXmlId
.isEmpty()) {
1951 const uno::Reference
<rdf::XMetadatable
> xMeta(i_xIfc
,
1955 const beans::StringPair
mdref( GetStreamName(), i_rXmlId
);
1957 xMeta
->setMetadataReference(mdref
);
1958 } catch (lang::IllegalArgumentException
&) {
1959 // probably duplicate; ignore
1960 SAL_INFO("xmloff.core", "SvXMLImport::SetXmlId: cannot set xml:id");
1963 } catch (uno::Exception
&) {
1964 SAL_WARN("xmloff.core","SvXMLImport::SetXmlId: exception?");
1969 ::xmloff::RDFaImportHelper
&
1970 SvXMLImport::GetRDFaImportHelper()
1972 if (!mpImpl
->mpRDFaHelper
.get())
1974 mpImpl
->mpRDFaHelper
.reset( new ::xmloff::RDFaImportHelper(*this) );
1976 return *mpImpl
->mpRDFaHelper
;
1980 SvXMLImport::AddRDFa(uno::Reference
<rdf::XMetadatable
> i_xObject
,
1981 OUString
const & i_rAbout
,
1982 OUString
const & i_rProperty
,
1983 OUString
const & i_rContent
,
1984 OUString
const & i_rDatatype
)
1986 // N.B.: we only get called if i_xObject had xhtml:about attribute
1987 // (an empty attribute value is valid)
1988 ::xmloff::RDFaImportHelper
& rRDFaHelper( GetRDFaImportHelper() );
1989 rRDFaHelper
.ParseAndAddRDFa(i_xObject
,
1990 i_rAbout
, i_rProperty
, i_rContent
, i_rDatatype
);
1993 bool SvXMLImport::embeddedFontAlreadyProcessed( const OUString
& url
)
1995 if( embeddedFontUrlsKnown
.count( url
) != 0 )
1997 embeddedFontUrlsKnown
.insert( url
);
2001 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */