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