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