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

Generated by: LCOV version 1.11