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 <rsc/rscsfx.hxx>
21 : #include <sfx2/docfile.hxx>
22 : #include <sfx2/objsh.hxx>
23 : #include <osl/diagnose.h>
24 : #include <comphelper/processfactory.hxx>
25 : #include <unotools/streamwrap.hxx>
26 : #include <svx/xmlgrhlp.hxx>
27 : #include <svtools/sfxecode.hxx>
28 : #include <sfx2/frame.hxx>
29 : #include <svl/itemset.hxx>
30 : #include <svl/stritem.hxx>
31 : #include <sfx2/sfxsids.hrc>
32 : #include <com/sun/star/container/XChild.hpp>
33 : #include <com/sun/star/beans/XPropertySetInfo.hpp>
34 : #include <com/sun/star/xml/sax/XErrorHandler.hpp>
35 : #include <com/sun/star/xml/sax/XEntityResolver.hpp>
36 : #include <com/sun/star/xml/sax/InputSource.hpp>
37 : #include <com/sun/star/xml/sax/XDTDHandler.hpp>
38 : #include <com/sun/star/xml/sax/Parser.hpp>
39 : #include <com/sun/star/xml/sax/Writer.hpp>
40 : #include <com/sun/star/io/XActiveDataSource.hpp>
41 : #include <com/sun/star/io/XActiveDataControl.hpp>
42 : #include <com/sun/star/frame/XModel.hpp>
43 : #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
44 : #include <com/sun/star/beans/PropertyAttribute.hpp>
45 : #include <comphelper/extract.hxx>
46 : #include <comphelper/propertysetinfo.hxx>
47 : #include <comphelper/genericpropertyset.hxx>
48 : #include <com/sun/star/container/XNameContainer.hpp>
49 : #include <com/sun/star/lang/DisposedException.hpp>
50 : #include <com/sun/star/packages/zip/ZipIOException.hpp>
51 : #include <com/sun/star/embed/ElementModes.hpp>
52 : #include <com/sun/star/script/vba/XVBACompatibility.hpp>
53 :
54 : #include <svx/xmleohlp.hxx>
55 : #include <rtl/logfile.hxx>
56 : #include <rtl/strbuf.hxx>
57 : #include <unotools/saveopt.hxx>
58 :
59 : #include "document.hxx"
60 : #include "xmlwrap.hxx"
61 : #include "xmlimprt.hxx"
62 : #include "xmlexprt.hxx"
63 : #include "global.hxx"
64 : #include "globstr.hrc"
65 : #include "scerrors.hxx"
66 : #include "XMLExportSharedData.hxx"
67 : #include "docuno.hxx"
68 : #include "sheetdata.hxx"
69 : #include "XMLCodeNameProvider.hxx"
70 :
71 : #define MAP_LEN(x) x, sizeof(x) - 1
72 :
73 : using namespace com::sun::star;
74 : using ::rtl::OUString;
75 :
76 : using rtl::OUString;
77 :
78 : // -----------------------------------------------------------------------
79 :
80 24 : ScXMLImportWrapper::ScXMLImportWrapper(ScDocument& rD, SfxMedium* pM, const uno::Reference < embed::XStorage >& xStor ) :
81 : rDoc(rD),
82 : pMedium(pM),
83 24 : xStorage(xStor)
84 : {
85 : OSL_ENSURE( pMedium || xStorage.is(), "ScXMLImportWrapper: Medium or Storage must be set" );
86 24 : }
87 :
88 24 : uno::Reference <task::XStatusIndicator> ScXMLImportWrapper::GetStatusIndicator()
89 : {
90 24 : uno::Reference<task::XStatusIndicator> xStatusIndicator;
91 24 : if (pMedium)
92 : {
93 24 : SfxItemSet* pSet = pMedium->GetItemSet();
94 24 : if (pSet)
95 : {
96 24 : const SfxUnoAnyItem* pItem = static_cast<const SfxUnoAnyItem*>(pSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL));
97 24 : if (pItem)
98 0 : xStatusIndicator.set(pItem->GetValue(), uno::UNO_QUERY);
99 : }
100 : }
101 24 : return xStatusIndicator;
102 : }
103 :
104 88 : sal_uInt32 ScXMLImportWrapper::ImportFromComponent(uno::Reference<lang::XMultiServiceFactory>& xServiceFactory,
105 : uno::Reference<frame::XModel>& xModel, uno::Reference<xml::sax::XParser>& xParser,
106 : xml::sax::InputSource& aParserInput,
107 : const rtl::OUString& sComponentName, const rtl::OUString& sDocName,
108 : const rtl::OUString& sOldDocName, uno::Sequence<uno::Any>& aArgs,
109 : sal_Bool bMustBeSuccessfull)
110 : {
111 88 : uno::Reference < io::XStream > xDocStream;
112 88 : if ( !xStorage.is() && pMedium )
113 0 : xStorage = pMedium->GetStorage();
114 :
115 88 : sal_Bool bEncrypted = false;
116 88 : rtl::OUString sStream(sDocName);
117 88 : if( xStorage.is() )
118 : {
119 : try
120 : {
121 88 : uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
122 88 : if ( xAccess->hasByName(sDocName) && xStorage->isStreamElement( sDocName) )
123 88 : xDocStream = xStorage->openStreamElement( sDocName, embed::ElementModes::READ );
124 0 : else if (!sOldDocName.isEmpty() && xAccess->hasByName(sOldDocName) && xStorage->isStreamElement( sOldDocName) )
125 : {
126 0 : xDocStream = xStorage->openStreamElement( sOldDocName, embed::ElementModes::READ );
127 0 : sStream = sOldDocName;
128 : }
129 : else
130 0 : return SCERR_NONE;
131 :
132 88 : aParserInput.aInputStream = xDocStream->getInputStream();
133 88 : uno::Reference < beans::XPropertySet > xSet( xDocStream, uno::UNO_QUERY );
134 :
135 88 : uno::Any aAny = xSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Encrypted") ) );
136 88 : aAny >>= bEncrypted;
137 : }
138 0 : catch( packages::WrongPasswordException& )
139 : {
140 0 : return ERRCODE_SFX_WRONGPASSWORD;
141 : }
142 0 : catch( packages::zip::ZipIOException& )
143 : {
144 0 : return ERRCODE_IO_BROKENPACKAGE;
145 : }
146 0 : catch( uno::Exception& )
147 : {
148 0 : return SCERR_IMPORT_UNKNOWN;
149 : }
150 : }
151 : else
152 0 : return SCERR_IMPORT_UNKNOWN;
153 :
154 : // set Base URL
155 88 : uno::Reference< beans::XPropertySet > xInfoSet;
156 88 : if( aArgs.getLength() > 0 )
157 88 : aArgs.getConstArray()[0] >>= xInfoSet;
158 : OSL_ENSURE( xInfoSet.is(), "missing property set" );
159 88 : if( xInfoSet.is() )
160 : {
161 88 : rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("StreamName") );
162 88 : xInfoSet->setPropertyValue( sPropName, uno::makeAny( sStream ) );
163 : }
164 :
165 88 : sal_uInt32 nReturn = SCERR_NONE;
166 88 : rDoc.SetRangeOverflowType(0); // is modified by the importer if limits are exceeded
167 :
168 : uno::Reference<xml::sax::XDocumentHandler> xDocHandler(
169 88 : xServiceFactory->createInstanceWithArguments(
170 88 : sComponentName, aArgs ),
171 88 : uno::UNO_QUERY );
172 : OSL_ENSURE( xDocHandler.is(), "can't get Calc importer" );
173 88 : uno::Reference<document::XImporter> xImporter( xDocHandler, uno::UNO_QUERY );
174 88 : uno::Reference<lang::XComponent> xComponent( xModel, uno::UNO_QUERY );
175 88 : if (xImporter.is())
176 88 : xImporter->setTargetDocument( xComponent );
177 :
178 : // connect parser and filter
179 88 : xParser->setDocumentHandler( xDocHandler );
180 :
181 : try
182 : {
183 88 : xParser->parseStream( aParserInput );
184 : }
185 0 : catch( xml::sax::SAXParseException& r )
186 : {
187 : // sax parser sends wrapped exceptions,
188 : // try to find the original one
189 0 : xml::sax::SAXException aSaxEx = *(xml::sax::SAXException*)(&r);
190 0 : sal_Bool bTryChild = sal_True;
191 :
192 0 : while( bTryChild )
193 : {
194 0 : xml::sax::SAXException aTmp;
195 0 : if ( aSaxEx.WrappedException >>= aTmp )
196 0 : aSaxEx = aTmp;
197 : else
198 0 : bTryChild = false;
199 0 : }
200 :
201 0 : packages::zip::ZipIOException aBrokenPackage;
202 0 : if ( aSaxEx.WrappedException >>= aBrokenPackage )
203 0 : return ERRCODE_IO_BROKENPACKAGE;
204 0 : else if( bEncrypted )
205 0 : nReturn = ERRCODE_SFX_WRONGPASSWORD;
206 : else
207 : {
208 :
209 : #if OSL_DEBUG_LEVEL > 0
210 : rtl::OStringBuffer aError(RTL_CONSTASCII_STRINGPARAM(
211 : "SAX parse exception catched while importing:\n"));
212 : aError.append(rtl::OUStringToOString(r.Message, RTL_TEXTENCODING_ASCII_US));
213 : OSL_FAIL(aError.getStr());
214 : #endif
215 :
216 0 : String sErr( String::CreateFromInt32( r.LineNumber ));
217 0 : sErr += ',';
218 0 : sErr += String::CreateFromInt32( r.ColumnNumber );
219 :
220 0 : if( !sDocName.isEmpty() )
221 : {
222 : nReturn = *new TwoStringErrorInfo(
223 : (bMustBeSuccessfull ? SCERR_IMPORT_FILE_ROWCOL
224 : : SCWARN_IMPORT_FILE_ROWCOL),
225 : sDocName, sErr,
226 0 : ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR );
227 : }
228 : else
229 : {
230 : OSL_ENSURE( bMustBeSuccessfull, "Warnings are not supported" );
231 : nReturn = *new StringErrorInfo( SCERR_IMPORT_FORMAT_ROWCOL, sErr,
232 0 : ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR );
233 0 : }
234 0 : }
235 : }
236 0 : catch( const xml::sax::SAXException& r )
237 : {
238 0 : packages::zip::ZipIOException aBrokenPackage;
239 0 : if ( r.WrappedException >>= aBrokenPackage )
240 0 : return ERRCODE_IO_BROKENPACKAGE;
241 0 : else if( bEncrypted )
242 0 : nReturn = ERRCODE_SFX_WRONGPASSWORD;
243 : else
244 : {
245 :
246 : #if OSL_DEBUG_LEVEL > 0
247 : rtl::OStringBuffer aError(RTL_CONSTASCII_STRINGPARAM(
248 : "SAX exception catched while importing:\n"));
249 : aError.append(rtl::OUStringToOString(r.Message,
250 : RTL_TEXTENCODING_ASCII_US));
251 : OSL_FAIL(aError.getStr());
252 : #endif
253 : (void)r; // avoid warning in product version
254 :
255 0 : nReturn = SCERR_IMPORT_FORMAT;
256 0 : }
257 : }
258 0 : catch( const packages::zip::ZipIOException& r )
259 : {
260 : #if OSL_DEBUG_LEVEL > 0
261 : rtl::OStringBuffer aError(RTL_CONSTASCII_STRINGPARAM(
262 : "Zip exception catched while importing:\n"));
263 : aError.append(rtl::OUStringToOString(r.Message,
264 : RTL_TEXTENCODING_ASCII_US));
265 : OSL_FAIL( aError.getStr() );
266 : #endif
267 : (void)r; // avoid warning in product version
268 :
269 0 : nReturn = ERRCODE_IO_BROKENPACKAGE;
270 : }
271 0 : catch( const io::IOException& r )
272 : {
273 : #if OSL_DEBUG_LEVEL > 0
274 : rtl::OStringBuffer aError(RTL_CONSTASCII_STRINGPARAM(
275 : "IO exception catched while importing:\n"));
276 : aError.append(rtl::OUStringToOString(r.Message,
277 : RTL_TEXTENCODING_ASCII_US));
278 : OSL_FAIL(aError.getStr());
279 : #endif
280 : (void)r; // avoid warning in product version
281 :
282 0 : nReturn = SCERR_IMPORT_OPEN;
283 : }
284 0 : catch( const uno::Exception& r )
285 : {
286 : #if OSL_DEBUG_LEVEL > 0
287 : rtl::OStringBuffer aError(RTL_CONSTASCII_STRINGPARAM(
288 : "uno exception catched while importing:\n"));
289 : aError.append(rtl::OUStringToOString(r.Message,
290 : RTL_TEXTENCODING_ASCII_US));
291 : OSL_FAIL(aError.getStr());
292 : #endif
293 : (void)r; // avoid warning in product version
294 :
295 0 : nReturn = SCERR_IMPORT_UNKNOWN;
296 : }
297 :
298 : // #i31130# Can't use getImplementation here to get the ScXMLImport from xDocHandler,
299 : // because when OOo 1.x files are loaded, xDocHandler is the OOo2OasisTransformer.
300 : // So the overflow warning ErrorCode is now stored in the document.
301 : // Export works differently, there getImplementation still works.
302 :
303 88 : if (rDoc.HasRangeOverflow() && !nReturn)
304 0 : nReturn = rDoc.GetRangeOverflowType();
305 :
306 : // free the component
307 88 : xParser->setDocumentHandler( NULL );
308 :
309 : // success!
310 88 : return nReturn;
311 : }
312 :
313 22 : sal_Bool ScXMLImportWrapper::Import(sal_Bool bStylesOnly, ErrCode& nError)
314 : {
315 : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "sb99857", "ScXMLImportWrapper::Import" );
316 :
317 : uno::Reference<lang::XMultiServiceFactory> xServiceFactory =
318 22 : comphelper::getProcessServiceFactory();
319 22 : uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
320 : OSL_ENSURE( xServiceFactory.is(), "got no service manager" );
321 22 : if( !xServiceFactory.is() )
322 0 : return false;
323 :
324 22 : xml::sax::InputSource aParserInput;
325 22 : if (pMedium)
326 22 : aParserInput.sSystemId = pMedium->GetName();
327 :
328 22 : if ( !xStorage.is() && pMedium )
329 22 : xStorage = pMedium->GetStorage();
330 :
331 : // get parser
332 22 : uno::Reference<xml::sax::XParser> xXMLParser = xml::sax::Parser::create(xContext);
333 :
334 : // get filter
335 22 : SfxObjectShell* pObjSh = rDoc.GetDocumentShell();
336 22 : if ( pObjSh )
337 : {
338 22 : rtl::OUString sEmpty;
339 22 : uno::Reference<frame::XModel> xModel(pObjSh->GetModel());
340 :
341 : /** property map for export info set */
342 : comphelper::PropertyMapEntry aImportInfoMap[] =
343 : {
344 22 : { MAP_LEN( "ProgressRange" ), 0, &::getCppuType((sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
345 22 : { MAP_LEN( "ProgressMax" ), 0, &::getCppuType((sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
346 22 : { MAP_LEN( "ProgressCurrent" ), 0, &::getCppuType((sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
347 22 : { MAP_LEN( "NumberStyles" ), 0, &::getCppuType((uno::Reference<container::XNameAccess> *)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
348 22 : { MAP_LEN( "PrivateData" ), 0, &::getCppuType( (uno::Reference<uno::XInterface> *)0 ), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
349 22 : { MAP_LEN( "BaseURI" ), 0, &::getCppuType( (rtl::OUString *)0 ), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
350 22 : { MAP_LEN( "StreamRelPath" ), 0, &::getCppuType( (rtl::OUString *)0 ), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
351 22 : { MAP_LEN( "StreamName" ), 0, &::getCppuType( (rtl::OUString *)0 ), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
352 22 : { MAP_LEN( "BuildId" ), 0, &::getCppuType( (OUString *)0 ), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
353 22 : { MAP_LEN( "VBACompatibilityMode" ), 0, &::getBooleanCppuType(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
354 22 : { MAP_LEN( "ScriptConfiguration" ), 0, &::getCppuType((uno::Reference<container::XNameAccess> *)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
355 22 : { MAP_LEN( "OrganizerMode" ), 0, &::getBooleanCppuType(),
356 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
357 :
358 : { NULL, 0, 0, NULL, 0, 0 }
359 286 : };
360 22 : uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aImportInfoMap ) ) );
361 :
362 : // ---- get BuildId from parent container if available
363 :
364 22 : uno::Reference< container::XChild > xChild( xModel, uno::UNO_QUERY );
365 22 : if( xChild.is() )
366 : {
367 22 : uno::Reference< beans::XPropertySet > xParentSet( xChild->getParent(), uno::UNO_QUERY );
368 22 : if( xParentSet.is() )
369 : {
370 0 : uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xParentSet->getPropertySetInfo() );
371 0 : OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("BuildId" ) );
372 0 : if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(sPropName) )
373 : {
374 0 : xInfoSet->setPropertyValue( sPropName, xParentSet->getPropertyValue(sPropName) );
375 0 : }
376 22 : }
377 : }
378 :
379 : // -------------------------------------
380 :
381 22 : uno::Reference<task::XStatusIndicator> xStatusIndicator(GetStatusIndicator());
382 22 : if (xStatusIndicator.is())
383 : {
384 0 : sal_Int32 nProgressRange(1000000);
385 0 : xStatusIndicator->start(rtl::OUString(ScGlobal::GetRscString(STR_LOAD_DOC)), nProgressRange);
386 0 : xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ProgressRange")), uno::makeAny(nProgressRange));
387 : }
388 :
389 : // Set base URI
390 : OSL_ENSURE( pMedium, "There is no medium to get MediaDescriptor from!\n" );
391 22 : ::rtl::OUString aBaseURL = pMedium ? pMedium->GetBaseURL() : ::rtl::OUString();
392 22 : rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("BaseURI") );
393 22 : xInfoSet->setPropertyValue( sPropName, uno::makeAny( aBaseURL ) );
394 :
395 : // TODO/LATER: do not do it for embedded links
396 22 : if( SFX_CREATE_MODE_EMBEDDED == pObjSh->GetCreateMode() )
397 : {
398 22 : OUString aName;
399 22 : if ( pMedium && pMedium->GetItemSet() )
400 : {
401 : const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
402 22 : pMedium->GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
403 22 : if ( pDocHierarchItem )
404 0 : aName = pDocHierarchItem->GetValue();
405 : }
406 : else
407 0 : aName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "dummyObjectName" ));
408 :
409 22 : if( !aName.isEmpty() )
410 : {
411 0 : sPropName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamRelPath"));
412 0 : xInfoSet->setPropertyValue( sPropName, uno::makeAny( aName ) );
413 22 : }
414 : }
415 :
416 22 : if (bStylesOnly)
417 : {
418 : ::rtl::OUString const sOrganizerMode(
419 0 : RTL_CONSTASCII_USTRINGPARAM("OrganizerMode"));
420 0 : xInfoSet->setPropertyValue(sOrganizerMode, uno::makeAny(sal_True));
421 : }
422 :
423 22 : sal_Bool bOasis = ( SotStorage::GetVersion( xStorage ) > SOFFICE_FILEFORMAT_60 );
424 :
425 : // #i103539#: always read meta.xml for generator
426 22 : sal_uInt32 nMetaRetval(0);
427 22 : uno::Sequence<uno::Any> aMetaArgs(1);
428 22 : uno::Any* pMetaArgs = aMetaArgs.getArray();
429 22 : pMetaArgs[0] <<= xInfoSet;
430 :
431 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "meta import start" );
432 :
433 : nMetaRetval = ImportFromComponent(
434 : xServiceFactory, xModel, xXMLParser, aParserInput,
435 : bOasis ? rtl::OUString("com.sun.star.comp.Calc.XMLOasisMetaImporter")
436 : : rtl::OUString("com.sun.star.comp.Calc.XMLMetaImporter"),
437 22 : "meta.xml", "Meta.xml", aMetaArgs, false);
438 :
439 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "meta import end" );
440 :
441 22 : SvXMLGraphicHelper* pGraphicHelper = NULL;
442 22 : uno::Reference< document::XGraphicObjectResolver > xGrfContainer;
443 :
444 22 : uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
445 22 : SvXMLEmbeddedObjectHelper *pObjectHelper = NULL;
446 :
447 22 : if( xStorage.is() )
448 : {
449 22 : pGraphicHelper = SvXMLGraphicHelper::Create( xStorage, GRAPHICHELPER_MODE_READ );
450 22 : xGrfContainer = pGraphicHelper;
451 :
452 22 : if( pObjSh )
453 : {
454 22 : pObjectHelper = SvXMLEmbeddedObjectHelper::Create(xStorage, *pObjSh, EMBEDDEDOBJECTHELPER_MODE_READ, false );
455 22 : xObjectResolver = pObjectHelper;
456 : }
457 : }
458 22 : uno::Sequence<uno::Any> aStylesArgs(4);
459 22 : uno::Any* pStylesArgs = aStylesArgs.getArray();
460 22 : pStylesArgs[0] <<= xInfoSet;
461 22 : pStylesArgs[1] <<= xGrfContainer;
462 22 : pStylesArgs[2] <<= xStatusIndicator;
463 22 : pStylesArgs[3] <<= xObjectResolver;
464 :
465 22 : sal_uInt32 nSettingsRetval(0);
466 22 : if (!bStylesOnly)
467 : {
468 : // Settings must be loaded first because of the printer setting,
469 : // which is needed in the page styles (paper tray).
470 :
471 22 : uno::Sequence<uno::Any> aSettingsArgs(1);
472 22 : uno::Any* pSettingsArgs = aSettingsArgs.getArray();
473 22 : pSettingsArgs[0] <<= xInfoSet;
474 :
475 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "settings import start" );
476 :
477 : nSettingsRetval = ImportFromComponent(
478 : xServiceFactory, xModel, xXMLParser, aParserInput,
479 : bOasis ? rtl::OUString("com.sun.star.comp.Calc.XMLOasisSettingsImporter")
480 : : rtl::OUString("com.sun.star.comp.Calc.XMLSettingsImporter"),
481 22 : "settings.xml", sEmpty, aSettingsArgs, false);
482 :
483 22 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "settings import end" );
484 : }
485 :
486 22 : sal_uInt32 nStylesRetval(0);
487 : {
488 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "styles import start" );
489 :
490 : nStylesRetval = ImportFromComponent(xServiceFactory, xModel, xXMLParser, aParserInput,
491 : bOasis ? rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.XMLOasisStylesImporter"))
492 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.XMLStylesImporter")),
493 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("styles.xml")),
494 22 : sEmpty, aStylesArgs, sal_True);
495 :
496 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "styles import end" );
497 : }
498 :
499 22 : sal_uInt32 nDocRetval(0);
500 22 : if (!bStylesOnly)
501 : {
502 22 : uno::Sequence<uno::Any> aDocArgs(4);
503 22 : uno::Any* pDocArgs = aDocArgs.getArray();
504 22 : pDocArgs[0] <<= xInfoSet;
505 22 : pDocArgs[1] <<= xGrfContainer;
506 22 : pDocArgs[2] <<= xStatusIndicator;
507 22 : pDocArgs[3] <<= xObjectResolver;
508 :
509 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "content import start" );
510 :
511 : nDocRetval = ImportFromComponent(xServiceFactory, xModel, xXMLParser, aParserInput,
512 : bOasis ? rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.XMLOasisContentImporter"))
513 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.XMLContentImporter")),
514 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("content.xml")),
515 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Content.xml")), aDocArgs,
516 22 : sal_True);
517 :
518 22 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "content import end" );
519 : }
520 22 : if( pGraphicHelper )
521 22 : SvXMLGraphicHelper::Destroy( pGraphicHelper );
522 :
523 22 : if( pObjectHelper )
524 22 : SvXMLEmbeddedObjectHelper::Destroy( pObjectHelper );
525 :
526 22 : if (xStatusIndicator.is())
527 0 : xStatusIndicator->end();
528 :
529 22 : sal_Bool bRet(false);
530 22 : if (bStylesOnly)
531 : {
532 0 : if (nStylesRetval)
533 0 : nError = nStylesRetval;
534 : else
535 0 : bRet = sal_True;
536 : }
537 : else
538 : {
539 22 : if (nDocRetval)
540 : {
541 0 : nError = nDocRetval;
542 0 : if (nDocRetval == SCWARN_IMPORT_RANGE_OVERFLOW ||
543 : nDocRetval == SCWARN_IMPORT_ROW_OVERFLOW ||
544 : nDocRetval == SCWARN_IMPORT_COLUMN_OVERFLOW ||
545 : nDocRetval == SCWARN_IMPORT_SHEET_OVERFLOW)
546 0 : bRet = sal_True;
547 : }
548 22 : else if (nStylesRetval)
549 0 : nError = nStylesRetval;
550 22 : else if (nMetaRetval)
551 0 : nError = nMetaRetval;
552 22 : else if (nSettingsRetval)
553 0 : nError = nSettingsRetval;
554 : else
555 22 : bRet = sal_True;
556 : }
557 :
558 : // set BuildId on XModel for later OLE object loading
559 22 : if( xInfoSet.is() )
560 : {
561 22 : uno::Reference< beans::XPropertySet > xModelSet( xModel, uno::UNO_QUERY );
562 22 : if( xModelSet.is() )
563 : {
564 22 : uno::Reference< beans::XPropertySetInfo > xModelSetInfo( xModelSet->getPropertySetInfo() );
565 22 : OUString sBuildPropName( RTL_CONSTASCII_USTRINGPARAM("BuildId" ) );
566 22 : if( xModelSetInfo.is() && xModelSetInfo->hasPropertyByName(sBuildPropName) )
567 : {
568 22 : xModelSet->setPropertyValue( sBuildPropName, xInfoSet->getPropertyValue(sBuildPropName) );
569 22 : }
570 : }
571 :
572 : // Set Code Names
573 22 : uno::Any aAny = xInfoSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("ScriptConfiguration") ));
574 22 : uno::Reference <container::XNameAccess> xCodeNameAccess;
575 22 : if( aAny >>= xCodeNameAccess )
576 0 : XMLCodeNameProvider::set( xCodeNameAccess, &rDoc );
577 :
578 : // VBA compatibility
579 22 : bool bVBACompat = false;
580 22 : if ( (xInfoSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("VBACompatibilityMode"))) >>= bVBACompat) && bVBACompat )
581 : {
582 : /* Set library container to VBA compatibility mode, this
583 : forces loading the Basic project, which in turn creates the
584 : VBA Globals object and does all related initialization. */
585 0 : if ( xModelSet.is() ) try
586 : {
587 0 : uno::Reference< script::vba::XVBACompatibility > xVBACompat( xModelSet->getPropertyValue(
588 0 : OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ), uno::UNO_QUERY_THROW );
589 0 : xVBACompat->setVBACompatibilityMode( sal_True );
590 : }
591 0 : catch( uno::Exception& )
592 : {
593 : }
594 22 : }
595 : }
596 :
597 : // Don't test bStylesRetval and bMetaRetval, because it could be an older file which not contain such streams
598 22 : return bRet;//!bStylesOnly ? bDocRetval : bStylesRetval;
599 : }
600 0 : return false;
601 : }
602 :
603 2 : static bool lcl_HasValidStream(ScDocument& rDoc)
604 : {
605 2 : SfxObjectShell* pObjSh = rDoc.GetDocumentShell();
606 2 : if ( pObjSh->IsDocShared() )
607 0 : return false; // never copy stream from shared file
608 :
609 : // don't read remote file again
610 : // (could instead re-use medium directly in that case)
611 2 : SfxMedium* pSrcMed = rDoc.GetDocumentShell()->GetMedium();
612 2 : if ( !pSrcMed || pSrcMed->IsRemote() )
613 0 : return false;
614 :
615 2 : SCTAB nTabCount = rDoc.GetTableCount();
616 4 : for (SCTAB nTab=0; nTab<nTabCount; ++nTab)
617 2 : if (rDoc.IsStreamValid(nTab))
618 0 : return true;
619 2 : return false;
620 : }
621 :
622 8 : sal_Bool ScXMLImportWrapper::ExportToComponent(uno::Reference<lang::XMultiServiceFactory>& xServiceFactory,
623 : uno::Reference<frame::XModel>& xModel, uno::Reference<xml::sax::XWriter>& xWriter,
624 : uno::Sequence<beans::PropertyValue>& aDescriptor, const rtl::OUString& sName,
625 : const rtl::OUString& sMediaType, const rtl::OUString& sComponentName,
626 : uno::Sequence<uno::Any>& aArgs, ScMySharedData*& pSharedData)
627 : {
628 8 : sal_Bool bRet(false);
629 8 : uno::Reference<io::XOutputStream> xOut;
630 8 : uno::Reference<io::XStream> xStream;
631 :
632 8 : if ( !xStorage.is() && pMedium )
633 0 : xStorage = pMedium->GetOutputStorage();
634 :
635 8 : if( xStorage.is() )
636 : {
637 : // #96807#; trunc stream before use, because it could be an existing stream
638 : // and the new content could be shorter than the old content. In this case
639 : // would not all be over written by the new content and the xml file
640 : // would not be valid.
641 8 : xStream = xStorage->openStreamElement( sName, embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
642 8 : uno::Reference < beans::XPropertySet > xSet( xStream, uno::UNO_QUERY );
643 8 : if (xSet.is())
644 : {
645 8 : xSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType")), uno::makeAny(sMediaType));
646 8 : OUString aUseCommonPassPropName( RTL_CONSTASCII_USTRINGPARAM("UseCommonStoragePasswordEncryption") );
647 :
648 : // advise storage impl to use common encryption
649 8 : xSet->setPropertyValue( aUseCommonPassPropName, uno::makeAny(sal_True) );
650 : }
651 :
652 8 : xOut = xStream->getOutputStream();
653 : }
654 :
655 : // set Base URL
656 8 : uno::Reference< beans::XPropertySet > xInfoSet;
657 8 : if( aArgs.getLength() > 0 )
658 8 : aArgs.getConstArray()[0] >>= xInfoSet;
659 : OSL_ENSURE( xInfoSet.is(), "missing property set" );
660 8 : if( xInfoSet.is() )
661 : {
662 8 : rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("StreamName") );
663 8 : xInfoSet->setPropertyValue( sPropName, uno::makeAny( sName ) );
664 : }
665 :
666 8 : xWriter->setOutputStream( xOut );
667 :
668 : uno::Reference<document::XFilter> xFilter(
669 8 : xServiceFactory->createInstanceWithArguments( sComponentName , aArgs ),
670 8 : uno::UNO_QUERY );
671 : OSL_ENSURE( xFilter.is(), "can't get exporter" );
672 8 : uno::Reference<document::XExporter> xExporter( xFilter, uno::UNO_QUERY );
673 8 : uno::Reference<lang::XComponent> xComponent( xModel, uno::UNO_QUERY );
674 8 : if (xExporter.is())
675 8 : xExporter->setSourceDocument( xComponent );
676 :
677 8 : if ( xFilter.is() )
678 : {
679 8 : ScXMLExport* pExport = static_cast<ScXMLExport*>(SvXMLExport::getImplementation(xFilter));
680 8 : pExport->SetSharedData(pSharedData);
681 :
682 : // if there are sheets to copy, get the source stream
683 8 : if ( sName == "content.xml" && lcl_HasValidStream(rDoc) && ( pExport->getExportFlags() & EXPORT_OASIS ) )
684 : {
685 : // old stream is still in this file's storage - open read-only
686 :
687 : // #i106854# use the document's storage directly, without a temporary SfxMedium
688 0 : uno::Reference<embed::XStorage> xTmpStorage = rDoc.GetDocumentShell()->GetStorage();
689 0 : uno::Reference<io::XStream> xSrcStream;
690 0 : uno::Reference<io::XInputStream> xSrcInput;
691 :
692 : // #i108978# If an embedded object is saved and no events are notified, don't use the stream
693 : // because without the ...DONE events, stream positions aren't updated.
694 0 : ScSheetSaveData* pSheetData = ScModelObj::getImplementation(xModel)->GetSheetSaveData();
695 0 : if (pSheetData && pSheetData->IsInSupportedSave())
696 : {
697 : try
698 : {
699 0 : if (xTmpStorage.is())
700 0 : xSrcStream = xTmpStorage->openStreamElement( sName, embed::ElementModes::READ );
701 0 : if (xSrcStream.is())
702 0 : xSrcInput = xSrcStream->getInputStream();
703 : }
704 0 : catch (uno::Exception&)
705 : {
706 : // stream not available (for example, password protected) - save normally (xSrcInput is null)
707 : }
708 : }
709 :
710 0 : pExport->SetSourceStream( xSrcInput );
711 0 : bRet = xFilter->filter( aDescriptor );
712 0 : pExport->SetSourceStream( uno::Reference<io::XInputStream>() );
713 :
714 : // If there was an error, reset all stream flags, so the next save attempt will use normal saving.
715 : // #i110692# For embedded objects, the stream may be unavailable for one save operation (m_pAntiImpl)
716 : // and become available again later. But after saving normally once, the stream positions aren't
717 : // valid anymore, so the flags also have to be reset if the stream wasn't available.
718 0 : if ( !bRet || !xSrcInput.is() )
719 : {
720 0 : SCTAB nTabCount = rDoc.GetTableCount();
721 0 : for (SCTAB nTab=0; nTab<nTabCount; nTab++)
722 0 : if (rDoc.IsStreamValid(nTab))
723 0 : rDoc.SetStreamValid(nTab, false);
724 0 : }
725 : }
726 : else
727 8 : bRet = xFilter->filter( aDescriptor );
728 :
729 8 : pSharedData = pExport->GetSharedData();
730 : }
731 :
732 8 : return bRet;
733 : }
734 :
735 2 : sal_Bool ScXMLImportWrapper::Export(sal_Bool bStylesOnly)
736 : {
737 : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "sb99857", "ScXMLImportWrapper::Export" );
738 :
739 2 : uno::Reference<lang::XMultiServiceFactory> xServiceFactory(comphelper::getProcessServiceFactory());
740 2 : uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
741 : OSL_ENSURE( xServiceFactory.is(), "got no service manager" );
742 2 : if( !xServiceFactory.is() )
743 0 : return false;
744 :
745 2 : uno::Reference<xml::sax::XWriter> xWriter = xml::sax::Writer::create(xContext);
746 :
747 2 : if ( !xStorage.is() && pMedium )
748 2 : xStorage = pMedium->GetOutputStorage();
749 :
750 2 : OUString sFileName;
751 2 : OUString sTextMediaType(RTL_CONSTASCII_USTRINGPARAM("text/xml"));
752 2 : if (pMedium)
753 2 : sFileName = pMedium->GetName();
754 2 : SfxObjectShell* pObjSh = rDoc.GetDocumentShell();
755 2 : uno::Sequence<beans::PropertyValue> aDescriptor(1);
756 2 : beans::PropertyValue* pProps = aDescriptor.getArray();
757 2 : pProps[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FileName" ) );
758 2 : pProps[0].Value <<= sFileName;
759 :
760 : /** property map for export info set */
761 : comphelper::PropertyMapEntry aExportInfoMap[] =
762 : {
763 2 : { MAP_LEN( "ProgressRange" ), 0, &::getCppuType((sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
764 2 : { MAP_LEN( "ProgressMax" ), 0, &::getCppuType((sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
765 2 : { MAP_LEN( "ProgressCurrent" ), 0, &::getCppuType((sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
766 2 : { MAP_LEN( "WrittenNumberStyles" ), 0, &::getCppuType((uno::Sequence<sal_Int32>*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
767 2 : { MAP_LEN( "UsePrettyPrinting" ), 0, &::getCppuType((sal_Bool*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
768 2 : { MAP_LEN( "BaseURI" ), 0, &::getCppuType( (rtl::OUString *)0 ), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
769 2 : { MAP_LEN( "StreamRelPath" ), 0, &::getCppuType( (rtl::OUString *)0 ), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
770 2 : { MAP_LEN( "StreamName" ), 0, &::getCppuType( (rtl::OUString *)0 ), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
771 2 : { MAP_LEN( "StyleNames" ), 0, &::getCppuType( (uno::Sequence<rtl::OUString>*)0 ), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
772 2 : { MAP_LEN( "StyleFamilies" ), 0, &::getCppuType( (uno::Sequence<sal_Int32>*)0 ), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
773 2 : { MAP_LEN( "TargetStorage" ), 0, &embed::XStorage::static_type(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
774 : { NULL, 0, 0, NULL, 0, 0 }
775 24 : };
776 2 : uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap ) ) );
777 :
778 2 : if ( pObjSh && xStorage.is() )
779 : {
780 2 : pObjSh->UpdateDocInfoForSave(); // update information
781 :
782 2 : uno::Reference<frame::XModel> xModel(pObjSh->GetModel());
783 2 : uno::Reference<task::XStatusIndicator> xStatusIndicator(GetStatusIndicator());
784 2 : sal_Int32 nProgressRange(1000000);
785 2 : if(xStatusIndicator.is())
786 0 : xStatusIndicator->start(rtl::OUString(ScGlobal::GetRscString(STR_SAVE_DOC)), nProgressRange);
787 2 : xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ProgressRange")), uno::makeAny(nProgressRange));
788 :
789 2 : SvtSaveOptions aSaveOpt;
790 2 : sal_Bool bUsePrettyPrinting(aSaveOpt.IsPrettyPrinting());
791 2 : xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UsePrettyPrinting")), uno::makeAny(bUsePrettyPrinting));
792 :
793 2 : const OUString sTargetStorage( RTL_CONSTASCII_USTRINGPARAM("TargetStorage") );
794 2 : xInfoSet->setPropertyValue( sTargetStorage, uno::Any( xStorage ) );
795 :
796 : OSL_ENSURE( pMedium, "There is no medium to get MediaDescriptor from!\n" );
797 2 : ::rtl::OUString aBaseURL = pMedium ? pMedium->GetBaseURL( true ) : ::rtl::OUString();
798 2 : rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("BaseURI") );
799 2 : xInfoSet->setPropertyValue( sPropName, uno::makeAny( aBaseURL ) );
800 :
801 : // TODO/LATER: do not do it for embedded links
802 2 : if( SFX_CREATE_MODE_EMBEDDED == pObjSh->GetCreateMode() )
803 : {
804 0 : OUString aName(RTL_CONSTASCII_USTRINGPARAM("dummyObjectName"));
805 0 : if ( pMedium && pMedium->GetItemSet() )
806 : {
807 : const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
808 0 : pMedium->GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
809 0 : if ( pDocHierarchItem )
810 0 : aName = pDocHierarchItem->GetValue();
811 : }
812 :
813 0 : if( !aName.isEmpty() )
814 : {
815 0 : sPropName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamRelPath"));
816 0 : xInfoSet->setPropertyValue( sPropName, uno::makeAny( aName ) );
817 0 : }
818 : }
819 :
820 2 : sal_Bool bMetaRet(pObjSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED);
821 2 : sal_Bool bStylesRet (false);
822 2 : sal_Bool bDocRet(false);
823 2 : sal_Bool bSettingsRet(false);
824 2 : ScMySharedData* pSharedData = NULL;
825 :
826 2 : sal_Bool bOasis = ( SotStorage::GetVersion( xStorage ) > SOFFICE_FILEFORMAT_60 );
827 :
828 : // meta export
829 2 : if (!bStylesOnly && !bMetaRet)
830 : {
831 2 : uno::Sequence<uno::Any> aMetaArgs(3);
832 2 : uno::Any* pMetaArgs = aMetaArgs.getArray();
833 2 : pMetaArgs[0] <<= xInfoSet;
834 2 : pMetaArgs[1] <<= xWriter;
835 2 : pMetaArgs[2] <<= xStatusIndicator;
836 :
837 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "meta export start" );
838 :
839 : bMetaRet = ExportToComponent(xServiceFactory, xModel, xWriter, aDescriptor,
840 : rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("meta.xml")),
841 : sTextMediaType,
842 : bOasis ? rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.XMLOasisMetaExporter"))
843 : : rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.XMLMetaExporter")),
844 2 : aMetaArgs, pSharedData);
845 :
846 2 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "meta export end" );
847 : }
848 :
849 2 : uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
850 2 : SvXMLEmbeddedObjectHelper *pObjectHelper = 0;
851 :
852 2 : uno::Reference< document::XGraphicObjectResolver > xGrfContainer;
853 2 : SvXMLGraphicHelper* pGraphicHelper = 0;
854 :
855 2 : if( xStorage.is() )
856 : {
857 2 : pGraphicHelper = SvXMLGraphicHelper::Create( xStorage, GRAPHICHELPER_MODE_WRITE, false );
858 2 : xGrfContainer = pGraphicHelper;
859 : }
860 :
861 2 : if( pObjSh )
862 : {
863 2 : pObjectHelper = SvXMLEmbeddedObjectHelper::Create( xStorage, *pObjSh, EMBEDDEDOBJECTHELPER_MODE_WRITE, false );
864 2 : xObjectResolver = pObjectHelper;
865 : }
866 :
867 : // styles export
868 :
869 : {
870 2 : uno::Sequence<uno::Any> aStylesArgs(5);
871 2 : uno::Any* pStylesArgs = aStylesArgs.getArray();
872 2 : pStylesArgs[0] <<= xInfoSet;
873 2 : pStylesArgs[1] <<= xGrfContainer;
874 2 : pStylesArgs[2] <<= xStatusIndicator;
875 2 : pStylesArgs[3] <<= xWriter;
876 2 : pStylesArgs[4] <<= xObjectResolver;
877 :
878 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "styles export start" );
879 :
880 : bStylesRet = ExportToComponent(xServiceFactory, xModel, xWriter, aDescriptor,
881 : rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("styles.xml")),
882 : sTextMediaType,
883 : bOasis ? rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.XMLOasisStylesExporter"))
884 : : rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.XMLStylesExporter")),
885 2 : aStylesArgs, pSharedData);
886 :
887 2 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "styles export end" );
888 : }
889 :
890 : // content export
891 :
892 2 : if (!bStylesOnly)
893 : {
894 2 : uno::Sequence<uno::Any> aDocArgs(5);
895 2 : uno::Any* pDocArgs = aDocArgs.getArray();
896 2 : pDocArgs[0] <<= xInfoSet;
897 2 : pDocArgs[1] <<= xGrfContainer;
898 2 : pDocArgs[2] <<= xStatusIndicator;
899 2 : pDocArgs[3] <<= xWriter;
900 2 : pDocArgs[4] <<= xObjectResolver;
901 :
902 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "content export start" );
903 :
904 : bDocRet = ExportToComponent(xServiceFactory, xModel, xWriter, aDescriptor,
905 : rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("content.xml")),
906 : sTextMediaType,
907 : bOasis ? rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.XMLOasisContentExporter"))
908 : : rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.XMLContentExporter")),
909 2 : aDocArgs, pSharedData);
910 :
911 2 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "content export end" );
912 : }
913 :
914 2 : if( pGraphicHelper )
915 2 : SvXMLGraphicHelper::Destroy( pGraphicHelper );
916 :
917 2 : if( pObjectHelper )
918 2 : SvXMLEmbeddedObjectHelper::Destroy( pObjectHelper );
919 :
920 : // settings export
921 :
922 2 : if (!bStylesOnly)
923 : {
924 2 : uno::Sequence<uno::Any> aSettingsArgs(3);
925 2 : uno::Any* pSettingsArgs = aSettingsArgs.getArray();
926 2 : pSettingsArgs[0] <<= xInfoSet;
927 2 : pSettingsArgs[1] <<= xWriter;
928 2 : pSettingsArgs[2] <<= xStatusIndicator;
929 :
930 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "settings export start" );
931 :
932 : bSettingsRet = ExportToComponent(xServiceFactory, xModel, xWriter, aDescriptor,
933 : rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("settings.xml")),
934 : sTextMediaType,
935 : bOasis ? rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.XMLOasisSettingsExporter"))
936 : : rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.XMLSettingsExporter")),
937 2 : aSettingsArgs, pSharedData);
938 :
939 2 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "settings export end" );
940 : }
941 :
942 2 : if (pSharedData)
943 2 : delete pSharedData;
944 :
945 2 : if (xStatusIndicator.is())
946 0 : xStatusIndicator->end();
947 2 : return bStylesRet && ((!bStylesOnly && bDocRet && bMetaRet && bSettingsRet) || bStylesOnly);
948 : }
949 :
950 : // later: give string descriptor as parameter for doc type
951 :
952 0 : return false;
953 : }
954 :
955 :
956 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|