LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlwrap.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 344 454 75.8 %
Date: 2014-11-03 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10