LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/filter/xml - sdxmlwrp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 312 412 75.7 %
Date: 2013-07-09 Functions: 9 10 90.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 <rtl/strbuf.hxx>
      21             : #include <com/sun/star/container/XChild.hpp>
      22             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      23             : #include <com/sun/star/embed/ElementModes.hpp>
      24             : #include <com/sun/star/xml/sax/SAXParseException.hpp>
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <sfx2/docfile.hxx>
      27             : #include <sfx2/docfilt.hxx>
      28             : #include "drawdoc.hxx"
      29             : #include <unotools/streamwrap.hxx>
      30             : #include <svx/xmlgrhlp.hxx>
      31             : 
      32             : #include "../../ui/inc/DrawDocShell.hxx"
      33             : 
      34             : #include "sdxmlwrp.hxx"
      35             : #include "strmname.h"
      36             : #include <svx/xmleohlp.hxx>
      37             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      38             : #include <com/sun/star/document/XFilter.hpp>
      39             : #include <com/sun/star/document/XImporter.hpp>
      40             : #include <com/sun/star/document/XExporter.hpp>
      41             : #include <com/sun/star/lang/XServiceInfo.hpp>
      42             : #include <com/sun/star/document/XGraphicObjectResolver.hpp>
      43             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      44             : #include <com/sun/star/container/XNameAccess.hpp>
      45             : #include <com/sun/star/packages/zip/ZipIOException.hpp>
      46             : 
      47             : #include <com/sun/star/xml/sax/XErrorHandler.hpp>
      48             : #include <com/sun/star/xml/sax/XEntityResolver.hpp>
      49             : #include <com/sun/star/xml/sax/InputSource.hpp>
      50             : #include <com/sun/star/xml/sax/XDTDHandler.hpp>
      51             : #include <com/sun/star/xml/sax/Parser.hpp>
      52             : #include <com/sun/star/xml/sax/Writer.hpp>
      53             : #include <com/sun/star/io/XActiveDataSource.hpp>
      54             : #include <com/sun/star/io/XActiveDataControl.hpp>
      55             : #include <comphelper/genericpropertyset.hxx>
      56             : #include <comphelper/propertysetinfo.hxx>
      57             : #include <unotools/saveopt.hxx>
      58             : 
      59             : // include necessary for XML progress bar at load time
      60             : #include <svl/itemset.hxx>
      61             : #include <svl/stritem.hxx>
      62             : #include <svtools/sfxecode.hxx>
      63             : 
      64             : #include "sderror.hxx"
      65             : #include "sdresid.hxx"
      66             : #include "glob.hrc"
      67             : 
      68             : #include <sfx2/frame.hxx>
      69             : 
      70             : using namespace com::sun::star;
      71             : using namespace com::sun::star::uno;
      72             : using namespace com::sun::star::lang;
      73             : using namespace com::sun::star::document;
      74             : using namespace comphelper;
      75             : 
      76             : #define SD_XML_READERROR 1234
      77             : 
      78             : extern void TransformOOo2xDocument( SdDrawDocument* pDocument );
      79             : 
      80             : //////////////////////////////////////////////////////////////////////////////
      81             : 
      82             : #ifndef SEQTYPE
      83             :  #if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
      84             :   #define SEQTYPE(x) (new ::com::sun::star::uno::Type( x ))
      85             :  #else
      86             :   #define SEQTYPE(x) &(x)
      87             :  #endif
      88             : #endif
      89             : 
      90             : #define MAP_LEN(x) x, sizeof(x) - 1
      91             : 
      92             : #define XML_STRING(i, x) sal_Char const i[sizeof(x)] = x
      93             : 
      94             : XML_STRING( sXML_metaStreamName, "meta.xml");
      95             : XML_STRING( sXML_styleStreamName, "styles.xml" );
      96             : XML_STRING( sXML_contentStreamName, "content.xml" );
      97             : XML_STRING( sXML_oldContentStreamName, "Content.xml" );
      98             : XML_STRING( sXML_settingsStreamName, "settings.xml" );
      99             : 
     100             : XML_STRING( sXML_export_impress_oasis_service, "com.sun.star.comp.Impress.XMLOasisExporter" );
     101             : XML_STRING( sXML_export_impress_meta_oasis_service, "com.sun.star.comp.Impress.XMLOasisMetaExporter" );
     102             : XML_STRING( sXML_export_impress_styles_oasis_service, "com.sun.star.comp.Impress.XMLOasisStylesExporter" );
     103             : XML_STRING( sXML_export_impress_content_oasis_service, "com.sun.star.comp.Impress.XMLOasisContentExporter" );
     104             : XML_STRING( sXML_export_impress_settings_oasis_service, "com.sun.star.comp.Impress.XMLOasisSettingsExporter" );
     105             : 
     106             : XML_STRING( sXML_export_draw_oasis_service, "com.sun.star.comp.Draw.XMLOasisExporter" );
     107             : XML_STRING( sXML_export_draw_meta_oasis_service, "com.sun.star.comp.Draw.XMLOasisMetaExporter" );
     108             : XML_STRING( sXML_export_draw_styles_oasis_service, "com.sun.star.comp.Draw.XMLOasisStylesExporter" );
     109             : XML_STRING( sXML_export_draw_content_oasis_service, "com.sun.star.comp.Draw.XMLOasisContentExporter" );
     110             : XML_STRING( sXML_export_draw_settings_oasis_service, "com.sun.star.comp.Draw.XMLOasisSettingsExporter" );
     111             : 
     112             : XML_STRING( sXML_import_impress_oasis_service, "com.sun.star.comp.Impress.XMLOasisImporter" );
     113             : XML_STRING( sXML_import_impress_meta_oasis_service, "com.sun.star.comp.Impress.XMLOasisMetaImporter" );
     114             : XML_STRING( sXML_import_impress_styles_oasis_service, "com.sun.star.comp.Impress.XMLOasisStylesImporter" );
     115             : XML_STRING( sXML_import_impress_content_oasis_service, "com.sun.star.comp.Impress.XMLOasisContentImporter" );
     116             : XML_STRING( sXML_import_impress_settings_oasis_service, "com.sun.star.comp.Impress.XMLOasisSettingsImporter" );
     117             : 
     118             : XML_STRING( sXML_import_draw_oasis_service, "com.sun.star.comp.Draw.XMLOasisImporter" );
     119             : XML_STRING( sXML_import_draw_meta_oasis_service, "com.sun.star.comp.Draw.XMLOasisMetaImporter" );
     120             : XML_STRING( sXML_import_draw_styles_oasis_service, "com.sun.star.comp.Draw.XMLOasisStylesImporter" );
     121             : XML_STRING( sXML_import_draw_content_oasis_service, "com.sun.star.comp.Draw.XMLOasisContentImporter" );
     122             : XML_STRING( sXML_import_draw_settings_oasis_service, "com.sun.star.comp.Draw.XMLOasisSettingsImporter" );
     123             : 
     124             : // OOo
     125             : XML_STRING( sXML_export_impress_ooo_service, "com.sun.star.comp.Impress.XMLExporter" );
     126             : XML_STRING( sXML_export_impress_meta_ooo_service, "com.sun.star.comp.Impress.XMLMetaExporter" );
     127             : XML_STRING( sXML_export_impress_styles_ooo_service, "com.sun.star.comp.Impress.XMLStylesExporter" );
     128             : XML_STRING( sXML_export_impress_content_ooo_service, "com.sun.star.comp.Impress.XMLContentExporter" );
     129             : XML_STRING( sXML_export_impress_settings_ooo_service, "com.sun.star.comp.Impress.XMLSettingsExporter" );
     130             : 
     131             : XML_STRING( sXML_export_draw_ooo_service, "com.sun.star.comp.Draw.XMLExporter" );
     132             : XML_STRING( sXML_export_draw_meta_ooo_service, "com.sun.star.comp.Draw.XMLMetaExporter" );
     133             : XML_STRING( sXML_export_draw_styles_ooo_service, "com.sun.star.comp.Draw.XMLStylesExporter" );
     134             : XML_STRING( sXML_export_draw_content_ooo_service, "com.sun.star.comp.Draw.XMLContentExporter" );
     135             : XML_STRING( sXML_export_draw_settings_ooo_service, "com.sun.star.comp.Draw.XMLSettingsExporter" );
     136             : 
     137             : XML_STRING( sXML_import_impress_ooo_service, "com.sun.star.comp.Impress.XMLImporter" );
     138             : XML_STRING( sXML_import_impress_meta_ooo_service, "com.sun.star.comp.Impress.XMLMetaImporter" );
     139             : XML_STRING( sXML_import_impress_styles_ooo_service, "com.sun.star.comp.Impress.XMLStylesImporter" );
     140             : XML_STRING( sXML_import_impress_content_ooo_service, "com.sun.star.comp.Impress.XMLContentImporter" );
     141             : XML_STRING( sXML_import_impress_settings_ooo_service, "com.sun.star.comp.Impress.XMLSettingsImporter" );
     142             : 
     143             : XML_STRING( sXML_import_draw_ooo_service, "com.sun.star.comp.Draw.XMLImporter" );
     144             : XML_STRING( sXML_import_draw_meta_ooo_service, "com.sun.star.comp.Draw.XMLMetaImporter" );
     145             : XML_STRING( sXML_import_draw_styles_ooo_service, "com.sun.star.comp.Draw.XMLStylesImporter" );
     146             : XML_STRING( sXML_import_draw_content_ooo_service, "com.sun.star.comp.Draw.XMLContentImporter" );
     147             : XML_STRING( sXML_import_draw_settings_ooo_service, "com.sun.star.comp.Draw.XMLSettingsImporter" );
     148             : 
     149             : struct XML_SERVICEMAP
     150             : {
     151             :     const sal_Char* mpService;
     152             :     const sal_Char* mpStream;
     153             : };
     154             : 
     155             : struct XML_SERVICES
     156             : {
     157             :     const sal_Char* mpAll;
     158             :     const sal_Char* mpMeta;
     159             :     const sal_Char* mpStyles;
     160             :     const sal_Char* mpContent;
     161             :     const sal_Char* mpSettings;
     162             : };
     163             : 
     164          11 : XML_SERVICES* getServices( bool bImport, bool bDraw, sal_uLong nStoreVer )
     165             : {
     166             :     static XML_SERVICES gServices[] =
     167             :     {
     168             :         { sXML_export_impress_oasis_service, sXML_export_impress_meta_oasis_service, sXML_export_impress_styles_oasis_service, sXML_export_impress_content_oasis_service, sXML_export_impress_settings_oasis_service },
     169             :         { sXML_export_draw_oasis_service, sXML_export_draw_meta_oasis_service, sXML_export_draw_styles_oasis_service, sXML_export_draw_content_oasis_service, sXML_export_draw_settings_oasis_service },
     170             :         { sXML_import_impress_oasis_service, sXML_import_impress_meta_oasis_service, sXML_import_impress_styles_oasis_service, sXML_import_impress_content_oasis_service, sXML_import_impress_settings_oasis_service },
     171             :         { sXML_import_draw_oasis_service, sXML_import_draw_meta_oasis_service, sXML_import_draw_styles_oasis_service, sXML_import_draw_content_oasis_service, sXML_import_draw_settings_oasis_service },
     172             : 
     173             :         { sXML_export_impress_ooo_service, sXML_export_impress_meta_ooo_service, sXML_export_impress_styles_ooo_service, sXML_export_impress_content_ooo_service, sXML_export_impress_settings_ooo_service },
     174             :         { sXML_export_draw_ooo_service, sXML_export_draw_meta_ooo_service, sXML_export_draw_styles_ooo_service, sXML_export_draw_content_ooo_service, sXML_export_draw_settings_ooo_service },
     175             :         { sXML_import_impress_ooo_service, sXML_import_impress_meta_ooo_service, sXML_import_impress_styles_ooo_service, sXML_import_impress_content_ooo_service, sXML_import_impress_settings_ooo_service },
     176             :         { sXML_import_draw_ooo_service, sXML_import_draw_meta_ooo_service, sXML_import_draw_styles_ooo_service, sXML_import_draw_content_ooo_service, sXML_import_draw_settings_ooo_service },
     177             :     };
     178             : 
     179          11 :     return &gServices[ (bImport ? 2 : 0) + ((nStoreVer == SOFFICE_FILEFORMAT_60) ? 4 : 0) + (bDraw ? 1 : 0 ) ];
     180             : }
     181             : 
     182             : 
     183             : // ----------------
     184             : // - SdXMLWrapper -
     185             : // ----------------
     186             : 
     187          11 : SdXMLFilter::SdXMLFilter( SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell, sal_Bool bShowProgress, SdXMLFilterMode eFilterMode, sal_uLong nStoreVer ) :
     188          11 :     SdFilter( rMedium, rDocShell, bShowProgress ), meFilterMode( eFilterMode ), mnStoreVer( nStoreVer )
     189             : {
     190          11 : }
     191             : 
     192          11 : SdXMLFilter::~SdXMLFilter(void)
     193             : {
     194          11 : }
     195             : 
     196          28 : sal_Int32 ReadThroughComponent(
     197             :     Reference<io::XInputStream> xInputStream,
     198             :     Reference<XComponent> xModelComponent,
     199             :     const String& rStreamName,
     200             :     Reference<uno::XComponentContext> & rxContext,
     201             :     const sal_Char* pFilterName,
     202             :     Sequence<Any> rFilterArguments,
     203             :     const OUString& rName,
     204             :     sal_Bool bMustBeSuccessfull,
     205             :     sal_Bool bEncrypted )
     206             : {
     207             :     DBG_ASSERT(xInputStream.is(), "input stream missing");
     208             :     DBG_ASSERT(xModelComponent.is(), "document missing");
     209             :     DBG_ASSERT(rxContext.is(), "factory missing");
     210             :     DBG_ASSERT(NULL != pFilterName,"I need a service name for the component!");
     211             : 
     212             :     SAL_INFO( "sd.filter", "ReadThroughComponent" );
     213             : 
     214             :     // prepare ParserInputSrouce
     215          28 :     xml::sax::InputSource aParserInput;
     216          28 :     aParserInput.sSystemId = rName;
     217          28 :     aParserInput.aInputStream = xInputStream;
     218             : 
     219             :     // get parser
     220          56 :     Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(rxContext);
     221             :     SAL_INFO( "sd.filter", "parser created" );
     222             : 
     223             :     // get filter
     224          56 :     OUString aFilterName(OUString::createFromAscii(pFilterName));
     225             :     Reference< xml::sax::XDocumentHandler > xFilter(
     226          56 :         rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(aFilterName, rFilterArguments, rxContext),
     227          56 :         UNO_QUERY );
     228             :     SAL_WARN_IF(!xFilter.is(), "sd.filter", "Can't instantiate filter component: " << aFilterName);
     229          28 :     if( !xFilter.is() )
     230           0 :         return SD_XML_READERROR;
     231             :     SAL_INFO( "sd.filter", "" << pFilterName << " created" );
     232             : 
     233             :     // connect parser and filter
     234          28 :     xParser->setDocumentHandler( xFilter );
     235             : 
     236             :     // connect model and filter
     237          56 :     Reference < XImporter > xImporter( xFilter, UNO_QUERY );
     238          28 :     xImporter->setTargetDocument( xModelComponent );
     239             :     // finally, parser the stream
     240             :     SAL_INFO( "sd.filter", "parsing stream" );
     241             :     try
     242             :     {
     243          28 :         xParser->parseStream( aParserInput );
     244             :     }
     245           0 :     catch (const xml::sax::SAXParseException& r)
     246             :     {
     247             :         // sax parser sends wrapped exceptions,
     248             :         // try to find the original one
     249           0 :         xml::sax::SAXException aSaxEx = *(xml::sax::SAXException*)(&r);
     250           0 :         sal_Bool bTryChild = sal_True;
     251             : 
     252           0 :         while( bTryChild )
     253             :         {
     254           0 :             xml::sax::SAXException aTmp;
     255           0 :             if ( aSaxEx.WrappedException >>= aTmp )
     256           0 :                 aSaxEx = aTmp;
     257             :             else
     258           0 :                 bTryChild = sal_False;
     259           0 :         }
     260             : 
     261           0 :         packages::zip::ZipIOException aBrokenPackage;
     262           0 :         if ( aSaxEx.WrappedException >>= aBrokenPackage )
     263           0 :             return ERRCODE_IO_BROKENPACKAGE;
     264             : 
     265           0 :         if( bEncrypted )
     266           0 :             return ERRCODE_SFX_WRONGPASSWORD;
     267             : 
     268             : #if OSL_DEBUG_LEVEL > 1
     269             :         SAL_WARN( "sd.filter", "SAX parse exception caught while importing:" << r.Message);
     270             : #endif
     271             : 
     272           0 :         String sErr( OUString::number( r.LineNumber ));
     273           0 :         sErr += ',';
     274           0 :         sErr += OUString::number( r.ColumnNumber );
     275             : 
     276           0 :         if( rStreamName.Len() )
     277             :         {
     278             :             return *new TwoStringErrorInfo(
     279             :                             (bMustBeSuccessfull ? ERR_FORMAT_FILE_ROWCOL
     280             :                                                     : WARN_FORMAT_FILE_ROWCOL),
     281             :                             rStreamName, sErr,
     282           0 :                             ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR );
     283             :         }
     284             :         else
     285             :         {
     286             :             DBG_ASSERT( bMustBeSuccessfull, "Warnings are not supported" );
     287             :             return *new StringErrorInfo( ERR_FORMAT_ROWCOL, sErr,
     288           0 :                              ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR );
     289           0 :         }
     290             :     }
     291           0 :     catch (const xml::sax::SAXException& r)
     292             :     {
     293           0 :         packages::zip::ZipIOException aBrokenPackage;
     294           0 :         if ( r.WrappedException >>= aBrokenPackage )
     295           0 :             return ERRCODE_IO_BROKENPACKAGE;
     296             : 
     297           0 :         if( bEncrypted )
     298           0 :             return ERRCODE_SFX_WRONGPASSWORD;
     299             : 
     300             : #if OSL_DEBUG_LEVEL > 1
     301             :         SAL_WARN( "sd.filter", "SAX exception caught while importing:" << r.Message);
     302             : #endif
     303           0 :         return SD_XML_READERROR;
     304             :     }
     305           0 :     catch (const packages::zip::ZipIOException& r)
     306             :     {
     307             : #if OSL_DEBUG_LEVEL > 1
     308             :         SAL_WARN( "sd.filter", "Zip exception caught while importing:" << r.Message);
     309             : #else
     310             :         (void)r;
     311             : #endif
     312           0 :         return ERRCODE_IO_BROKENPACKAGE;
     313             :     }
     314           0 :     catch (const io::IOException& r)
     315             :     {
     316             : #if OSL_DEBUG_LEVEL > 1
     317             :         SAL_WARN( "sd.filter", "IO exception caught while importing:" << r.Message);
     318             : #else
     319             :         (void)r;
     320             : #endif
     321           0 :         return SD_XML_READERROR;
     322             :     }
     323           0 :     catch (const uno::Exception& r)
     324             :     {
     325             : #if OSL_DEBUG_LEVEL > 1
     326             :         SAL_WARN( "sd.filter", "uno exception caught while importing:" << r.Message);
     327             : #else
     328             :         (void)r;
     329             : #endif
     330           0 :         return SD_XML_READERROR;
     331             :     }
     332             : 
     333             :     // success!
     334          56 :     return 0;
     335             : }
     336             : 
     337          28 : sal_Int32 ReadThroughComponent(
     338             :     const uno::Reference < embed::XStorage >& xStorage,
     339             :     Reference<XComponent> xModelComponent,
     340             :     const sal_Char* pStreamName,
     341             :     const sal_Char* pCompatibilityStreamName,
     342             :     Reference<uno::XComponentContext> & rxContext,
     343             :     const sal_Char* pFilterName,
     344             :     Sequence<Any> rFilterArguments,
     345             :     const OUString& rName,
     346             :     sal_Bool bMustBeSuccessfull )
     347             : {
     348             :     DBG_ASSERT(xStorage.is(), "Need storage!");
     349             :     DBG_ASSERT(NULL != pStreamName, "Please, please, give me a name!");
     350             : 
     351             :     // open stream (and set parser input)
     352          28 :     OUString sStreamName = OUString::createFromAscii(pStreamName);
     353          28 :     sal_Bool bContainsStream = sal_False;
     354             :     try
     355             :     {
     356          28 :         bContainsStream = xStorage->isStreamElement(sStreamName);
     357             :     }
     358           0 :     catch (const container::NoSuchElementException&)
     359             :     {
     360             :     }
     361             : 
     362          28 :     if (!bContainsStream )
     363             :     {
     364             :         // stream name not found! Then try the compatibility name.
     365             :         // if no stream can be opened, return immediately with OK signal
     366             : 
     367             :         // do we even have an alternative name?
     368           0 :         if ( NULL == pCompatibilityStreamName )
     369           0 :             return 0;
     370             : 
     371             :         // if so, does the stream exist?
     372           0 :         sStreamName = OUString::createFromAscii(pCompatibilityStreamName);
     373             :         try
     374             :         {
     375           0 :             bContainsStream = xStorage->isStreamElement(sStreamName);
     376             :         }
     377           0 :         catch (const container::NoSuchElementException&)
     378             :         {
     379             :         }
     380             : 
     381           0 :         if (! bContainsStream )
     382           0 :             return 0;
     383             :     }
     384             : 
     385             :     // set Base URL
     386          56 :     uno::Reference< beans::XPropertySet > xInfoSet;
     387          28 :     if( rFilterArguments.getLength() > 0 )
     388          28 :         rFilterArguments.getConstArray()[0] >>= xInfoSet;
     389             :     DBG_ASSERT( xInfoSet.is(), "missing property set" );
     390          28 :     if( xInfoSet.is() )
     391             :     {
     392          28 :         OUString sPropName( "StreamName" );
     393          28 :         xInfoSet->setPropertyValue( sPropName, makeAny( sStreamName ) );
     394             :     }
     395             : 
     396             :     try
     397             :     {
     398             :         // get input stream
     399             :         Reference <io::XStream> xStream =
     400          28 :                 xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
     401          56 :         Reference <beans::XPropertySet > xProps( xStream, uno::UNO_QUERY );
     402          28 :         if ( !xStream.is() || ! xProps.is() )
     403           0 :             return SD_XML_READERROR;
     404             : 
     405          56 :         Any aAny = xProps->getPropertyValue( "Encrypted" );
     406             : 
     407          56 :         sal_Bool bEncrypted = aAny.getValueType() == ::getBooleanCppuType() &&
     408          56 :                 *(sal_Bool *)aAny.getValue();
     409             : 
     410          56 :         Reference <io::XInputStream> xInputStream = xStream->getInputStream();
     411             : 
     412             :         // read from the stream
     413             :         return ReadThroughComponent(
     414             :             xInputStream, xModelComponent, sStreamName, rxContext,
     415             :             pFilterName, rFilterArguments,
     416          56 :             rName, bMustBeSuccessfull, bEncrypted );
     417             :     }
     418           0 :     catch (const packages::WrongPasswordException&)
     419             :     {
     420           0 :         return ERRCODE_SFX_WRONGPASSWORD;
     421             :     }
     422           0 :     catch (const packages::zip::ZipIOException&)
     423             :     {
     424           0 :         return ERRCODE_IO_BROKENPACKAGE;
     425             :     }
     426           0 :     catch (const uno::Exception&)
     427             :     {}
     428             : 
     429          28 :     return SD_XML_READERROR;
     430             : }
     431             : 
     432             : // -----------------------------------------------------------------------------
     433             : 
     434           7 : sal_Bool SdXMLFilter::Import( ErrCode& nError )
     435             : {
     436             :     SAL_INFO( "sd.filter", "sd cl93746 SdXMLFilter::Import" );
     437             : #ifdef TIMELOG
     438             :     OString aFile(OUStringToOString(mrMedium.GetName(), RTL_TEXTENCODING_ASCII_US));
     439             :     SAL_INFO( "sd.filter", "importing " << aFile.getStr() );
     440             : #endif
     441             : 
     442           7 :     sal_uInt32  nRet = 0;
     443             : 
     444             :     // Get service factory
     445             :     Reference< uno::XComponentContext > rxContext =
     446           7 :             comphelper::getProcessComponentContext();
     447             : 
     448             :     // -------------------------------------
     449             : 
     450           7 :     SdDrawDocument* pDoc = mrDocShell.GetDoc();
     451           7 :     pDoc->EnableUndo(false);
     452           7 :     pDoc->NewOrLoadCompleted( NEW_DOC );
     453           7 :     pDoc->CreateFirstPages();
     454           7 :     pDoc->StopWorkStartupDelay();
     455             : 
     456             :     // -------------------------------------
     457             : 
     458           7 :     mxModel->lockControllers();
     459             : 
     460             :     // -------------------------------------
     461             : 
     462             :     /** property map for import info set */
     463             :     PropertyMapEntry aImportInfoMap[] =
     464             :     {
     465             :         // necessary properties for XML progress bar at load time
     466           7 :         { MAP_LEN( "ProgressRange" ),   0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
     467           7 :         { MAP_LEN( "ProgressMax" ),     0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
     468           7 :         { MAP_LEN( "ProgressCurrent" ), 0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
     469           7 :         { MAP_LEN( "Preview" ),         0, &::getCppuType((const sal_Bool*)0),  ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
     470           7 :         { MAP_LEN( "PageLayouts" ), 0, SEQTYPE(::getCppuType((const uno::Reference< container::XNameAccess >*)0)),  ::com::sun::star::beans::PropertyAttribute::MAYBEVOID,     0},
     471             :         { MAP_LEN( "PrivateData" ), 0,
     472           7 :               &::getCppuType( (Reference<XInterface> *)0 ),
     473             :               ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     474             :         { MAP_LEN( "BaseURI" ), 0,
     475           7 :               &::getCppuType( (OUString *)0 ),
     476             :               ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     477             :         { MAP_LEN( "StreamRelPath" ), 0,
     478           7 :               &::getCppuType( (OUString *)0 ),
     479             :               ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     480             :         { MAP_LEN( "StreamName" ), 0,
     481           7 :               &::getCppuType( (OUString *)0 ),
     482             :               ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     483             :         { MAP_LEN( "BuildId" ), 0,
     484           7 :               &::getCppuType( (OUString *)0 ),
     485             :               ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     486             :         { MAP_LEN( "OrganizerMode" ), 0,
     487           7 :               &::getBooleanCppuType(),
     488             :               ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     489           7 :         { MAP_LEN( "SourceStorage" ), 0, &embed::XStorage::static_type(),
     490             :           ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     491             :         { NULL, 0, 0, NULL, 0, 0 }
     492          91 :     };
     493             : 
     494          14 :     uno::Reference< beans::XPropertySet > xInfoSet( GenericPropertySet_CreateInstance( new PropertySetInfo( aImportInfoMap ) ) );
     495           7 :     xInfoSet->setPropertyValue( "Preview" , uno::makeAny( mrDocShell.GetDoc()->IsStarDrawPreviewMode() ) );
     496             : 
     497             :     // ---- get BuildId from parent container if available
     498             : 
     499          14 :     uno::Reference< container::XChild > xChild( mxModel, uno::UNO_QUERY );
     500           7 :     if( xChild.is() )
     501             :     {
     502           7 :         uno::Reference< beans::XPropertySet > xParentSet( xChild->getParent(), uno::UNO_QUERY );
     503           7 :         if( xParentSet.is() )
     504             :         {
     505           0 :             uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xParentSet->getPropertySetInfo() );
     506           0 :             OUString sPropName( "BuildId" );
     507           0 :             if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(sPropName) )
     508             :             {
     509           0 :                 xInfoSet->setPropertyValue( sPropName, xParentSet->getPropertyValue(sPropName) );
     510           0 :             }
     511           7 :         }
     512             :     }
     513             : 
     514             :     // -------------------------------------
     515             : 
     516          14 :     Reference< io::XActiveDataSource > xSource;
     517          14 :     Reference< XInterface > xPipe;
     518          14 :     Reference< document::XGraphicObjectResolver > xGraphicResolver;
     519           7 :     SvXMLGraphicHelper *pGraphicHelper = 0;
     520          14 :     Reference< document::XEmbeddedObjectResolver > xObjectResolver;
     521           7 :     SvXMLEmbeddedObjectHelper *pObjectHelper = 0;
     522             : 
     523          14 :     Reference< lang::XComponent > xModelComp( mxModel, uno::UNO_QUERY );
     524             : 
     525             :     // -------------------------------------
     526             : 
     527             :     // try to get an XStatusIndicator from the Medium
     528           7 :     if( mbShowProgress )
     529             :     {
     530           7 :         SfxItemSet* pSet = mrMedium.GetItemSet();
     531           7 :         if(pSet)
     532             :         {
     533             :             const SfxUnoAnyItem* pItem = static_cast<const SfxUnoAnyItem*>(
     534           7 :                 pSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) );
     535           7 :             if (pItem)
     536             :             {
     537           4 :                 pItem->GetValue() >>= mxStatusIndicator;
     538             :             }
     539             :         }
     540             : 
     541           7 :         if(mxStatusIndicator.is())
     542             :         {
     543           4 :             sal_Int32 nProgressRange(1000000);
     544           4 :             sal_Int32 nProgressCurrent(0);
     545           4 :             OUString aMsg = String( SdResId( STR_LOAD_DOC ) );
     546           4 :             mxStatusIndicator->start(aMsg, nProgressRange);
     547             : 
     548             :             // set ProgressRange
     549           8 :             uno::Any aProgRange;
     550           4 :             aProgRange <<= nProgressRange;
     551           4 :             xInfoSet->setPropertyValue( "ProgressRange" , aProgRange);
     552             : 
     553             :             // set ProgressCurrent
     554           8 :             uno::Any aProgCurrent;
     555           4 :             aProgCurrent <<= nProgressCurrent;
     556           8 :             xInfoSet->setPropertyValue( "ProgressCurrent" , aProgCurrent);
     557             :         }
     558             :     }
     559             : 
     560             :     // -------------------------------------
     561             :     // get the input stream (storage or stream)
     562             :     // -------------------------------------
     563             : 
     564          14 :     SvStorageStreamRef xDocStream;
     565          14 :     Reference<io::XInputStream> xInputStream;
     566          14 :     uno::Reference < embed::XStorage > xStorage = mrMedium.GetStorage();
     567             : 
     568          14 :     OUString sSourceStorage( "SourceStorage");
     569           7 :     xInfoSet->setPropertyValue( sSourceStorage, Any( xStorage ) );
     570             : 
     571           7 :     if( !xStorage.is() )
     572           0 :         nRet = SD_XML_READERROR;
     573             : 
     574           7 :     if( 0 == nRet )
     575             :     {
     576             :         pGraphicHelper = SvXMLGraphicHelper::Create( xStorage,
     577             :                                                      GRAPHICHELPER_MODE_READ,
     578           7 :                                                      sal_False );
     579           7 :         xGraphicResolver = pGraphicHelper;
     580             :         pObjectHelper = SvXMLEmbeddedObjectHelper::Create(
     581           7 :                                     xStorage, *pDoc->GetPersist(),
     582             :                                     EMBEDDEDOBJECTHELPER_MODE_READ,
     583           7 :                                     sal_False );
     584           7 :         xObjectResolver = pObjectHelper;
     585             :     }
     586             : 
     587             :     // Set base URI
     588           7 :     xInfoSet->setPropertyValue( "BaseURI" , makeAny( mrMedium.GetBaseURL() ) );
     589             : 
     590           7 :     if( 0 == nRet && SFX_CREATE_MODE_EMBEDDED == mrDocShell.GetCreateMode() )
     591             :     {
     592           3 :         OUString aName;
     593           3 :         if ( mrMedium.GetItemSet() )
     594             :         {
     595             :             const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
     596           3 :                 mrMedium.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
     597           3 :             if ( pDocHierarchItem )
     598           0 :                 aName = pDocHierarchItem->GetValue();
     599             :         }
     600             :         else
     601           0 :             aName = "dummyObjectName" ;
     602             : 
     603           3 :         if( !aName.isEmpty() )
     604           0 :             xInfoSet->setPropertyValue( "StreamRelPath", Any( aName ) );
     605             :     }
     606             : 
     607           7 :     if (SDXMLMODE_Organizer == meFilterMode)
     608           0 :         xInfoSet->setPropertyValue("OrganizerMode", uno::makeAny(sal_True));
     609             : 
     610             :     // -------------------------------------
     611             : 
     612           7 :     if( 0 == nRet )
     613             :     {
     614             : 
     615             :         // prepare filter arguments
     616           7 :         Sequence<Any> aFilterArgs( 4 );
     617           7 :         Any *pArgs = aFilterArgs.getArray();
     618           7 :         *pArgs++ <<= xInfoSet;
     619           7 :         *pArgs++ <<= xGraphicResolver;
     620           7 :         *pArgs++ <<= xObjectResolver;
     621           7 :         *pArgs++ <<= mxStatusIndicator;
     622             : 
     623          14 :         Sequence<Any> aEmptyArgs( 2 );
     624           7 :         pArgs = aEmptyArgs.getArray();
     625           7 :         *pArgs++ <<= xInfoSet;
     626           7 :         *pArgs++ <<= mxStatusIndicator;
     627             : 
     628          14 :         const OUString aName( mrMedium.GetName() );
     629             : 
     630           7 :         XML_SERVICES* pServices = getServices( true, IsDraw(), mnStoreVer );
     631             : 
     632           7 :         sal_uInt32 nWarn = 0;
     633           7 :         sal_uInt32 nWarn2 = 0;
     634             :         // read storage streams
     635             :         // #i103539#: always read meta.xml for generator
     636             :         nWarn = ReadThroughComponent(
     637             :             xStorage, xModelComp, "meta.xml", "Meta.xml", rxContext,
     638             :             pServices->mpMeta,
     639           7 :             aEmptyArgs, aName, sal_False );
     640             : 
     641           7 :         if( meFilterMode != SDXMLMODE_Organizer )
     642             :         {
     643             :             nWarn2 = ReadThroughComponent(
     644             :                 xStorage, xModelComp, "settings.xml", NULL, rxContext,
     645             :                 pServices->mpSettings,
     646           7 :                 aFilterArgs, aName, sal_False );
     647             :         }
     648             : 
     649             :         nRet = ReadThroughComponent(
     650             :             xStorage, xModelComp, "styles.xml", NULL, rxContext,
     651             :             pServices->mpStyles,
     652           7 :             aFilterArgs, aName, sal_True );
     653             : 
     654           7 :         if( !nRet && (meFilterMode != SDXMLMODE_Organizer) )
     655             :             nRet = ReadThroughComponent(
     656             :                xStorage, xModelComp, "content.xml", "Content.xml", rxContext,
     657             :                pServices->mpContent,
     658           7 :                aFilterArgs, aName, sal_True );
     659             : 
     660           7 :         if( !nRet )
     661             :         {
     662           7 :             if( nWarn )
     663           0 :                 nRet = nWarn;
     664           7 :             else if( nWarn2 )
     665           0 :                 nRet = nWarn2;
     666           7 :         }
     667             :     }
     668             : 
     669             :     // -------------------------------------
     670           7 :     if( pGraphicHelper )
     671           7 :         SvXMLGraphicHelper::Destroy( pGraphicHelper );
     672           7 :     xGraphicResolver = 0;
     673           7 :     if( pObjectHelper )
     674           7 :         SvXMLEmbeddedObjectHelper::Destroy( pObjectHelper );
     675           7 :     xObjectResolver = 0;
     676             : 
     677           7 :     if( mxStatusIndicator.is() )
     678           4 :         mxStatusIndicator->end();
     679             : 
     680           7 :     if( mxModel.is() )
     681           7 :         mxModel->unlockControllers();
     682             : 
     683           7 :     if( nRet == 0 )
     684           7 :         pDoc->UpdateAllLinks();
     685             : 
     686           7 :     switch( nRet )
     687             :     {
     688           7 :     case 0: break;
     689           0 :     case SD_XML_READERROR: break;
     690             :     case ERRCODE_IO_BROKENPACKAGE:
     691           0 :         if( xStorage.is() )
     692             :         {
     693           0 :             nError = ERRCODE_IO_BROKENPACKAGE;
     694           0 :             break;
     695             :         }
     696             :         // fall through intented
     697             :     default:
     698             :         {
     699             :             // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly!
     700           0 :             ErrorHandler::HandleError( nRet );
     701           0 :             if( IsWarning( nRet ) )
     702           0 :                 nRet = 0;
     703             :         }
     704             :     }
     705             : 
     706             : 
     707             :     // clear unused named items from item pool
     708             : 
     709           7 :     uno::Reference< lang::XMultiServiceFactory> xModelFactory( mxModel, uno::UNO_QUERY );
     710           7 :     if( xModelFactory.is() )
     711             :     {
     712             :         try
     713             :         {
     714           7 :             const OUString aName("~clear~" );
     715          14 :             uno::Reference< container::XNameContainer > xGradient( xModelFactory->createInstance( "com.sun.star.drawing.GradientTable" ), uno::UNO_QUERY );
     716           7 :             if( xGradient.is() )
     717           7 :                 xGradient->removeByName( aName );
     718             : 
     719          14 :             uno::Reference< container::XNameContainer > xHatch( xModelFactory->createInstance( "com.sun.star.drawing.HatchTable" ), uno::UNO_QUERY );
     720           7 :             if( xHatch.is() )
     721           7 :                 xHatch->removeByName( aName );
     722             : 
     723          14 :             uno::Reference< container::XNameContainer > xBitmap( xModelFactory->createInstance( "com.sun.star.drawing.BitmapTable" ), uno::UNO_QUERY );
     724           7 :             if( xBitmap.is() )
     725           7 :                 xBitmap->removeByName( aName );
     726             : 
     727          14 :             uno::Reference< container::XNameContainer > xTransGradient( xModelFactory->createInstance( "com.sun.star.drawing.TransparencyGradientTable" ), uno::UNO_QUERY );
     728           7 :             if( xTransGradient.is() )
     729           7 :                 xTransGradient->removeByName( aName );
     730             : 
     731          14 :             uno::Reference< container::XNameContainer > xMarker( xModelFactory->createInstance( "com.sun.star.drawing.MarkerTable" ), uno::UNO_QUERY );
     732           7 :             if( xMarker.is() )
     733           7 :                 xMarker->removeByName( aName );
     734             : 
     735          14 :             uno::Reference< container::XNameContainer > xDashes( xModelFactory->createInstance( "com.sun.star.drawing.DashTable" ), uno::UNO_QUERY );
     736           7 :             if( xDashes.is() )
     737          14 :                 xDashes->removeByName( aName );
     738             :         }
     739           0 :         catch (const Exception&)
     740             :         {
     741             :             SAL_WARN( "sd.filter","sd::SdXMLFilter::Import(), exception during clearing of unused named items");
     742             :         }
     743             :     }
     744             : 
     745             :     // set BuildId on XModel for later OLE object loading
     746           7 :     if( xInfoSet.is() )
     747             :     {
     748           7 :         uno::Reference< beans::XPropertySet > xModelSet( mxModel, uno::UNO_QUERY );
     749           7 :         if( xModelSet.is() )
     750             :         {
     751           7 :             uno::Reference< beans::XPropertySetInfo > xModelSetInfo( xModelSet->getPropertySetInfo() );
     752          14 :             const OUString sPropName( "BuildId" );
     753             : 
     754          14 :             OUString sBuildId;
     755           7 :             xInfoSet->getPropertyValue(sPropName) >>= sBuildId;
     756             : 
     757           7 :             if( xModelSetInfo.is() && xModelSetInfo->hasPropertyByName(sPropName) )
     758             :             {
     759           7 :                 xModelSet->setPropertyValue( sPropName, Any( sBuildId ) );
     760             :             }
     761             : 
     762           7 :             bool bTransform = false;
     763             : 
     764           7 :             if( nRet == 0 )
     765             :             {
     766           7 :                 if( !sBuildId.isEmpty() )
     767             :                 {
     768           6 :                     sal_Int32 nIndex = sBuildId.indexOf('$');
     769           6 :                     if( nIndex != -1 )
     770             :                     {
     771           2 :                         sal_Int32 nUPD = sBuildId.copy( 0, nIndex ).toInt32();
     772             : 
     773           2 :                         if( nUPD == 300 )
     774             :                         {
     775           0 :                             sal_Int32 nBuildId = sBuildId.copy( nIndex+1 ).toInt32();
     776           0 :                             if( (nBuildId > 0) && (nBuildId < 9316) )
     777           0 :                                 bTransform = true; // treat OOo 3.0 beta1 as OOo 2.x
     778             :                         }
     779           2 :                         else if( (nUPD == 680) || ( nUPD >= 640 && nUPD <= 645 ) )
     780           0 :                             bTransform = true;
     781             :                     }
     782             :                 }
     783             :                 else
     784             :                 {
     785             :                     // check for binary formats
     786           1 :                      const SfxFilter * pFilter = mrMedium.GetFilter();
     787           1 :                     if( pFilter )
     788             :                     {
     789           1 :                         OUString typeName(pFilter->GetRealTypeName());
     790           2 :                         if( typeName.startsWith( "impress_StarImpress" ) ||
     791           1 :                             typeName.startsWith( "draw_StarDraw" ) )
     792             :                         {
     793           0 :                             bTransform = true;
     794           1 :                         }
     795             :                     }
     796             :                 }
     797             :             }
     798             : 
     799           7 :             if( bTransform )
     800           7 :                 TransformOOo2xDocument( pDoc );
     801           7 :         }
     802             :     }
     803             : 
     804           7 :     pDoc->EnableUndo(true);
     805           7 :     mrDocShell.ClearUndoBuffer();
     806          14 :     return nRet == 0;
     807             : }
     808             : 
     809             : // -----------------------------------------------------------------------------
     810             : 
     811           4 : sal_Bool SdXMLFilter::Export()
     812             : {
     813             : #ifdef TIMELOG
     814             :     SAL_INFO( "sd.filter", "sd cl93746 SdXMLFilter::Export" );
     815             :     OString aFile(OUStringToOString(mrMedium.GetName(), RTL_TEXTENCODING_ASCII_US));
     816             :     SAL_INFO( "sd.filter", "exporting " << aFile.getStr() );
     817             : #endif
     818             : 
     819           4 :     SvXMLEmbeddedObjectHelper*  pObjectHelper = NULL;
     820           4 :     SvXMLGraphicHelper*         pGraphicHelper = NULL;
     821           4 :     sal_Bool                    bDocRet = sal_False;
     822             : 
     823           4 :     if( !mxModel.is() )
     824             :     {
     825             :         SAL_WARN( "sd.filter","Got NO Model in XMLExport");
     826           0 :         return sal_False;
     827             :     }
     828             : 
     829           4 :     sal_Bool bLocked = mxModel->hasControllersLocked();
     830             : 
     831             :     try
     832             :     {
     833           4 :         mxModel->lockControllers();
     834             : 
     835           4 :         uno::Reference< lang::XServiceInfo > xServiceInfo( mxModel, uno::UNO_QUERY );
     836             : 
     837           4 :         if( !xServiceInfo.is() || !xServiceInfo->supportsService( "com.sun.star.drawing.GenericDrawingDocument" ) )
     838             :         {
     839             :             SAL_WARN( "sd.filter", "Model is no DrawingDocument in XMLExport" );
     840           0 :             return sal_False;
     841             :         }
     842             : 
     843           8 :         uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
     844             : 
     845           8 :         uno::Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create( xContext );
     846             : 
     847             :         /** property map for export info set */
     848             :         PropertyMapEntry aExportInfoMap[] =
     849             :         {
     850           4 :             { MAP_LEN( "ProgressRange" ),   0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
     851           4 :             { MAP_LEN( "ProgressMax" ),     0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
     852           4 :             { MAP_LEN( "ProgressCurrent" ), 0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
     853           4 :             { MAP_LEN( "UsePrettyPrinting"),0, &::getBooleanCppuType(),             ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
     854             : 
     855           4 :             { MAP_LEN( "PageLayoutNames" ), 0, SEQTYPE(::getCppuType((const OUString*)0)),  ::com::sun::star::beans::PropertyAttribute::MAYBEVOID,     0},
     856             :             { MAP_LEN( "BaseURI" ), 0,
     857           4 :                   &::getCppuType( (OUString *)0 ),
     858             :                   ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     859             :             { MAP_LEN( "StreamRelPath" ), 0,
     860           4 :                   &::getCppuType( (OUString *)0 ),
     861             :                   ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     862             :             { MAP_LEN( "StreamName" ), 0,
     863           4 :                   &::getCppuType( (OUString *)0 ),
     864             :                   ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     865             :             { MAP_LEN( "StyleNames" ), 0,
     866           4 :                   &::getCppuType( (Sequence<OUString>*)0 ),
     867             :                   ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     868             :             { MAP_LEN( "StyleFamilies" ), 0,
     869           4 :                   &::getCppuType( (Sequence<sal_Int32>*)0 ),
     870             :                   ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     871           4 :             { MAP_LEN( "TargetStorage" ), 0, &embed::XStorage::static_type(),
     872             :                   ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     873             : 
     874             :             { NULL, 0, 0, NULL, 0, 0 }
     875          48 :         };
     876             : 
     877           8 :         uno::Reference< beans::XPropertySet > xInfoSet( GenericPropertySet_CreateInstance( new PropertySetInfo( aExportInfoMap ) ) );
     878             : 
     879             : 
     880           8 :         SvtSaveOptions aSaveOpt;
     881           8 :         OUString sUsePrettyPrinting("UsePrettyPrinting");
     882           4 :         sal_Bool bUsePrettyPrinting( aSaveOpt.IsPrettyPrinting() );
     883           4 :         xInfoSet->setPropertyValue( sUsePrettyPrinting, makeAny( bUsePrettyPrinting ) );
     884             : 
     885           8 :         const uno::Reference < embed::XStorage >& xStorage = mrMedium.GetOutputStorage();
     886             : 
     887             :         // Set base URI
     888           8 :         OUString sPropName( "BaseURI" );
     889           4 :         xInfoSet->setPropertyValue( sPropName, makeAny( mrMedium.GetBaseURL( true ) ) );
     890             : 
     891           8 :         OUString sTargetStorage( "TargetStorage" );
     892           4 :         xInfoSet->setPropertyValue( sTargetStorage, Any( xStorage ) );
     893             : 
     894           4 :         if( SFX_CREATE_MODE_EMBEDDED == mrDocShell.GetCreateMode() )
     895             :         {
     896           0 :             OUString aName;
     897           0 :             if ( mrMedium.GetItemSet() )
     898             :             {
     899             :                 const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
     900           0 :                     mrMedium.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
     901           0 :                 if ( pDocHierarchItem )
     902           0 :                     aName = pDocHierarchItem->GetValue();
     903             :             }
     904             : 
     905           0 :             if( !aName.isEmpty() )
     906             :             {
     907           0 :                 sPropName = OUString( "StreamRelPath" );
     908           0 :                 xInfoSet->setPropertyValue( sPropName, makeAny( aName ) );
     909           0 :             }
     910             :         }
     911             : 
     912             :         // initialize descriptor
     913           8 :         uno::Sequence< beans::PropertyValue > aDescriptor( 1 );
     914           4 :         beans::PropertyValue* pProps = aDescriptor.getArray();
     915             : 
     916           4 :         pProps[0].Name = "FileName";
     917           4 :         pProps[0].Value <<= OUString( mrMedium.GetName() );
     918             : 
     919             :         {
     920           4 :             uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
     921           8 :             uno::Reference< document::XGraphicObjectResolver >  xGrfResolver;
     922             : 
     923             :             // create helper for graphic and ole export if we have a storage
     924           4 :             if( xStorage.is() )
     925             :             {
     926           4 :                 pObjectHelper = SvXMLEmbeddedObjectHelper::Create( xStorage, *mrDocShell.GetDoc()->GetPersist(), EMBEDDEDOBJECTHELPER_MODE_WRITE, sal_False );
     927           4 :                 xObjectResolver = pObjectHelper;
     928             : 
     929           4 :                 pGraphicHelper = SvXMLGraphicHelper::Create( xStorage, GRAPHICHELPER_MODE_WRITE, sal_False );
     930           4 :                 xGrfResolver = pGraphicHelper;
     931             :             }
     932             : 
     933           4 :             if(mbShowProgress)
     934             :             {
     935           4 :                 CreateStatusIndicator();
     936           4 :                 if(mxStatusIndicator.is())
     937             :                 {
     938           0 :                     sal_Int32 nProgressRange(1000000);
     939           0 :                     sal_Int32 nProgressCurrent(0);
     940           0 :                     OUString aMsg = String( SdResId( STR_SAVE_DOC ) );
     941           0 :                     mxStatusIndicator->start(aMsg, nProgressRange);
     942             : 
     943             :                     // set ProgressRange
     944           0 :                     uno::Any aProgRange;
     945           0 :                     aProgRange <<= nProgressRange;
     946           0 :                     xInfoSet->setPropertyValue( "ProgressRange" , aProgRange);
     947             : 
     948             :                     // set ProgressCurrent
     949           0 :                     uno::Any aProgCurrent;
     950           0 :                     aProgCurrent <<= nProgressCurrent;
     951           0 :                     xInfoSet->setPropertyValue( "ProgressCurrent" , aProgCurrent);
     952             :                 }
     953             :             }
     954             : 
     955           8 :             uno::Reference< lang::XComponent > xComponent( mxModel, uno::UNO_QUERY );
     956             : 
     957           4 :             XML_SERVICES* pServiceNames = getServices( false, IsDraw(), mnStoreVer );
     958             : 
     959           4 :             XML_SERVICEMAP aServices[5]; sal_uInt16 i = 0;
     960           4 :             aServices[i  ].mpService = pServiceNames->mpStyles;
     961           4 :             aServices[i++].mpStream  = sXML_styleStreamName;
     962             : 
     963           4 :             aServices[i  ].mpService = pServiceNames->mpContent;
     964           4 :             aServices[i++].mpStream  = sXML_contentStreamName;
     965             : 
     966           4 :             aServices[i  ].mpService = pServiceNames->mpSettings;
     967           4 :             aServices[i++].mpStream  = sXML_settingsStreamName;
     968             : 
     969           4 :             if( mrDocShell.GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
     970             :             {
     971           4 :                 aServices[i  ].mpService = pServiceNames->mpMeta;
     972           4 :                 aServices[i++].mpStream  = sXML_metaStreamName;
     973             :             };
     974             : 
     975           4 :             aServices[i].mpService = NULL;
     976           4 :             aServices[i].mpStream  = NULL;
     977             : 
     978           4 :             XML_SERVICEMAP* pServices = aServices;
     979             : 
     980             :             // doc export
     981          16 :             do
     982             :             {
     983             :                 SAL_INFO( "sd.filter", "exporting substream " << pServices->mpStream );
     984             : 
     985          16 :                 uno::Reference<io::XOutputStream> xDocOut;
     986          16 :                 if( xStorage.is() )
     987             :                 {
     988          16 :                     const OUString sDocName( OUString::createFromAscii( pServices->mpStream ) );
     989             :                     uno::Reference<io::XStream> xStream =
     990          16 :                             xStorage->openStreamElement( sDocName,
     991          32 :                             embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
     992             : 
     993             :                     DBG_ASSERT(xStream.is(), "Can't create output stream in package!");
     994          16 :                     if( !xStream.is() )
     995           0 :                         return sal_False;
     996             : 
     997          16 :                     xDocOut = xStream->getOutputStream();
     998          32 :                     Reference <beans::XPropertySet > xProps( xStream, uno::UNO_QUERY );
     999          16 :                     if( !xDocOut.is() || !xProps.is() )
    1000           0 :                         return sal_False;
    1001             : 
    1002          32 :                     uno::Any aAny; aAny <<= OUString( "text/xml");
    1003          16 :                     xProps->setPropertyValue( "MediaType" , aAny);
    1004             : 
    1005             :                     // encrypt all streams
    1006          16 :                     xProps->setPropertyValue( "UseCommonStoragePasswordEncryption",
    1007          16 :                                               uno::makeAny( (sal_Bool)sal_True ) );
    1008             : 
    1009          32 :                     const OUString sStreamName( "StreamName");
    1010          32 :                     xInfoSet->setPropertyValue( sStreamName, Any( sDocName ) );
    1011             :                 }
    1012             : 
    1013          32 :                 uno::Reference< io::XActiveDataSource > xDocSrc( xWriter, uno::UNO_QUERY );
    1014          16 :                 xDocSrc->setOutputStream( xDocOut );
    1015             : 
    1016          32 :                 uno::Sequence< uno::Any > aArgs( 2 + ( mxStatusIndicator.is() ? 1 : 0 ) + ( xGrfResolver.is() ? 1 : 0 ) + ( xObjectResolver.is() ? 1 : 0 ) );
    1017          16 :                 uno::Any* pArgs = aArgs.getArray();
    1018          16 :                 *pArgs++ <<= xInfoSet;
    1019          16 :                 if( xGrfResolver.is() )         *pArgs++ <<= xGrfResolver;
    1020          16 :                 if( xObjectResolver.is() )      *pArgs++ <<= xObjectResolver;
    1021          16 :                 if( mxStatusIndicator.is() )    *pArgs++ <<= mxStatusIndicator;
    1022             : 
    1023          16 :                 *pArgs   <<= xWriter;
    1024             : 
    1025          32 :                 uno::Reference< document::XFilter > xFilter( xContext->getServiceManager()->createInstanceWithArgumentsAndContext( OUString::createFromAscii( pServices->mpService ), aArgs, xContext ), uno::UNO_QUERY );
    1026          16 :                 if( xFilter.is() )
    1027             :                 {
    1028          16 :                     uno::Reference< document::XExporter > xExporter( xFilter, uno::UNO_QUERY );
    1029          16 :                     if( xExporter.is() )
    1030             :                     {
    1031          16 :                         xExporter->setSourceDocument( xComponent );
    1032             :                         // outputstream will be closed by SAX parser
    1033          16 :                         bDocRet = xFilter->filter( aDescriptor );
    1034          16 :                     }
    1035             :                 }
    1036             : 
    1037          32 :                 pServices++;
    1038             :             }
    1039          16 :             while( bDocRet && pServices->mpService );
    1040             : 
    1041           4 :             if(mbShowProgress)
    1042             :             {
    1043           4 :                 if(mxStatusIndicator.is())
    1044           0 :                     mxStatusIndicator->end();
    1045           4 :             }
    1046           4 :         }
    1047             :     }
    1048           0 :     catch (const uno::Exception &e)
    1049             :     {
    1050             : #if OSL_DEBUG_LEVEL > 1
    1051             :         SAL_WARN( "sd.filter", "uno Exception caught while exporting:" << e.Message);
    1052             : #else
    1053             :         (void)e;
    1054             : #endif
    1055           0 :         bDocRet = sal_False;
    1056             :     }
    1057           4 :     if ( !bLocked )
    1058           4 :         mxModel->unlockControllers();
    1059             : 
    1060           4 :     if( pGraphicHelper )
    1061           4 :         SvXMLGraphicHelper::Destroy( pGraphicHelper );
    1062             : 
    1063           4 :     if( pObjectHelper )
    1064           4 :         SvXMLEmbeddedObjectHelper::Destroy( pObjectHelper );
    1065             : 
    1066           4 :     return bDocRet;
    1067          33 : }
    1068             : 
    1069             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10