Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <string.h>
21 :
22 : #include <tools/diagnose_ex.h>
23 : #include <com/sun/star/beans/XPropertySetInfo.hpp>
24 : #include <tools/debug.hxx>
25 : #include <tools/urlobj.hxx>
26 : #include <osl/mutex.hxx>
27 : #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
28 : #include <xmloff/nmspmap.hxx>
29 : #include <xmloff/xmluconv.hxx>
30 : #include <xmloff/xmlnmspe.hxx>
31 : #include <xmloff/xmltoken.hxx>
32 : #include <xmloff/XMLFontStylesContext.hxx>
33 : #include <xmloff/xmlictxt.hxx>
34 : #include <xmloff/xmlimp.hxx>
35 : #include <xmloff/xmlnumfi.hxx>
36 : #include "XMLEventImportHelper.hxx"
37 : #include "XMLStarBasicContextFactory.hxx"
38 : #include "XMLScriptContextFactory.hxx"
39 : #include "StyleMap.hxx"
40 : #include <xmloff/ProgressBarHelper.hxx>
41 : #include <xmloff/xmlerror.hxx>
42 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 : #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
44 : #include <com/sun/star/io/XOutputStream.hpp>
45 : #include <com/sun/star/util/MeasureUnit.hpp>
46 : #include <com/sun/star/document/XBinaryStreamResolver.hpp>
47 : #include <com/sun/star/document/XStorageBasedDocument.hpp>
48 : #include <com/sun/star/xml/sax/XLocator.hpp>
49 : #include <com/sun/star/packages/zip/ZipIOException.hpp>
50 : #include <comphelper/namecontainer.hxx>
51 : #include <comphelper/servicehelper.hxx>
52 : #include <cppuhelper/implbase1.hxx>
53 : #include <cppuhelper/supportsservice.hxx>
54 : #include <comphelper/extract.hxx>
55 : #include <comphelper/processfactory.hxx>
56 : #include <comphelper/documentconstants.hxx>
57 : #include <comphelper/storagehelper.hxx>
58 : #include <unotools/fontcvt.hxx>
59 :
60 : #include <com/sun/star/rdf/XMetadatable.hpp>
61 : #include <com/sun/star/rdf/XRepositorySupplier.hpp>
62 : #include "RDFaImportHelper.hxx"
63 :
64 : using ::com::sun::star::beans::XPropertySetInfo;
65 :
66 : using namespace ::osl;
67 : using namespace ::com::sun::star;
68 : using namespace ::com::sun::star::frame;
69 : using namespace ::com::sun::star::uno;
70 : using namespace ::com::sun::star::util;
71 : using namespace ::com::sun::star::io;
72 : using namespace ::com::sun::star::container;
73 : using namespace ::com::sun::star::document;
74 : using namespace ::xmloff::token;
75 :
76 : sal_Char const sXML_np__office[] = "_office";
77 : sal_Char const sXML_np__office_ext[] = "_office_ooo";
78 : sal_Char const sXML_np__ooo[] = "_ooo";
79 : sal_Char const sXML_np__ooow[] = "_ooow";
80 : sal_Char const sXML_np__oooc[] = "_oooc";
81 : sal_Char const sXML_np__of[] = "_of";
82 : sal_Char const sXML_np__style[] = "_style";
83 : sal_Char const sXML_np__text[] = "_text";
84 : sal_Char const sXML_np__table[] = "_table";
85 : sal_Char const sXML_np__table_ext[] = "_table_ooo";
86 : sal_Char const sXML_np__draw[] = "_draw";
87 : sal_Char const sXML_np__draw_ext[] = "_draw_ooo";
88 : sal_Char const sXML_np__dr3d[] = "_dr3d";
89 : sal_Char const sXML_np__fo[] = "_fo";
90 : sal_Char const sXML_np__xlink[] = "_xlink";
91 : sal_Char const sXML_np__dc[] = "_dc";
92 : sal_Char const sXML_np__dom[] = "_dom";
93 : sal_Char const sXML_np__meta[] = "_meta";
94 : sal_Char const sXML_np__number[] = "_number";
95 : sal_Char const sXML_np__svg[] = "_svg";
96 : sal_Char const sXML_np__chart[] = "_chart";
97 : sal_Char const sXML_np__math[] = "_math";
98 : sal_Char const sXML_np__form[] = "_form";
99 : sal_Char const sXML_np__script[] = "_script";
100 : sal_Char const sXML_np__config[] = "_config";
101 : sal_Char const sXML_np__xforms[] = "_xforms";
102 : sal_Char const sXML_np__formx[] = "_formx";
103 : sal_Char const sXML_np__xsd[] = "_xsd";
104 : sal_Char const sXML_np__xsi[] = "_xsi";
105 : sal_Char const sXML_np__field[] = "_field";
106 : sal_Char const sXML_np__xhtml[] = "_xhtml";
107 : sal_Char const sXML_np__css3text[] = "_css3text";
108 :
109 : class SvXMLImportEventListener : public cppu::WeakImplHelper1<
110 : com::sun::star::lang::XEventListener >
111 : {
112 : private:
113 : SvXMLImport* pImport;
114 :
115 : public:
116 : SvXMLImportEventListener(SvXMLImport* pImport);
117 : virtual ~SvXMLImportEventListener();
118 :
119 : // XEventListener
120 : virtual void SAL_CALL disposing(const lang::EventObject& rEventObject) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
121 : };
122 :
123 1263 : SvXMLImportEventListener::SvXMLImportEventListener(SvXMLImport* pTempImport)
124 1263 : : pImport(pTempImport)
125 : {
126 1263 : }
127 :
128 2526 : SvXMLImportEventListener::~SvXMLImportEventListener()
129 : {
130 2526 : }
131 :
132 : // XEventListener
133 8 : void SAL_CALL SvXMLImportEventListener::disposing( const lang::EventObject& )
134 : throw(uno::RuntimeException, std::exception)
135 : {
136 8 : if (pImport)
137 : {
138 8 : pImport->DisposingModel();
139 8 : pImport = NULL;
140 : }
141 8 : }
142 :
143 : namespace
144 : {
145 :
146 : static OUString
147 1955 : getBuildIdsProperty(uno::Reference<beans::XPropertySet> const& xImportInfo)
148 : {
149 1955 : if (xImportInfo.is())
150 : {
151 : try
152 : {
153 : Reference< XPropertySetInfo > const xSetInfo(
154 1888 : xImportInfo->getPropertySetInfo());
155 1888 : if (xSetInfo.is() && xSetInfo->hasPropertyByName("BuildId"))
156 : {
157 1888 : OUString aBuildId;
158 1888 : xImportInfo->getPropertyValue("BuildId") >>= aBuildId;
159 1888 : return aBuildId;
160 0 : }
161 : }
162 0 : catch (Exception const&)
163 : {
164 : SAL_WARN("xmloff.core", "exception getting BuildId");
165 : DBG_UNHANDLED_EXCEPTION();
166 : }
167 : }
168 67 : return OUString();
169 : }
170 :
171 : class DocumentInfo
172 : {
173 : private:
174 : sal_uInt16 mnGeneratorVersion;
175 :
176 : public:
177 183 : DocumentInfo( const SvXMLImport& rImport )
178 183 : : mnGeneratorVersion( SvXMLImport::ProductVersionUnknown )
179 : {
180 : OUString const buildIds(
181 183 : getBuildIdsProperty(rImport.getImportInfo()));
182 183 : if (!buildIds.isEmpty())
183 : {
184 98 : sal_Int32 const ix = buildIds.indexOf(';');
185 98 : if (-1 != ix)
186 : {
187 80 : OUString const loVersion(buildIds.copy(ix + 1));
188 80 : if (!loVersion.isEmpty())
189 : {
190 80 : if ('3' == loVersion[0])
191 : {
192 25 : mnGeneratorVersion = SvXMLImport::LO_3x;
193 : }
194 : else
195 : {
196 : SAL_INFO_IF('4' != loVersion[0], "xmloff.core", "unknown LO version: " << loVersion);
197 165 : if ('4' == loVersion[0] && loVersion.getLength() > 1
198 110 : && (loVersion[1] == '0' || loVersion[1] == '1'))
199 : {
200 34 : mnGeneratorVersion = SvXMLImport::LO_41x; // 4.0/4.1
201 : }
202 42 : else if ('4' == loVersion[0]
203 21 : && loVersion.getLength() > 1 && loVersion[1] == '2')
204 : {
205 21 : mnGeneratorVersion = SvXMLImport::LO_42x; // 4.2
206 : }
207 : else
208 : {
209 0 : mnGeneratorVersion = SvXMLImport::LO_4x;
210 : }
211 : }
212 263 : return; // ignore buildIds
213 0 : }
214 : }
215 : }
216 : sal_Int32 nUPD, nBuild;
217 103 : if ( rImport.getBuildIds( nUPD, nBuild ) )
218 : {
219 18 : if ( nUPD >= 640 && nUPD <= 645 )
220 : {
221 0 : mnGeneratorVersion = SvXMLImport::OOo_1x;
222 : }
223 18 : else if ( nUPD == 680 )
224 : {
225 0 : mnGeneratorVersion = SvXMLImport::OOo_2x;
226 : }
227 18 : else if ( nUPD == 300 && nBuild <= 9379 )
228 : {
229 1 : mnGeneratorVersion = SvXMLImport::OOo_30x;
230 : }
231 17 : else if ( nUPD == 310 )
232 : {
233 0 : mnGeneratorVersion = SvXMLImport::OOo_31x;
234 : }
235 17 : else if ( nUPD == 320 )
236 : {
237 6 : mnGeneratorVersion = SvXMLImport::OOo_32x;
238 : }
239 11 : else if ( nUPD == 330 )
240 : {
241 4 : mnGeneratorVersion = SvXMLImport::OOo_33x;
242 : }
243 7 : else if ( nUPD == 340 )
244 : {
245 0 : mnGeneratorVersion = SvXMLImport::OOo_34x;
246 : }
247 7 : else if (nUPD == 400)
248 : {
249 1 : mnGeneratorVersion = SvXMLImport::AOO_40x;
250 : }
251 6 : else if (nUPD >= 410)
252 : {
253 : // effectively this means "latest", see use
254 : // in XMLGraphicsDefaultStyle::SetDefaults()!
255 0 : mnGeneratorVersion = SvXMLImport::AOO_4x;
256 : }
257 103 : }
258 : }
259 :
260 183 : ~DocumentInfo()
261 183 : {}
262 :
263 530 : sal_uInt16 getGeneratorVersion() const
264 : {
265 530 : return mnGeneratorVersion;
266 : }
267 : };
268 : }
269 :
270 : class SvXMLImport_Impl
271 : {
272 : public:
273 : FontToSubsFontConverter hBatsFontConv;
274 : FontToSubsFontConverter hMathFontConv;
275 :
276 : bool mbOwnGraphicResolver;
277 : bool mbOwnEmbeddedResolver;
278 : INetURLObject aBaseURL;
279 : INetURLObject aDocBase;
280 :
281 : /// name of stream in package, e.g., "content.xml"
282 : OUString mStreamName;
283 :
284 : OUString aODFVersion;
285 :
286 : bool mbIsOOoXML;
287 :
288 : // Boolean, indicating that position attributes
289 : // of shapes are given in horizontal left-to-right layout. This is the case
290 : // for the OpenOffice.org file format. (#i28749#)
291 : bool mbShapePositionInHoriL2R;
292 : bool mbTextDocInOOoFileFormat;
293 :
294 : const uno::Reference< uno::XComponentContext > mxComponentContext;
295 : OUString implementationName;
296 :
297 : uno::Reference< embed::XStorage > mxSourceStorage;
298 :
299 : std::auto_ptr< xmloff::RDFaImportHelper > mpRDFaHelper;
300 :
301 : std::auto_ptr< DocumentInfo > mpDocumentInfo;
302 :
303 1593 : SvXMLImport_Impl( const uno::Reference< uno::XComponentContext >& rxContext,
304 : OUString const & theImplementationName)
305 : : hBatsFontConv( 0 )
306 : , hMathFontConv( 0 )
307 : , mbOwnGraphicResolver( false )
308 : , mbOwnEmbeddedResolver( false )
309 : , mbIsOOoXML(false)
310 : // Convert drawing object positions from OOo file format to OASIS (#i28749#)
311 : , mbShapePositionInHoriL2R( false )
312 : , mbTextDocInOOoFileFormat( false )
313 : , mxComponentContext( rxContext )
314 : , implementationName(theImplementationName)
315 : , mpRDFaHelper() // lazy
316 1593 : , mpDocumentInfo() // lazy
317 : {
318 : SAL_WARN_IF(!mxComponentContext.is(), "xmloff.core", "SvXMLImport: no ComponentContext");
319 1593 : if (!mxComponentContext.is()) throw uno::RuntimeException();
320 1593 : }
321 :
322 1593 : ~SvXMLImport_Impl()
323 1593 : {
324 1593 : if( hBatsFontConv )
325 0 : DestroyFontToSubsFontConverter( hBatsFontConv );
326 1593 : if( hMathFontConv )
327 0 : DestroyFontToSubsFontConverter( hMathFontConv );
328 1593 : }
329 :
330 530 : sal_uInt16 getGeneratorVersion( const SvXMLImport& rImport )
331 : {
332 530 : if ( !mpDocumentInfo.get() )
333 : {
334 183 : mpDocumentInfo.reset( new DocumentInfo( rImport ) );
335 : }
336 :
337 530 : return mpDocumentInfo->getGeneratorVersion();
338 : }
339 :
340 : ::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper;
341 : };
342 :
343 3186 : class SvXMLImportContexts_Impl : public std::vector<SvXMLImportContext *> {};
344 :
345 830 : SvXMLImportContext *SvXMLImport::CreateContext( sal_uInt16 nPrefix,
346 : const OUString& rLocalName,
347 : const uno::Reference< xml::sax::XAttributeList >& )
348 : {
349 830 : return new SvXMLImportContext( *this, nPrefix, rLocalName );
350 : }
351 :
352 1593 : void SvXMLImport::_InitCtor()
353 : {
354 1593 : if( mnImportFlags != 0 )
355 : {
356 : // implicit "xml" namespace prefix
357 1287 : mpNamespaceMap->Add( GetXMLToken(XML_XML), GetXMLToken(XML_N_XML), XML_NAMESPACE_XML );
358 1287 : mpNamespaceMap->Add( OUString( sXML_np__office ), GetXMLToken(XML_N_OFFICE), XML_NAMESPACE_OFFICE );
359 1287 : mpNamespaceMap->Add( OUString( sXML_np__office_ext ), GetXMLToken(XML_N_OFFICE_EXT), XML_NAMESPACE_OFFICE_EXT );
360 1287 : mpNamespaceMap->Add( OUString( sXML_np__ooo ), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
361 1287 : mpNamespaceMap->Add( OUString( sXML_np__style ), GetXMLToken(XML_N_STYLE), XML_NAMESPACE_STYLE );
362 1287 : mpNamespaceMap->Add( OUString( sXML_np__text ), GetXMLToken(XML_N_TEXT), XML_NAMESPACE_TEXT );
363 1287 : mpNamespaceMap->Add( OUString( sXML_np__table ), GetXMLToken(XML_N_TABLE), XML_NAMESPACE_TABLE );
364 1287 : mpNamespaceMap->Add( OUString( sXML_np__table_ext ), GetXMLToken(XML_N_TABLE_EXT), XML_NAMESPACE_TABLE_EXT );
365 1287 : mpNamespaceMap->Add( OUString( sXML_np__draw ), GetXMLToken(XML_N_DRAW), XML_NAMESPACE_DRAW );
366 1287 : mpNamespaceMap->Add( OUString( sXML_np__draw_ext ), GetXMLToken(XML_N_DRAW_EXT), XML_NAMESPACE_DRAW_EXT );
367 1287 : mpNamespaceMap->Add( OUString( sXML_np__dr3d ), GetXMLToken(XML_N_DR3D), XML_NAMESPACE_DR3D );
368 1287 : mpNamespaceMap->Add( OUString( sXML_np__fo ), GetXMLToken(XML_N_FO_COMPAT), XML_NAMESPACE_FO );
369 1287 : mpNamespaceMap->Add( OUString( sXML_np__xlink ), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
370 1287 : mpNamespaceMap->Add( OUString( sXML_np__dc ), GetXMLToken(XML_N_DC), XML_NAMESPACE_DC );
371 1287 : mpNamespaceMap->Add( OUString( sXML_np__dom ), GetXMLToken(XML_N_DOM), XML_NAMESPACE_DOM );
372 1287 : mpNamespaceMap->Add( OUString( sXML_np__meta ), GetXMLToken(XML_N_META), XML_NAMESPACE_META );
373 1287 : mpNamespaceMap->Add( OUString( sXML_np__number ), GetXMLToken(XML_N_NUMBER), XML_NAMESPACE_NUMBER );
374 1287 : mpNamespaceMap->Add( OUString( sXML_np__svg ), GetXMLToken(XML_N_SVG_COMPAT), XML_NAMESPACE_SVG );
375 1287 : mpNamespaceMap->Add( OUString( sXML_np__chart ), GetXMLToken(XML_N_CHART), XML_NAMESPACE_CHART );
376 1287 : mpNamespaceMap->Add( OUString( sXML_np__math ), GetXMLToken(XML_N_MATH), XML_NAMESPACE_MATH );
377 1287 : mpNamespaceMap->Add(OUString( sXML_np__form ), GetXMLToken(XML_N_FORM), XML_NAMESPACE_FORM );
378 1287 : mpNamespaceMap->Add( OUString( sXML_np__script ), GetXMLToken(XML_N_SCRIPT), XML_NAMESPACE_SCRIPT );
379 1287 : mpNamespaceMap->Add( OUString( sXML_np__config ), GetXMLToken(XML_N_CONFIG), XML_NAMESPACE_CONFIG );
380 1287 : mpNamespaceMap->Add( OUString( sXML_np__xforms ), GetXMLToken(XML_N_XFORMS_1_0), XML_NAMESPACE_XFORMS );
381 1287 : mpNamespaceMap->Add( OUString( sXML_np__formx ), GetXMLToken( XML_N_FORMX ), XML_NAMESPACE_FORMX );
382 1287 : mpNamespaceMap->Add( OUString( sXML_np__xsd ), GetXMLToken(XML_N_XSD), XML_NAMESPACE_XSD );
383 1287 : mpNamespaceMap->Add( OUString( sXML_np__xsi ), GetXMLToken(XML_N_XSI), XML_NAMESPACE_XFORMS );
384 1287 : mpNamespaceMap->Add( OUString( sXML_np__ooow ), GetXMLToken(XML_N_OOOW), XML_NAMESPACE_OOOW );
385 1287 : mpNamespaceMap->Add( OUString( sXML_np__oooc ), GetXMLToken(XML_N_OOOC), XML_NAMESPACE_OOOC );
386 1287 : mpNamespaceMap->Add( OUString( sXML_np__field ), GetXMLToken(XML_N_FIELD), XML_NAMESPACE_FIELD );
387 1287 : mpNamespaceMap->Add( OUString( sXML_np__of ), GetXMLToken(XML_N_OF), XML_NAMESPACE_OF );
388 1287 : mpNamespaceMap->Add( OUString( sXML_np__xhtml ), GetXMLToken(XML_N_XHTML), XML_NAMESPACE_XHTML );
389 1287 : mpNamespaceMap->Add( OUString( sXML_np__css3text ), GetXMLToken(XML_N_CSS3TEXT), XML_NAMESPACE_CSS3TEXT );
390 :
391 1287 : mpNamespaceMap->Add( "_calc_libo", GetXMLToken(XML_N_CALC_EXT), XML_NAMESPACE_CALC_EXT);
392 : mpNamespaceMap->Add( "_office_libo",
393 1287 : GetXMLToken(XML_N_LO_EXT), XML_NAMESPACE_LO_EXT);
394 : }
395 :
396 1593 : msPackageProtocol = "vnd.sun.star.Package:";
397 :
398 1593 : if (mxNumberFormatsSupplier.is())
399 0 : mpNumImport = new SvXMLNumFmtHelper(mxNumberFormatsSupplier, GetComponentContext());
400 :
401 1593 : if (mxModel.is() && !mxEventListener.is())
402 : {
403 0 : mxEventListener.set(new SvXMLImportEventListener(this));
404 0 : mxModel->addEventListener(mxEventListener);
405 : }
406 :
407 1593 : ::comphelper::UnoInterfaceToUniqueIdentifierMapper maInterfaceToIdentifierMapper;
408 :
409 1593 : }
410 :
411 1593 : SvXMLImport::SvXMLImport(
412 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
413 : OUString const & implementationName, sal_uInt16 nImportFlags ) throw ()
414 1593 : : mpImpl( new SvXMLImport_Impl(xContext, implementationName) ),
415 1593 : mpNamespaceMap( new SvXMLNamespaceMap ),
416 :
417 : mpUnitConv( new SvXMLUnitConverter( xContext,
418 1593 : util::MeasureUnit::MM_100TH, util::MeasureUnit::MM_100TH) ),
419 :
420 1593 : mpContexts( new SvXMLImportContexts_Impl ),
421 : mpNumImport( NULL ),
422 : mpProgressBarHelper( NULL ),
423 : mpEventImportHelper( NULL ),
424 : mpXMLErrors( NULL ),
425 : mpStyleMap(0),
426 : mnImportFlags( nImportFlags ),
427 : mnErrorFlags(0),
428 : mbIsFormsSupported( true ),
429 : mbIsTableShapeSupported( false ),
430 7965 : mbIsGraphicLoadOnDemandSupported( true )
431 : {
432 : SAL_WARN_IF( !xContext.is(), "xmloff.core", "got no service manager" );
433 1593 : _InitCtor();
434 1593 : }
435 :
436 3186 : SvXMLImport::~SvXMLImport() throw ()
437 : {
438 1593 : delete mpXMLErrors;
439 1593 : delete mpNamespaceMap;
440 1593 : delete mpUnitConv;
441 1593 : delete mpEventImportHelper;
442 1593 : if( mpContexts )
443 : {
444 3202 : while( !mpContexts->empty() )
445 : {
446 16 : SvXMLImportContext *pContext = mpContexts->back();
447 16 : mpContexts->pop_back();
448 16 : if( pContext )
449 16 : pContext->ReleaseRef();
450 : }
451 1593 : delete mpContexts;
452 : }
453 :
454 : // #i9518# the import component might not be deleted until after the document has been closed,
455 : // so the stuff that accesses the document has been moved to endDocument.
456 :
457 : // pNumImport is allocated in the ctor, so it must also be deleted here in case the component
458 : // is created and deleted without actually importing.
459 1593 : delete mpNumImport;
460 1593 : delete mpProgressBarHelper;
461 :
462 1593 : if( mpImpl )
463 1593 : delete mpImpl;
464 :
465 1593 : if (mxEventListener.is() && mxModel.is())
466 1255 : mxModel->removeEventListener(mxEventListener);
467 1593 : }
468 :
469 : namespace
470 : {
471 : class theSvXMLImportUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvXMLImportUnoTunnelId> {};
472 : }
473 :
474 : // XUnoTunnel & co
475 0 : const uno::Sequence< sal_Int8 > & SvXMLImport::getUnoTunnelId() throw()
476 : {
477 0 : return theSvXMLImportUnoTunnelId::get().getSeq();
478 : }
479 :
480 : // XUnoTunnel
481 0 : sal_Int64 SAL_CALL SvXMLImport::getSomething( const uno::Sequence< sal_Int8 >& rId )
482 : throw( uno::RuntimeException, std::exception )
483 : {
484 0 : if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
485 0 : rId.getConstArray(), 16 ) )
486 : {
487 0 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
488 : }
489 0 : return 0;
490 : }
491 :
492 1465 : void SAL_CALL SvXMLImport::startDocument()
493 : throw (xml::sax::SAXException,
494 : uno::RuntimeException,
495 : std::exception)
496 : {
497 : SAL_INFO( "xmloff.core", "{ SvXMLImport::startDocument" );
498 1465 : if( !mxGraphicResolver.is() || !mxEmbeddedResolver.is() )
499 : {
500 868 : Reference< lang::XMultiServiceFactory > xFactory( mxModel, UNO_QUERY );
501 868 : if( xFactory.is() )
502 : {
503 : try
504 : {
505 633 : if( !mxGraphicResolver.is() )
506 : {
507 786 : mxGraphicResolver = Reference< XGraphicObjectResolver >::query(
508 393 : xFactory->createInstance(
509 : // #99870# Import... instead of Export...
510 786 : "com.sun.star.document.ImportGraphicObjectResolver"));
511 393 : mpImpl->mbOwnGraphicResolver = mxGraphicResolver.is();
512 : }
513 :
514 633 : if( !mxEmbeddedResolver.is() )
515 : {
516 1266 : mxEmbeddedResolver = Reference< XEmbeddedObjectResolver >::query(
517 633 : xFactory->createInstance(
518 : // #99870# Import... instead of Export...
519 1266 : "com.sun.star.document.ImportEmbeddedObjectResolver"));
520 633 : mpImpl->mbOwnEmbeddedResolver = mxEmbeddedResolver.is();
521 : }
522 : }
523 0 : catch( com::sun::star::uno::Exception& )
524 : {
525 : }
526 868 : }
527 : }
528 1465 : }
529 :
530 1459 : void SAL_CALL SvXMLImport::endDocument()
531 : throw(xml::sax::SAXException,
532 : uno::RuntimeException,
533 : std::exception)
534 : {
535 : SAL_INFO( "xmloff.core", "} SvXMLImport::startDocument" );
536 : // #i9518# All the stuff that accesses the document has to be done here, not in the dtor,
537 : // because the SvXMLImport dtor might not be called until after the document has been closed.
538 :
539 1459 : if (mpImpl->mpRDFaHelper.get())
540 : {
541 : const uno::Reference<rdf::XRepositorySupplier> xRS(mxModel,
542 6 : uno::UNO_QUERY);
543 6 : if (xRS.is())
544 : {
545 6 : mpImpl->mpRDFaHelper->InsertRDFa( xRS );
546 6 : }
547 : }
548 :
549 1459 : if (mpNumImport)
550 : {
551 562 : delete mpNumImport;
552 562 : mpNumImport = NULL;
553 : }
554 1459 : if (mxImportInfo.is())
555 : {
556 1208 : uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
557 1208 : if (xPropertySetInfo.is())
558 : {
559 1208 : if (mpProgressBarHelper)
560 : {
561 679 : OUString sProgressMax(XML_PROGRESSMAX);
562 1358 : OUString sProgressCurrent(XML_PROGRESSCURRENT);
563 1358 : OUString sRepeat(XML_PROGRESSREPEAT);
564 1339 : if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
565 660 : xPropertySetInfo->hasPropertyByName(sProgressCurrent))
566 : {
567 660 : sal_Int32 nProgressMax(mpProgressBarHelper->GetReference());
568 660 : sal_Int32 nProgressCurrent(mpProgressBarHelper->GetValue());
569 660 : uno::Any aAny;
570 660 : aAny <<= nProgressMax;
571 660 : mxImportInfo->setPropertyValue(sProgressMax, aAny);
572 660 : aAny <<= nProgressCurrent;
573 660 : mxImportInfo->setPropertyValue(sProgressCurrent, aAny);
574 : }
575 679 : if (xPropertySetInfo->hasPropertyByName(sRepeat))
576 679 : mxImportInfo->setPropertyValue(sRepeat, css::uno::makeAny(mpProgressBarHelper->GetRepeat()));
577 : // pProgressBarHelper is deleted in dtor
578 : }
579 1208 : OUString sNumberStyles(XML_NUMBERSTYLES);
580 1208 : if (mxNumberStyles.is() && xPropertySetInfo->hasPropertyByName(sNumberStyles))
581 : {
582 218 : uno::Any aAny;
583 218 : aAny <<= mxNumberStyles;
584 218 : mxImportInfo->setPropertyValue(sNumberStyles, aAny);
585 1208 : }
586 1208 : }
587 : }
588 :
589 1459 : if( mxFontDecls.Is() )
590 518 : ((SvXMLStylesContext *)&mxFontDecls)->Clear();
591 1459 : if( mxStyles.Is() )
592 257 : ((SvXMLStylesContext *)&mxStyles)->Clear();
593 1459 : if( mxAutoStyles.Is() )
594 573 : ((SvXMLStylesContext *)&mxAutoStyles)->Clear();
595 1459 : if( mxMasterStyles.Is() )
596 149 : ((SvXMLStylesContext *)&mxMasterStyles)->Clear();
597 :
598 : // possible form-layer related knittings which can only be done when
599 : // the whole document exists
600 1459 : if ( mxFormImport.is() )
601 621 : mxFormImport->documentDone();
602 :
603 : // The shape import helper does the z-order sorting in the dtor,
604 : // so it must be deleted here, too.
605 1459 : mxShapeImport = NULL;
606 :
607 1459 : if( mpImpl->mbOwnGraphicResolver )
608 : {
609 385 : Reference< lang::XComponent > xComp( mxGraphicResolver, UNO_QUERY );
610 385 : xComp->dispose();
611 : }
612 :
613 1459 : if( mpImpl->mbOwnEmbeddedResolver )
614 : {
615 385 : Reference< lang::XComponent > xComp( mxEmbeddedResolver, UNO_QUERY );
616 385 : xComp->dispose();
617 : }
618 1459 : if( mpStyleMap )
619 : {
620 350 : mpStyleMap->release();
621 350 : mpStyleMap = 0;
622 : }
623 :
624 1459 : if ( mpXMLErrors != NULL )
625 : {
626 10 : mpXMLErrors->ThrowErrorAsSAXException( XMLERROR_FLAG_SEVERE );
627 : }
628 1459 : }
629 :
630 124595 : void SAL_CALL SvXMLImport::startElement( const OUString& rName,
631 : const uno::Reference< xml::sax::XAttributeList >& xAttrList )
632 : throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
633 : {
634 124595 : SvXMLNamespaceMap *pRewindMap = 0;
635 : // SAL_INFO("svg", "startElement " << rName);
636 : // Process namespace attributes. This must happen before creating the
637 : // context, because namespace decaration apply to the element name itself.
638 124595 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
639 398633 : for( sal_Int16 i=0; i < nAttrCount; i++ )
640 : {
641 274038 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
642 274038 : if ( rAttrName == "office:version" )
643 : {
644 1278 : mpImpl->aODFVersion = xAttrList->getValueByIndex( i );
645 :
646 : // the ODF version in content.xml and manifest.xml must be the same starting from ODF1.2
647 1278 : if ( mpImpl->mStreamName == "content.xml" && !IsODFVersionConsistent( mpImpl->aODFVersion ) )
648 : {
649 : throw xml::sax::SAXException("Inconsistent ODF versions in content.xml and manifest.xml!",
650 : uno::Reference< uno::XInterface >(),
651 : uno::makeAny(
652 : packages::zip::ZipIOException("Inconsistent ODF versions in content.xml and manifest.xml!",
653 0 : Reference< XInterface >() ) ) );
654 : }
655 : }
656 818280 : else if( ( rAttrName.getLength() >= 5 ) &&
657 326494 : ( rAttrName.startsWith( GetXMLToken(XML_XMLNS) ) ) &&
658 53732 : ( rAttrName.getLength() == 5 || ':' == rAttrName[5] ) )
659 : {
660 26867 : if( !pRewindMap )
661 : {
662 1539 : pRewindMap = mpNamespaceMap;
663 1539 : mpNamespaceMap = new SvXMLNamespaceMap( *mpNamespaceMap );
664 : }
665 26867 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
666 :
667 26867 : OUString aPrefix( ( rAttrName.getLength() == 5 )
668 : ? OUString()
669 53734 : : rAttrName.copy( 6 ) );
670 : // Add namespace, but only if it is known.
671 26867 : sal_uInt16 nKey = mpNamespaceMap->AddIfKnown( aPrefix, rAttrValue );
672 : // If namespace is unknown, try to match a name with similar
673 : // TC Id an version
674 26867 : if( XML_NAMESPACE_UNKNOWN == nKey )
675 : {
676 3403 : OUString aTestName( rAttrValue );
677 3403 : if( SvXMLNamespaceMap::NormalizeURI( aTestName ) )
678 370 : nKey = mpNamespaceMap->AddIfKnown( aPrefix, aTestName );
679 : }
680 : // If that namespace is not known, too, add it as unknown
681 26867 : if( XML_NAMESPACE_UNKNOWN == nKey )
682 30168 : mpNamespaceMap->Add( aPrefix, rAttrValue );
683 :
684 : }
685 274038 : }
686 :
687 : // Get element's namespace and local name.
688 124595 : OUString aLocalName;
689 : sal_uInt16 nPrefix =
690 124595 : mpNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
691 :
692 : // If there are contexts already, call a CreateChildContext at the topmost
693 : // context. Otherwise, create a default context.
694 : SvXMLImportContext *pContext;
695 124595 : sal_uInt16 nCount = mpContexts->size();
696 124595 : if( nCount > 0 )
697 : {
698 123130 : pContext = (*mpContexts)[nCount - 1]->CreateChildContext( nPrefix,
699 : aLocalName,
700 123130 : xAttrList );
701 : SAL_WARN_IF( !pContext || (pContext->GetPrefix() != nPrefix), "xmloff.core",
702 : "SvXMLImport::startElement: created context has wrong prefix" );
703 : }
704 : else
705 : {
706 1465 : pContext = CreateContext( nPrefix, aLocalName, xAttrList );
707 1465 : if( (nPrefix & XML_NAMESPACE_UNKNOWN_FLAG) != 0 &&
708 0 : IS_TYPE( SvXMLImportContext, pContext ) )
709 : {
710 0 : OUString aMsg( "Root element unknown" );
711 0 : Reference<xml::sax::XLocator> xDummyLocator;
712 0 : Sequence < OUString > aParams(1);
713 0 : aParams.getArray()[0] = rName;
714 :
715 : SetError( XMLERROR_FLAG_SEVERE|XMLERROR_UNKNOWN_ROOT,
716 0 : aParams, aMsg, xDummyLocator );
717 : }
718 : }
719 :
720 : SAL_WARN_IF( !pContext, "xmloff.core", "SvXMLImport::startElement: missing context" );
721 124593 : if( !pContext )
722 0 : pContext = new SvXMLImportContext( *this, nPrefix, aLocalName );
723 :
724 124593 : pContext->AddRef();
725 :
726 : // Remember old namespace map.
727 124593 : if( pRewindMap )
728 1537 : pContext->SetRewindMap( pRewindMap );
729 :
730 : // Call a startElement at the new context.
731 124593 : pContext->StartElement( xAttrList );
732 :
733 : // Push context on stack.
734 124595 : mpContexts->push_back( pContext );
735 124593 : }
736 :
737 124577 : void SAL_CALL SvXMLImport::endElement( const OUString&
738 : #ifdef DBG_UTIL
739 : rName
740 : #endif
741 : )
742 : throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
743 : {
744 124577 : sal_uInt16 nCount = mpContexts->size();
745 : SAL_WARN_IF( nCount == 0, "xmloff.core", "SvXMLImport::endElement: no context left" );
746 124577 : if( nCount > 0 )
747 : {
748 : // Get topmost context and remove it from the stack.
749 124577 : SvXMLImportContext *pContext = mpContexts->back();
750 124577 : mpContexts->pop_back();
751 :
752 : #ifdef DBG_UTIL
753 : // Non product only: check if endElement call matches startELement call.
754 : OUString aLocalName;
755 : sal_uInt16 nPrefix =
756 : mpNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
757 : SAL_WARN_IF( pContext->GetPrefix() != nPrefix, "xmloff.core", "SvXMLImport::endElement: popped context has wrong prefix" );
758 : SAL_WARN_IF( pContext->GetLocalName() != aLocalName, "xmloff.core", "SvXMLImport::endElement: popped context has wrong lname" );
759 : #endif
760 :
761 : // Call a EndElement at the current context.
762 124577 : pContext->EndElement();
763 :
764 : // Get a namespace map to rewind.
765 124577 : SvXMLNamespaceMap *pRewindMap = pContext->GetRewindMap();
766 :
767 : // Delete the current context.
768 124577 : pContext->ReleaseRef();
769 124577 : pContext = 0;
770 :
771 : // Rewind a namespace map.
772 124577 : if( pRewindMap )
773 : {
774 1535 : delete mpNamespaceMap;
775 1535 : mpNamespaceMap = pRewindMap;
776 : }
777 : }
778 124577 : }
779 :
780 73931 : void SAL_CALL SvXMLImport::characters( const OUString& rChars )
781 : throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
782 : {
783 73931 : if( !mpContexts->empty() )
784 : {
785 73931 : mpContexts->back()->Characters( rChars );
786 : }
787 73931 : }
788 :
789 0 : void SAL_CALL SvXMLImport::ignorableWhitespace( const OUString& )
790 : throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
791 : {
792 0 : }
793 :
794 0 : void SAL_CALL SvXMLImport::processingInstruction( const OUString&,
795 : const OUString& )
796 : throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
797 : {
798 0 : }
799 :
800 1373 : void SAL_CALL SvXMLImport::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& rLocator )
801 : throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
802 : {
803 1373 : mxLocator = rLocator;
804 1373 : }
805 :
806 : // XExtendedDocumentHandler
807 0 : void SAL_CALL SvXMLImport::startCDATA( void ) throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
808 : {
809 0 : }
810 :
811 0 : void SAL_CALL SvXMLImport::endCDATA( void ) throw(uno::RuntimeException, std::exception)
812 : {
813 0 : }
814 :
815 1078 : void SAL_CALL SvXMLImport::comment( const OUString& )
816 : throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
817 : {
818 1078 : }
819 :
820 0 : void SAL_CALL SvXMLImport::allowLineBreak( void )
821 : throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
822 : {
823 0 : }
824 :
825 2903 : void SAL_CALL SvXMLImport::unknown( const OUString& )
826 : throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
827 : {
828 2903 : }
829 :
830 324 : void SvXMLImport::SetStatistics(const uno::Sequence< beans::NamedValue> &)
831 : {
832 324 : GetProgressBarHelper()->SetRepeat(false);
833 324 : GetProgressBarHelper()->SetReference(0);
834 324 : }
835 :
836 : // XImporter
837 1294 : void SAL_CALL SvXMLImport::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
838 : throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
839 : {
840 1294 : mxModel = uno::Reference< frame::XModel >::query( xDoc );
841 1294 : if( !mxModel.is() )
842 0 : throw lang::IllegalArgumentException();
843 :
844 : try
845 : {
846 : uno::Reference<document::XStorageBasedDocument> const xSBDoc(mxModel,
847 1294 : uno::UNO_QUERY_THROW);
848 : uno::Reference<embed::XStorage> const xStor(
849 2546 : xSBDoc->getDocumentStorage());
850 1252 : if (xStor.is())
851 : {
852 : mpImpl->mbIsOOoXML =
853 1006 : ::comphelper::OStorageHelper::GetXStorageFormat(xStor)
854 2012 : < SOFFICE_FILEFORMAT_8;
855 1294 : }
856 : }
857 42 : catch (uno::Exception const&)
858 : {
859 : SAL_WARN("xmloff.core", "exception caught");
860 : DBG_UNHANDLED_EXCEPTION();
861 : }
862 1294 : if (!mxEventListener.is())
863 : {
864 1263 : mxEventListener.set(new SvXMLImportEventListener(this));
865 1263 : mxModel->addEventListener(mxEventListener);
866 : }
867 :
868 : SAL_WARN_IF( mpNumImport, "xmloff.core", "number format import already exists." );
869 1294 : if( mpNumImport )
870 : {
871 0 : delete mpNumImport;
872 0 : mpNumImport = 0;
873 : }
874 1294 : }
875 :
876 : // XFilter
877 0 : sal_Bool SAL_CALL SvXMLImport::filter( const uno::Sequence< beans::PropertyValue >& )
878 : throw (uno::RuntimeException, std::exception)
879 : {
880 0 : return sal_False;
881 : }
882 :
883 0 : void SAL_CALL SvXMLImport::cancel( )
884 : throw (uno::RuntimeException, std::exception)
885 : {
886 0 : }
887 :
888 : // XInitialize
889 1236 : void SAL_CALL SvXMLImport::initialize( const uno::Sequence< uno::Any >& aArguments )
890 : throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception)
891 : {
892 1236 : const sal_Int32 nAnyCount = aArguments.getLength();
893 1236 : const uno::Any* pAny = aArguments.getConstArray();
894 :
895 5049 : for( sal_Int32 nIndex = 0; nIndex < nAnyCount; nIndex++, pAny++ )
896 : {
897 3813 : Reference<XInterface> xValue;
898 3813 : *pAny >>= xValue;
899 :
900 : uno::Reference<task::XStatusIndicator> xTmpStatusIndicator(
901 7626 : xValue, UNO_QUERY );
902 3813 : if( xTmpStatusIndicator.is() )
903 489 : mxStatusIndicator = xTmpStatusIndicator;
904 :
905 : uno::Reference<document::XGraphicObjectResolver> xTmpGraphicResolver(
906 7626 : xValue, UNO_QUERY );
907 3813 : if( xTmpGraphicResolver.is() )
908 837 : mxGraphicResolver = xTmpGraphicResolver;
909 :
910 : uno::Reference<document::XEmbeddedObjectResolver> xTmpObjectResolver(
911 7626 : xValue, UNO_QUERY );
912 3813 : if( xTmpObjectResolver.is() )
913 597 : mxEmbeddedResolver = xTmpObjectResolver;
914 :
915 7626 : uno::Reference<beans::XPropertySet> xTmpPropSet( xValue, UNO_QUERY );
916 3813 : if( xTmpPropSet.is() )
917 : {
918 1194 : mxImportInfo = xTmpPropSet;
919 1194 : uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
920 1194 : if (xPropertySetInfo.is())
921 : {
922 1194 : OUString sPropName(XML_NUMBERSTYLES);
923 1194 : if (xPropertySetInfo->hasPropertyByName(sPropName))
924 : {
925 872 : uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
926 872 : aAny >>= mxNumberStyles;
927 : }
928 :
929 1194 : sPropName = "PrivateData";
930 1194 : if (xPropertySetInfo->hasPropertyByName(sPropName))
931 : {
932 1176 : Reference < XInterface > xIfc;
933 2352 : uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
934 1176 : aAny >>= xIfc;
935 :
936 1176 : StyleMap *pSMap = StyleMap::getImplementation( xIfc );
937 1176 : if( pSMap )
938 : {
939 156 : mpStyleMap = pSMap;
940 156 : mpStyleMap->acquire();
941 1176 : }
942 : }
943 2388 : OUString sBaseURI;
944 1194 : sPropName = "BaseURI";
945 1194 : if (xPropertySetInfo->hasPropertyByName(sPropName))
946 : {
947 1194 : uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
948 1194 : aAny >>= sBaseURI;
949 1194 : mpImpl->aBaseURL.SetURL( sBaseURI );
950 1194 : mpImpl->aDocBase.SetURL( sBaseURI );
951 : }
952 2388 : OUString sRelPath;
953 1194 : sPropName = "StreamRelPath";
954 1194 : if( xPropertySetInfo->hasPropertyByName(sPropName) )
955 : {
956 1176 : uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
957 1176 : aAny >>= sRelPath;
958 : }
959 2388 : OUString sName;
960 1194 : sPropName = "StreamName";
961 1194 : if( xPropertySetInfo->hasPropertyByName(sPropName) )
962 : {
963 1194 : uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
964 1194 : aAny >>= sName;
965 : }
966 1194 : if( !sBaseURI.isEmpty() && !sName.isEmpty() )
967 : {
968 944 : if( !sRelPath.isEmpty() )
969 0 : mpImpl->aBaseURL.insertName( sRelPath );
970 944 : mpImpl->aBaseURL.insertName( sName );
971 : }
972 1194 : mpImpl->mStreamName = sName; // Note: may be empty (XSLT)
973 : // Retrieve property <ShapePositionInHoriL2R> (#i28749#)
974 1194 : sPropName = "ShapePositionInHoriL2R";
975 1194 : if( xPropertySetInfo->hasPropertyByName(sPropName) )
976 : {
977 456 : uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
978 456 : aAny >>= (mpImpl->mbShapePositionInHoriL2R);
979 : }
980 1194 : sPropName = "TextDocInOOoFileFormat";
981 1194 : if( xPropertySetInfo->hasPropertyByName(sPropName) )
982 : {
983 456 : uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
984 456 : aAny >>= (mpImpl->mbTextDocInOOoFileFormat);
985 : }
986 :
987 1194 : sPropName = "SourceStorage";
988 1194 : if( xPropertySetInfo->hasPropertyByName(sPropName) )
989 2120 : mxImportInfo->getPropertyValue(sPropName) >>= mpImpl->mxSourceStorage;
990 1194 : }
991 : }
992 3813 : }
993 1236 : }
994 :
995 : // XServiceInfo
996 0 : OUString SAL_CALL SvXMLImport::getImplementationName()
997 : throw(uno::RuntimeException, std::exception)
998 : {
999 0 : return mpImpl->implementationName;
1000 : }
1001 :
1002 0 : sal_Bool SAL_CALL SvXMLImport::supportsService( const OUString& rServiceName )
1003 : throw(::com::sun::star::uno::RuntimeException, std::exception)
1004 : {
1005 0 : return cppu::supportsService(this, rServiceName);
1006 : }
1007 :
1008 0 : uno::Sequence< OUString > SAL_CALL SvXMLImport::getSupportedServiceNames( )
1009 : throw(uno::RuntimeException, std::exception)
1010 : {
1011 0 : uno::Sequence<OUString> aSeq(2);
1012 0 : aSeq[0] = "com.sun.star.document.ImportFilter";
1013 0 : aSeq[1] = "com.sun.star.xml.XMLImportFilter";
1014 0 : return aSeq;
1015 : }
1016 :
1017 359 : XMLTextImportHelper* SvXMLImport::CreateTextImport()
1018 : {
1019 359 : return new XMLTextImportHelper( mxModel, *this );
1020 : }
1021 :
1022 177 : XMLShapeImportHelper* SvXMLImport::CreateShapeImport()
1023 : {
1024 177 : return new XMLShapeImportHelper( *this, mxModel );
1025 : }
1026 :
1027 623 : SchXMLImportHelper* SvXMLImport::CreateChartImport()
1028 : {
1029 623 : return new SchXMLImportHelper();
1030 : }
1031 :
1032 623 : ::xmloff::OFormLayerXMLImport* SvXMLImport::CreateFormImport()
1033 : {
1034 623 : return new ::xmloff::OFormLayerXMLImport(*this);
1035 : }
1036 :
1037 :
1038 : // Get or create fill/line/lineend-style-helper
1039 :
1040 :
1041 31 : const Reference< container::XNameContainer > & SvXMLImport::GetGradientHelper()
1042 : {
1043 31 : if( !mxGradientHelper.is() )
1044 : {
1045 13 : if( mxModel.is() )
1046 : {
1047 13 : Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1048 13 : if( xServiceFact.is() )
1049 : {
1050 : try
1051 : {
1052 39 : mxGradientHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1053 26 : "com.sun.star.drawing.GradientTable" ), UNO_QUERY);
1054 : }
1055 0 : catch( lang::ServiceNotRegisteredException& )
1056 : {}
1057 13 : }
1058 : }
1059 : }
1060 :
1061 31 : return mxGradientHelper;
1062 : }
1063 :
1064 21 : const Reference< container::XNameContainer > & SvXMLImport::GetHatchHelper()
1065 : {
1066 21 : if( !mxHatchHelper.is() )
1067 : {
1068 11 : if( mxModel.is() )
1069 : {
1070 11 : Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1071 11 : if( xServiceFact.is() )
1072 : {
1073 : try
1074 : {
1075 33 : mxHatchHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1076 22 : "com.sun.star.drawing.HatchTable" ), UNO_QUERY);
1077 : }
1078 0 : catch( lang::ServiceNotRegisteredException& )
1079 : {}
1080 11 : }
1081 : }
1082 : }
1083 :
1084 21 : return mxHatchHelper;
1085 : }
1086 :
1087 13 : const Reference< container::XNameContainer > & SvXMLImport::GetBitmapHelper()
1088 : {
1089 13 : if( !mxBitmapHelper.is() )
1090 : {
1091 10 : if( mxModel.is() )
1092 : {
1093 10 : Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1094 10 : if( xServiceFact.is() )
1095 : {
1096 : try
1097 : {
1098 30 : mxBitmapHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1099 20 : "com.sun.star.drawing.BitmapTable" ), UNO_QUERY);
1100 : }
1101 0 : catch( lang::ServiceNotRegisteredException& )
1102 : {}
1103 10 : }
1104 : }
1105 : }
1106 :
1107 13 : return mxBitmapHelper;
1108 : }
1109 :
1110 6 : const Reference< container::XNameContainer > & SvXMLImport::GetTransGradientHelper()
1111 : {
1112 6 : if( !mxTransGradientHelper.is() )
1113 : {
1114 3 : if( mxModel.is() )
1115 : {
1116 3 : Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1117 3 : if( xServiceFact.is() )
1118 : {
1119 : try
1120 : {
1121 9 : mxTransGradientHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1122 6 : "com.sun.star.drawing.TransparencyGradientTable" ), UNO_QUERY);
1123 : }
1124 0 : catch( lang::ServiceNotRegisteredException& )
1125 : {}
1126 3 : }
1127 : }
1128 : }
1129 :
1130 6 : return mxTransGradientHelper;
1131 : }
1132 :
1133 35 : const Reference< container::XNameContainer > & SvXMLImport::GetMarkerHelper()
1134 : {
1135 35 : if( !mxMarkerHelper.is() )
1136 : {
1137 33 : if( mxModel.is() )
1138 : {
1139 33 : Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1140 33 : if( xServiceFact.is() )
1141 : {
1142 : try
1143 : {
1144 99 : mxMarkerHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1145 66 : "com.sun.star.drawing.MarkerTable" ), UNO_QUERY);
1146 : }
1147 0 : catch( lang::ServiceNotRegisteredException& )
1148 : {}
1149 33 : }
1150 : }
1151 : }
1152 :
1153 35 : return mxMarkerHelper;
1154 : }
1155 :
1156 14 : const Reference< container::XNameContainer > & SvXMLImport::GetDashHelper()
1157 : {
1158 14 : if( !mxDashHelper.is() )
1159 : {
1160 9 : if( mxModel.is() )
1161 : {
1162 9 : Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1163 9 : if( xServiceFact.is() )
1164 : {
1165 : try
1166 : {
1167 27 : mxDashHelper = Reference< container::XNameContainer >( xServiceFact->createInstance(
1168 18 : "com.sun.star.drawing.DashTable" ), UNO_QUERY);
1169 : }
1170 0 : catch( lang::ServiceNotRegisteredException& )
1171 : {}
1172 9 : }
1173 : }
1174 : }
1175 :
1176 14 : return mxDashHelper;
1177 : }
1178 :
1179 219 : bool SvXMLImport::IsPackageURL( const OUString& rURL ) const
1180 : {
1181 :
1182 : // if, and only if, only parts are imported, then we're in a package
1183 219 : const sal_uInt32 nTest = IMPORT_META|IMPORT_STYLES|IMPORT_CONTENT|IMPORT_SETTINGS;
1184 219 : if( (mnImportFlags & nTest) == nTest )
1185 0 : return false;
1186 :
1187 : // Some quick tests: Some may rely on the package structure!
1188 219 : sal_Int32 nLen = rURL.getLength();
1189 219 : if( (nLen > 0 && '/' == rURL[0]) )
1190 : // RFC2396 net_path or abs_path
1191 0 : return false;
1192 219 : else if( nLen > 1 && '.' == rURL[0] )
1193 : {
1194 129 : if( '.' == rURL[1] )
1195 : // ../: We are never going up one level, so we know
1196 : // it's not an external URI
1197 0 : return false;
1198 129 : else if( '/' == rURL[1] )
1199 : // we are remaining on a level, so it's an package URI
1200 129 : return true;
1201 : }
1202 :
1203 : // Now check for a RFC2396 schema
1204 90 : sal_Int32 nPos = 1;
1205 795 : while( nPos < nLen )
1206 : {
1207 705 : switch( rURL[nPos] )
1208 : {
1209 : case '/':
1210 : // a relative path segement
1211 90 : return true;
1212 : case ':':
1213 : // a schema
1214 0 : return false;
1215 : default:
1216 615 : break;
1217 : // we don't care about any other characters
1218 : }
1219 615 : ++nPos;
1220 : }
1221 :
1222 0 : return true;
1223 : }
1224 :
1225 128 : OUString SvXMLImport::ResolveGraphicObjectURL( const OUString& rURL,
1226 : bool bLoadOnDemand )
1227 : {
1228 128 : OUString sRet;
1229 :
1230 128 : if( IsPackageURL( rURL ) )
1231 : {
1232 128 : if( !bLoadOnDemand && mxGraphicResolver.is() )
1233 : {
1234 63 : OUString aTmp( msPackageProtocol );
1235 63 : aTmp += rURL;
1236 63 : sRet = mxGraphicResolver->resolveGraphicObjectURL( aTmp );
1237 : }
1238 :
1239 128 : if( sRet.isEmpty() )
1240 : {
1241 65 : sRet = msPackageProtocol;
1242 65 : sRet += rURL;
1243 : }
1244 : }
1245 :
1246 128 : if( sRet.isEmpty() )
1247 0 : sRet = GetAbsoluteReference( rURL );
1248 :
1249 128 : return sRet;
1250 : }
1251 :
1252 124 : Reference< XOutputStream > SvXMLImport::GetStreamForGraphicObjectURLFromBase64()
1253 : {
1254 124 : Reference< XOutputStream > xOStm;
1255 248 : Reference< document::XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
1256 :
1257 124 : if( xStmResolver.is() )
1258 124 : xOStm = xStmResolver->createOutputStream();
1259 :
1260 248 : return xOStm;
1261 : }
1262 :
1263 124 : OUString SvXMLImport::ResolveGraphicObjectURLFromBase64(
1264 : const Reference < XOutputStream >& rOut )
1265 : {
1266 124 : OUString sURL;
1267 248 : Reference< document::XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
1268 124 : if( xStmResolver.is() )
1269 124 : sURL = xStmResolver->resolveOutputStream( rOut );
1270 :
1271 248 : return sURL;
1272 : }
1273 :
1274 43 : OUString SvXMLImport::ResolveEmbeddedObjectURL(
1275 : const OUString& rURL,
1276 : const OUString& rClassId )
1277 : {
1278 43 : OUString sRet;
1279 :
1280 43 : if( IsPackageURL( rURL ) )
1281 : {
1282 43 : if ( mxEmbeddedResolver.is() )
1283 : {
1284 43 : OUString sURL( rURL );
1285 43 : if( !rClassId.isEmpty() )
1286 : {
1287 0 : sURL += "!" + rClassId;
1288 : }
1289 43 : sRet = mxEmbeddedResolver->resolveEmbeddedObjectURL( sURL );
1290 : }
1291 : }
1292 : else
1293 0 : sRet = GetAbsoluteReference( rURL );
1294 :
1295 43 : return sRet;
1296 : }
1297 :
1298 14 : Reference< embed::XStorage > SvXMLImport::GetSourceStorage()
1299 : {
1300 14 : return mpImpl->mxSourceStorage;
1301 : }
1302 :
1303 : Reference < XOutputStream >
1304 0 : SvXMLImport::GetStreamForEmbeddedObjectURLFromBase64()
1305 : {
1306 0 : Reference < XOutputStream > xOLEStream;
1307 :
1308 0 : if( mxEmbeddedResolver.is() )
1309 : {
1310 0 : Reference< XNameAccess > xNA( mxEmbeddedResolver, UNO_QUERY );
1311 0 : if( xNA.is() )
1312 : {
1313 0 : OUString aURL( "Obj12345678" );
1314 0 : Any aAny = xNA->getByName( aURL );
1315 0 : aAny >>= xOLEStream;
1316 0 : }
1317 : }
1318 :
1319 0 : return xOLEStream;
1320 : }
1321 :
1322 0 : OUString SvXMLImport::ResolveEmbeddedObjectURLFromBase64()
1323 : {
1324 0 : OUString sRet;
1325 :
1326 0 : if( mxEmbeddedResolver.is() )
1327 : {
1328 0 : OUString aURL( "Obj12345678" );
1329 0 : sRet = mxEmbeddedResolver->resolveEmbeddedObjectURL( aURL );
1330 : }
1331 :
1332 0 : return sRet;
1333 : }
1334 :
1335 964 : void SvXMLImport::AddStyleDisplayName( sal_uInt16 nFamily,
1336 : const OUString& rName,
1337 : const OUString& rDisplayName )
1338 : {
1339 964 : if( !mpStyleMap )
1340 : {
1341 196 : mpStyleMap = new StyleMap;
1342 196 : mpStyleMap->acquire();
1343 196 : if( mxImportInfo.is() )
1344 : {
1345 158 : OUString sPrivateData( "PrivateData" );
1346 : Reference< beans::XPropertySetInfo > xPropertySetInfo =
1347 316 : mxImportInfo->getPropertySetInfo();
1348 316 : if( xPropertySetInfo.is() &&
1349 158 : xPropertySetInfo->hasPropertyByName(sPrivateData) )
1350 : {
1351 : Reference < XInterface > xIfc(
1352 158 : static_cast< XUnoTunnel *>( mpStyleMap ) );
1353 316 : Any aAny;
1354 158 : aAny <<= xIfc;
1355 316 : mxImportInfo->setPropertyValue( sPrivateData, aAny );
1356 158 : }
1357 : }
1358 : }
1359 :
1360 964 : StyleMap::key_type aKey( nFamily, rName );
1361 1928 : StyleMap::value_type aValue( aKey, rDisplayName );
1362 964 : ::std::pair<StyleMap::iterator,bool> aRes( mpStyleMap->insert( aValue ) );
1363 : SAL_WARN_IF( !aRes.second,
1364 : "xmloff.core",
1365 964 : "duplicate style name" );
1366 :
1367 964 : }
1368 :
1369 10781 : OUString SvXMLImport::GetStyleDisplayName( sal_uInt16 nFamily,
1370 : const OUString& rName ) const
1371 : {
1372 10781 : OUString sName( rName );
1373 10781 : if( mpStyleMap && !rName.isEmpty() )
1374 : {
1375 6566 : StyleMap::key_type aKey( nFamily, rName );
1376 6566 : StyleMap::const_iterator aIter = mpStyleMap->find( aKey );
1377 6566 : if( aIter != mpStyleMap->end() )
1378 1611 : sName = (*aIter).second;
1379 : }
1380 10781 : return sName;
1381 : }
1382 :
1383 0 : void SvXMLImport::SetViewSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&)
1384 : {
1385 0 : }
1386 :
1387 0 : void SvXMLImport::SetConfigurationSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&)
1388 : {
1389 0 : }
1390 :
1391 0 : void SvXMLImport::SetDocumentSpecificSettings(const OUString& _rSettingsGroupName, const uno::Sequence<beans::PropertyValue>& _rSettings)
1392 : {
1393 : (void)_rSettingsGroupName;
1394 : (void)_rSettings;
1395 0 : }
1396 :
1397 5249 : ProgressBarHelper* SvXMLImport::GetProgressBarHelper()
1398 : {
1399 5249 : if (!mpProgressBarHelper)
1400 : {
1401 735 : mpProgressBarHelper = new ProgressBarHelper(mxStatusIndicator, false);
1402 :
1403 735 : if (mxImportInfo.is())
1404 : {
1405 678 : uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
1406 678 : if (xPropertySetInfo.is())
1407 : {
1408 678 : OUString sProgressRange(XML_PROGRESSRANGE);
1409 1356 : OUString sProgressMax(XML_PROGRESSMAX);
1410 1356 : OUString sProgressCurrent(XML_PROGRESSCURRENT);
1411 1356 : OUString sRepeat(XML_PROGRESSREPEAT);
1412 2016 : if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
1413 1338 : xPropertySetInfo->hasPropertyByName(sProgressCurrent) &&
1414 660 : xPropertySetInfo->hasPropertyByName(sProgressRange))
1415 : {
1416 660 : uno::Any aAny;
1417 660 : sal_Int32 nProgressMax(0);
1418 660 : sal_Int32 nProgressCurrent(0);
1419 660 : sal_Int32 nProgressRange(0);
1420 660 : aAny = mxImportInfo->getPropertyValue(sProgressRange);
1421 660 : if (aAny >>= nProgressRange)
1422 416 : mpProgressBarHelper->SetRange(nProgressRange);
1423 660 : aAny = mxImportInfo->getPropertyValue(sProgressMax);
1424 660 : if (aAny >>= nProgressMax)
1425 344 : mpProgressBarHelper->SetReference(nProgressMax);
1426 660 : aAny = mxImportInfo->getPropertyValue(sProgressCurrent);
1427 660 : if (aAny >>= nProgressCurrent)
1428 347 : mpProgressBarHelper->SetValue(nProgressCurrent);
1429 : }
1430 678 : if (xPropertySetInfo->hasPropertyByName(sRepeat))
1431 : {
1432 0 : uno::Any aAny = mxImportInfo->getPropertyValue(sRepeat);
1433 0 : if (aAny.getValueType() == getBooleanCppuType())
1434 0 : mpProgressBarHelper->SetRepeat(::cppu::any2bool(aAny));
1435 : else {
1436 : SAL_WARN( "xmloff.core", "why is it no boolean?" );
1437 0 : }
1438 678 : }
1439 678 : }
1440 : }
1441 : }
1442 5249 : return mpProgressBarHelper;
1443 : }
1444 :
1445 739 : void SvXMLImport::AddNumberStyle(sal_Int32 nKey, const OUString& rName)
1446 : {
1447 739 : if (!mxNumberStyles.is())
1448 195 : mxNumberStyles = uno::Reference< container::XNameContainer >( comphelper::NameContainer_createInstance( ::getCppuType((const sal_Int32*)0)) );
1449 739 : if (mxNumberStyles.is())
1450 : {
1451 739 : uno::Any aAny;
1452 739 : aAny <<= nKey;
1453 : try
1454 : {
1455 739 : mxNumberStyles->insertByName(rName, aAny);
1456 : }
1457 0 : catch ( uno::Exception& )
1458 : {
1459 : SAL_WARN( "xmloff.core", "Numberformat could not be inserted");
1460 : DBG_UNHANDLED_EXCEPTION();
1461 739 : }
1462 : }
1463 : else {
1464 : SAL_WARN( "xmloff.core", "not possible to create NameContainer");
1465 : DBG_UNHANDLED_EXCEPTION();
1466 : }
1467 739 : }
1468 :
1469 36 : XMLEventImportHelper& SvXMLImport::GetEventImport()
1470 : {
1471 36 : if (!mpEventImportHelper)
1472 : {
1473 : // construct event helper and register StarBasic handler and standard
1474 : // event tables
1475 10 : mpEventImportHelper = new XMLEventImportHelper();
1476 10 : OUString sStarBasic(GetXMLToken(XML_STARBASIC));
1477 : mpEventImportHelper->RegisterFactory(sStarBasic,
1478 10 : new XMLStarBasicContextFactory());
1479 20 : OUString sScript(GetXMLToken(XML_SCRIPT));
1480 : mpEventImportHelper->RegisterFactory(sScript,
1481 10 : new XMLScriptContextFactory());
1482 10 : mpEventImportHelper->AddTranslationTable(aStandardEventTable);
1483 :
1484 : // register StarBasic event handler with capitalized spelling
1485 20 : OUString sStarBasicCap( "StarBasic" );
1486 : mpEventImportHelper->RegisterFactory(sStarBasicCap,
1487 20 : new XMLStarBasicContextFactory());
1488 : }
1489 :
1490 36 : return *mpEventImportHelper;
1491 : }
1492 :
1493 520 : void SvXMLImport::SetFontDecls( XMLFontStylesContext *pFontDecls )
1494 : {
1495 520 : mxFontDecls = pFontDecls;
1496 520 : }
1497 :
1498 259 : void SvXMLImport::SetStyles( SvXMLStylesContext *pStyles )
1499 : {
1500 259 : mxStyles = pStyles;
1501 259 : }
1502 :
1503 575 : void SvXMLImport::SetAutoStyles( SvXMLStylesContext *pAutoStyles )
1504 : {
1505 575 : if (pAutoStyles && mxNumberStyles.is() && (mnImportFlags & IMPORT_CONTENT) )
1506 : {
1507 107 : uno::Reference<xml::sax::XAttributeList> xAttrList;
1508 214 : uno::Sequence< OUString > aNames = mxNumberStyles->getElementNames();
1509 107 : sal_uInt32 nCount(aNames.getLength());
1510 107 : if (nCount)
1511 : {
1512 107 : const OUString* pNames = aNames.getConstArray();
1513 107 : if ( pNames )
1514 : {
1515 : SvXMLStyleContext* pContext;
1516 107 : uno::Any aAny;
1517 107 : sal_Int32 nKey(0);
1518 646 : for (sal_uInt32 i = 0; i < nCount; i++, pNames++)
1519 : {
1520 539 : aAny = mxNumberStyles->getByName(*pNames);
1521 539 : if (aAny >>= nKey)
1522 : {
1523 : pContext = new SvXMLNumFormatContext( *this, XML_NAMESPACE_NUMBER,
1524 539 : *pNames, xAttrList, nKey, *pAutoStyles );
1525 539 : pAutoStyles->AddStyle(*pContext);
1526 : }
1527 107 : }
1528 : }
1529 107 : }
1530 : }
1531 575 : mxAutoStyles = pAutoStyles;
1532 575 : GetTextImport()->SetAutoStyles( pAutoStyles );
1533 575 : GetShapeImport()->SetAutoStylesContext( pAutoStyles );
1534 575 : GetChartImport()->SetAutoStylesContext( pAutoStyles );
1535 575 : GetFormImport()->setAutoStyleContext( pAutoStyles );
1536 575 : }
1537 :
1538 151 : void SvXMLImport::SetMasterStyles( SvXMLStylesContext *pMasterStyles )
1539 : {
1540 151 : mxMasterStyles = pMasterStyles;
1541 151 : }
1542 :
1543 7671 : XMLFontStylesContext *SvXMLImport::GetFontDecls()
1544 : {
1545 7671 : return (XMLFontStylesContext *)&mxFontDecls;
1546 : }
1547 :
1548 826 : SvXMLStylesContext *SvXMLImport::GetStyles()
1549 : {
1550 826 : return (SvXMLStylesContext *)&mxStyles;
1551 : }
1552 :
1553 5241 : SvXMLStylesContext *SvXMLImport::GetAutoStyles()
1554 : {
1555 5241 : return (SvXMLStylesContext *)&mxAutoStyles;
1556 : }
1557 :
1558 0 : const XMLFontStylesContext *SvXMLImport::GetFontDecls() const
1559 : {
1560 0 : return (const XMLFontStylesContext *)&mxFontDecls;
1561 : }
1562 :
1563 0 : const SvXMLStylesContext *SvXMLImport::GetStyles() const
1564 : {
1565 0 : return (const SvXMLStylesContext *)&mxStyles;
1566 : }
1567 :
1568 1308 : const SvXMLStylesContext *SvXMLImport::GetAutoStyles() const
1569 : {
1570 1308 : return (const SvXMLStylesContext *)&mxAutoStyles;
1571 : }
1572 :
1573 735 : OUString SvXMLImport::GetAbsoluteReference(const OUString& rValue) const
1574 : {
1575 735 : if( rValue.isEmpty() || rValue[0] == '#' )
1576 643 : return rValue;
1577 :
1578 92 : INetURLObject aAbsURL;
1579 92 : if( mpImpl->aBaseURL.GetNewAbsURL( rValue, &aAbsURL ) )
1580 92 : return aAbsURL.GetMainURL( INetURLObject::DECODE_TO_IURI );
1581 : else
1582 0 : return rValue;
1583 : }
1584 :
1585 345 : bool SvXMLImport::IsODFVersionConsistent( const OUString& aODFVersion )
1586 : {
1587 : // the check returns sal_False only if the storage version could be retrieved
1588 345 : bool bResult = true;
1589 :
1590 345 : if ( !aODFVersion.isEmpty() && aODFVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
1591 : {
1592 : // check the consistency only for the ODF1.2 and later ( according to content.xml )
1593 : // manifest.xml might have no version, it should be checked here and the correct version should be set
1594 : try
1595 : {
1596 337 : uno::Reference< document::XStorageBasedDocument > xDoc( mxModel, uno::UNO_QUERY_THROW );
1597 646 : uno::Reference< embed::XStorage > xStor = xDoc->getDocumentStorage();
1598 538 : uno::Reference< beans::XPropertySet > xStorProps( xStor, uno::UNO_QUERY_THROW );
1599 :
1600 : // the check should be done only for OASIS format
1601 229 : if (!IsOOoXML())
1602 : {
1603 228 : sal_Bool bRepairPackage = sal_False;
1604 : try
1605 : {
1606 228 : xStorProps->getPropertyValue( "RepairPackage" )
1607 228 : >>= bRepairPackage;
1608 0 : } catch ( uno::Exception& )
1609 : {}
1610 :
1611 : // check only if not in Repair mode
1612 228 : if ( !bRepairPackage )
1613 : {
1614 228 : OUString aStorVersion;
1615 228 : xStorProps->getPropertyValue( "Version" )
1616 228 : >>= aStorVersion;
1617 :
1618 : // if the storage version is set in manifest.xml, it must be the same as in content.xml
1619 : // if not, set it explicitly to be used further ( it will work even for readonly storage )
1620 : // This workaround is not nice, but I see no other way to handle it, since there are
1621 : // ODF1.2 documents without version in manifest.xml
1622 228 : if ( !aStorVersion.isEmpty() )
1623 227 : bResult = aODFVersion.equals( aStorVersion );
1624 : else
1625 1 : xStorProps->setPropertyValue( "Version",
1626 1 : uno::makeAny( aODFVersion ) );
1627 :
1628 228 : if ( bResult )
1629 : {
1630 228 : sal_Bool bInconsistent = sal_False;
1631 228 : xStorProps->getPropertyValue( "IsInconsistent" )
1632 228 : >>= bInconsistent;
1633 228 : bResult = !bInconsistent;
1634 228 : }
1635 : }
1636 337 : }
1637 : }
1638 108 : catch( uno::Exception& )
1639 : {}
1640 : }
1641 :
1642 345 : return bResult;
1643 : }
1644 :
1645 1363 : void SvXMLImport::_CreateNumberFormatsSupplier()
1646 : {
1647 : SAL_WARN_IF( mxNumberFormatsSupplier.is(), "xmloff.core", "number formats supplier already exists!" );
1648 1363 : if(mxModel.is())
1649 2726 : mxNumberFormatsSupplier =
1650 1363 : uno::Reference< util::XNumberFormatsSupplier> (mxModel, uno::UNO_QUERY);
1651 1363 : }
1652 :
1653 1372 : void SvXMLImport::_CreateDataStylesImport()
1654 : {
1655 : SAL_WARN_IF( mpNumImport != NULL, "xmloff.core", "data styles import already exists!" );
1656 : uno::Reference<util::XNumberFormatsSupplier> xNum =
1657 1372 : GetNumberFormatsSupplier();
1658 1372 : if ( xNum.is() )
1659 564 : mpNumImport = new SvXMLNumFmtHelper(xNum, GetComponentContext() );
1660 1372 : }
1661 :
1662 0 : sal_Unicode SvXMLImport::ConvStarBatsCharToStarSymbol( sal_Unicode c )
1663 : {
1664 0 : sal_Unicode cNew = c;
1665 0 : if( !mpImpl->hBatsFontConv )
1666 : {
1667 0 : OUString sStarBats( "StarBats" );
1668 : mpImpl->hBatsFontConv = CreateFontToSubsFontConverter( sStarBats,
1669 0 : FONTTOSUBSFONT_IMPORT|FONTTOSUBSFONT_ONLYOLDSOSYMBOLFONTS );
1670 0 : SAL_WARN_IF( !mpImpl->hBatsFontConv, "xmloff.core", "Got no symbol font converter" );
1671 : }
1672 0 : if( mpImpl->hBatsFontConv )
1673 : {
1674 0 : cNew = ConvertFontToSubsFontChar( mpImpl->hBatsFontConv, c );
1675 : }
1676 :
1677 0 : return cNew;
1678 : }
1679 :
1680 0 : sal_Unicode SvXMLImport::ConvStarMathCharToStarSymbol( sal_Unicode c )
1681 : {
1682 0 : sal_Unicode cNew = c;
1683 0 : if( !mpImpl->hMathFontConv )
1684 : {
1685 0 : OUString sStarMath( "StarMath" );
1686 : mpImpl->hMathFontConv = CreateFontToSubsFontConverter( sStarMath,
1687 0 : FONTTOSUBSFONT_IMPORT|FONTTOSUBSFONT_ONLYOLDSOSYMBOLFONTS );
1688 0 : SAL_WARN_IF( !mpImpl->hMathFontConv, "xmloff.core", "Got no symbol font converter" );
1689 : }
1690 0 : if( mpImpl->hMathFontConv )
1691 : {
1692 0 : cNew = ConvertFontToSubsFontChar( mpImpl->hMathFontConv, c );
1693 : }
1694 :
1695 0 : return cNew;
1696 : }
1697 :
1698 100 : void SvXMLImport::SetError(
1699 : sal_Int32 nId,
1700 : const Sequence<OUString>& rMsgParams,
1701 : const OUString& rExceptionMessage,
1702 : const Reference<xml::sax::XLocator>& rLocator )
1703 : {
1704 : // maintain error flags
1705 100 : if ( ( nId & XMLERROR_FLAG_ERROR ) != 0 )
1706 64 : mnErrorFlags |= ERROR_ERROR_OCCURRED;
1707 100 : if ( ( nId & XMLERROR_FLAG_WARNING ) != 0 )
1708 36 : mnErrorFlags |= ERROR_WARNING_OCCURRED;
1709 100 : if ( ( nId & XMLERROR_FLAG_SEVERE ) != 0 )
1710 0 : mnErrorFlags |= ERROR_DO_NOTHING;
1711 :
1712 : // create error list on demand
1713 100 : if ( mpXMLErrors == NULL )
1714 10 : mpXMLErrors = new XMLErrors();
1715 :
1716 : // save error information
1717 : // use document locator (if none supplied)
1718 : mpXMLErrors->AddRecord( nId, rMsgParams, rExceptionMessage,
1719 100 : rLocator.is() ? rLocator : mxLocator );
1720 100 : }
1721 :
1722 18 : void SvXMLImport::SetError(
1723 : sal_Int32 nId,
1724 : const Sequence<OUString>& rMsgParams)
1725 : {
1726 18 : OUString sEmpty;
1727 18 : SetError( nId, rMsgParams, sEmpty, NULL );
1728 18 : }
1729 :
1730 0 : void SvXMLImport::SetError(
1731 : sal_Int32 nId)
1732 : {
1733 0 : Sequence<OUString> aSeq(0);
1734 0 : SetError( nId, aSeq );
1735 0 : }
1736 :
1737 0 : void SvXMLImport::SetError(
1738 : sal_Int32 nId,
1739 : const OUString& rMsg1)
1740 : {
1741 0 : Sequence<OUString> aSeq(1);
1742 0 : OUString* pSeq = aSeq.getArray();
1743 0 : pSeq[0] = rMsg1;
1744 0 : SetError( nId, aSeq );
1745 0 : }
1746 :
1747 0 : void SvXMLImport::SetError(
1748 : sal_Int32 nId,
1749 : const OUString& rMsg1,
1750 : const OUString& rMsg2)
1751 : {
1752 0 : Sequence<OUString> aSeq(2);
1753 0 : OUString* pSeq = aSeq.getArray();
1754 0 : pSeq[0] = rMsg1;
1755 0 : pSeq[1] = rMsg2;
1756 0 : SetError( nId, aSeq );
1757 0 : }
1758 :
1759 8 : void SvXMLImport::DisposingModel()
1760 : {
1761 8 : if( mxFontDecls.Is() )
1762 0 : ((SvXMLStylesContext *)&mxFontDecls)->Clear();
1763 8 : if( mxStyles.Is() )
1764 1 : ((SvXMLStylesContext *)&mxStyles)->Clear();
1765 8 : if( mxAutoStyles.Is() )
1766 0 : ((SvXMLStylesContext *)&mxAutoStyles)->Clear();
1767 8 : if( mxMasterStyles.Is() )
1768 0 : ((SvXMLStylesContext *)&mxMasterStyles)->Clear();
1769 :
1770 8 : mxModel.set(0);
1771 8 : mxEventListener.set(NULL);
1772 8 : }
1773 :
1774 24 : ::comphelper::UnoInterfaceToUniqueIdentifierMapper& SvXMLImport::getInterfaceToIdentifierMapper()
1775 : {
1776 24 : return mpImpl->maInterfaceToIdentifierMapper;
1777 : }
1778 :
1779 : uno::Reference< uno::XComponentContext >
1780 2689 : SvXMLImport::GetComponentContext() const
1781 : {
1782 2689 : return mpImpl->mxComponentContext;
1783 : }
1784 :
1785 1 : OUString SvXMLImport::GetBaseURL() const
1786 : {
1787 1 : return mpImpl->aBaseURL.GetMainURL( INetURLObject::NO_DECODE );
1788 : }
1789 :
1790 30 : OUString SvXMLImport::GetDocumentBase() const
1791 : {
1792 30 : return mpImpl->aDocBase.GetMainURL( INetURLObject::NO_DECODE );
1793 : }
1794 :
1795 94 : OUString SvXMLImport::GetStreamName() const
1796 : {
1797 94 : return mpImpl->mStreamName;
1798 : }
1799 :
1800 : // Convert drawing object positions from OOo file format to OASIS (#i28749#)
1801 576 : bool SvXMLImport::IsShapePositionInHoriL2R() const
1802 : {
1803 576 : return mpImpl->mbShapePositionInHoriL2R;
1804 : }
1805 :
1806 183 : bool SvXMLImport::IsTextDocInOOoFileFormat() const
1807 : {
1808 183 : return mpImpl->mbTextDocInOOoFileFormat;
1809 : }
1810 :
1811 0 : void SvXMLImport::initXForms()
1812 : {
1813 : // dummy method; to be implemented by derived classes supporting XForms
1814 0 : }
1815 :
1816 1772 : bool SvXMLImport::getBuildIds( sal_Int32& rUPD, sal_Int32& rBuild ) const
1817 : {
1818 1772 : bool bRet = false;
1819 1772 : OUString const aBuildId(getBuildIdsProperty(mxImportInfo));
1820 1772 : if (!aBuildId.isEmpty())
1821 : {
1822 1036 : sal_Int32 nIndex = aBuildId.indexOf('$');
1823 1036 : if (nIndex != -1)
1824 : {
1825 489 : rUPD = aBuildId.copy( 0, nIndex ).toInt32();
1826 489 : sal_Int32 nIndexEnd = aBuildId.indexOf(';', nIndex);
1827 : rBuild = (nIndexEnd == -1)
1828 683 : ? aBuildId.copy(nIndex + 1).toInt32()
1829 978 : : aBuildId.copy(nIndex + 1, nIndexEnd - nIndex - 1).toInt32();
1830 489 : bRet = true;
1831 : }
1832 : }
1833 1772 : return bRet;
1834 : }
1835 :
1836 530 : sal_uInt16 SvXMLImport::getGeneratorVersion() const
1837 : {
1838 : // --> ORW
1839 530 : return mpImpl->getGeneratorVersion( *this );
1840 : // <--
1841 : }
1842 :
1843 192 : bool SvXMLImport::isGeneratorVersionOlderThan(
1844 : sal_uInt16 const nOOoVersion, sal_uInt16 const nLOVersion)
1845 : {
1846 : assert( (nLOVersion & LO_flag));
1847 : assert(!(nOOoVersion & LO_flag));
1848 192 : const sal_uInt16 nGeneratorVersion(getGeneratorVersion());
1849 192 : return (nGeneratorVersion & LO_flag)
1850 : ? nGeneratorVersion < nLOVersion
1851 192 : : nGeneratorVersion < nOOoVersion;
1852 : }
1853 :
1854 10 : bool SvXMLImport::isGraphicLoadOnDemandSupported() const
1855 : {
1856 10 : return mbIsGraphicLoadOnDemandSupported;
1857 : }
1858 :
1859 190 : OUString SvXMLImport::GetODFVersion() const
1860 : {
1861 190 : return mpImpl->aODFVersion;
1862 : }
1863 :
1864 386 : bool SvXMLImport::IsOOoXML() const
1865 : {
1866 386 : return mpImpl->mbIsOOoXML;
1867 : }
1868 :
1869 : // xml:id for RDF metadata
1870 1132 : void SvXMLImport::SetXmlId(uno::Reference<uno::XInterface> const & i_xIfc,
1871 : OUString const & i_rXmlId)
1872 : {
1873 1132 : if (!i_rXmlId.isEmpty()) {
1874 : try {
1875 : const uno::Reference<rdf::XMetadatable> xMeta(i_xIfc,
1876 94 : uno::UNO_QUERY);
1877 : //FIXME: not yet
1878 94 : if (xMeta.is()) {
1879 94 : const beans::StringPair mdref( GetStreamName(), i_rXmlId );
1880 : try {
1881 94 : xMeta->setMetadataReference(mdref);
1882 0 : } catch (lang::IllegalArgumentException &) {
1883 : // probably duplicate; ignore
1884 : SAL_INFO("xmloff.core", "SvXMLImport::SetXmlId: cannot set xml:id");
1885 94 : }
1886 94 : }
1887 0 : } catch (uno::Exception &) {
1888 : SAL_WARN("xmloff.core","SvXMLImport::SetXmlId: exception?");
1889 : }
1890 : }
1891 1132 : }
1892 :
1893 : ::xmloff::RDFaImportHelper &
1894 44 : SvXMLImport::GetRDFaImportHelper()
1895 : {
1896 44 : if (!mpImpl->mpRDFaHelper.get())
1897 : {
1898 6 : mpImpl->mpRDFaHelper.reset( new ::xmloff::RDFaImportHelper(*this) );
1899 : }
1900 44 : return *mpImpl->mpRDFaHelper;
1901 : }
1902 :
1903 : void
1904 36 : SvXMLImport::AddRDFa(uno::Reference<rdf::XMetadatable> i_xObject,
1905 : OUString const & i_rAbout,
1906 : OUString const & i_rProperty,
1907 : OUString const & i_rContent,
1908 : OUString const & i_rDatatype)
1909 : {
1910 : // N.B.: we only get called if i_xObject had xhtml:about attribute
1911 : // (an empty attribute value is valid)
1912 36 : ::xmloff::RDFaImportHelper & rRDFaHelper( GetRDFaImportHelper() );
1913 : rRDFaHelper.ParseAndAddRDFa(i_xObject,
1914 36 : i_rAbout, i_rProperty, i_rContent, i_rDatatype);
1915 36 : }
1916 :
1917 0 : bool SvXMLImport::embeddedFontAlreadyProcessed( const OUString& url )
1918 : {
1919 0 : if( embeddedFontUrlsKnown.count( url ) != 0 )
1920 0 : return true;
1921 0 : embeddedFontUrlsKnown.insert( url );
1922 0 : return false;
1923 : }
1924 :
1925 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|