LCOV - code coverage report
Current view: top level - basic/source/uno - dlgcont.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 79 302 26.2 %
Date: 2012-08-25 Functions: 21 40 52.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 51 590 8.6 %

           Branch data     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 <com/sun/star/container/XNameContainer.hpp>
      21                 :            : #include <com/sun/star/xml/sax/XParser.hpp>
      22                 :            : #include <com/sun/star/xml/sax/InputSource.hpp>
      23                 :            : #include <com/sun/star/io/XOutputStream.hpp>
      24                 :            : #include <com/sun/star/io/XInputStream.hpp>
      25                 :            : #include <com/sun/star/embed/ElementModes.hpp>
      26                 :            : #include <com/sun/star/ucb/XSimpleFileAccess2.hpp>
      27                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      28                 :            : #include <com/sun/star/io/XActiveDataSource.hpp>
      29                 :            : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      30                 :            : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
      31                 :            : #include "com/sun/star/resource/XStringResourceWithStorage.hpp"
      32                 :            : #include "com/sun/star/resource/XStringResourceWithLocation.hpp"
      33                 :            : #include "com/sun/star/document/XGraphicObjectResolver.hpp"
      34                 :            : #include "dlgcont.hxx"
      35                 :            : #include "sbmodule.hxx"
      36                 :            : #include <comphelper/processfactory.hxx>
      37                 :            : #include <unotools/streamwrap.hxx>
      38                 :            : #include <osl/mutex.hxx>
      39                 :            : 
      40                 :            : #include <vcl/svapp.hxx>
      41                 :            : #include <vcl/settings.hxx>
      42                 :            : #include <unotools/pathoptions.hxx>
      43                 :            : #include <xmlscript/xmldlg_imexp.hxx>
      44                 :            : #include <cppuhelper/factory.hxx>
      45                 :            : #include <svtools/sfxecode.hxx>
      46                 :            : #include <svtools/ehdl.hxx>
      47                 :            : #include <svtools/grfmgr.hxx>
      48                 :            : 
      49                 :            : namespace basic
      50                 :            : {
      51                 :            : 
      52                 :            : using namespace com::sun::star::document;
      53                 :            : using namespace com::sun::star::container;
      54                 :            : using namespace com::sun::star::io;
      55                 :            : using namespace com::sun::star::uno;
      56                 :            : using namespace com::sun::star::ucb;
      57                 :            : using namespace com::sun::star::lang;
      58                 :            : using namespace com::sun::star::script;
      59                 :            : using namespace com::sun::star::xml::sax;
      60                 :            : using namespace com::sun::star;
      61                 :            : using namespace cppu;
      62                 :            : using namespace osl;
      63                 :            : 
      64                 :            : using ::rtl::OUString;
      65                 :            : 
      66                 :            : using com::sun::star::uno::Reference;
      67                 :            : 
      68                 :            : //============================================================================
      69                 :            : // Implementation class SfxDialogLibraryContainer
      70                 :            : 
      71                 :        187 : const sal_Char* SAL_CALL SfxDialogLibraryContainer::getInfoFileName() const { return "dialog"; }
      72                 :        187 : const sal_Char* SAL_CALL SfxDialogLibraryContainer::getOldInfoFileName() const { return "dialogs"; }
      73                 :        187 : const sal_Char* SAL_CALL SfxDialogLibraryContainer::getLibElementFileExtension() const { return "xdl"; }
      74                 :        187 : const sal_Char* SAL_CALL SfxDialogLibraryContainer::getLibrariesDir() const { return "Dialogs"; }
      75                 :            : 
      76                 :            : // Ctor for service
      77                 :         65 : SfxDialogLibraryContainer::SfxDialogLibraryContainer( void )
      78                 :            : {
      79                 :            :     // all initialisation has to be done
      80                 :            :     // by calling XInitialization::initialize
      81                 :         65 : }
      82                 :            : 
      83                 :        122 : SfxDialogLibraryContainer::SfxDialogLibraryContainer( const uno::Reference< embed::XStorage >& xStorage )
      84                 :            : {
      85         [ +  - ]:        122 :     init( OUString(), xStorage );
      86                 :        122 : }
      87                 :            : 
      88                 :            : // Methods to get library instances of the correct type
      89                 :        127 : SfxLibrary* SfxDialogLibraryContainer::implCreateLibrary( const ::rtl::OUString& aName )
      90                 :            : {
      91         [ +  - ]:        127 :     SfxLibrary* pRet = new SfxDialogLibrary( maModifiable, aName, mxMSF, mxSFI, this );
      92                 :        127 :     return pRet;
      93                 :            : }
      94                 :            : 
      95                 :        558 : SfxLibrary* SfxDialogLibraryContainer::implCreateLibraryLink
      96                 :            :     ( const ::rtl::OUString& aName, const OUString& aLibInfoFileURL,
      97                 :            :       const OUString& StorageURL, sal_Bool ReadOnly )
      98                 :            : {
      99                 :            :     SfxLibrary* pRet = new SfxDialogLibrary
     100         [ +  - ]:        558 :             ( maModifiable, aName, mxMSF, mxSFI, aLibInfoFileURL, StorageURL, ReadOnly, this );
     101                 :        558 :     return pRet;
     102                 :            : }
     103                 :            : 
     104                 :        622 : Any SAL_CALL SfxDialogLibraryContainer::createEmptyLibraryElement( void )
     105                 :            : {
     106                 :        622 :     Reference< XInputStreamProvider > xISP;
     107                 :        622 :     Any aRetAny;
     108         [ +  - ]:        622 :     aRetAny <<= xISP;
     109                 :        622 :     return aRetAny;
     110                 :            : }
     111                 :            : 
     112                 :          0 : bool SAL_CALL SfxDialogLibraryContainer::isLibraryElementValid( Any aElement ) const
     113                 :            : {
     114                 :          0 :     return SfxDialogLibrary::containsValidDialog( aElement );
     115                 :            : }
     116                 :            : 
     117                 :          0 : bool writeOasis2OOoLibraryElement(
     118                 :            :     Reference< XInputStream > xInput, Reference< XOutputStream > xOutput )
     119                 :            : {
     120                 :            :     Reference< XMultiServiceFactory > xMSF(
     121         [ #  # ]:          0 :         comphelper::getProcessServiceFactory() );
     122                 :            : 
     123                 :          0 :     Reference< XComponentContext > xContext;
     124         [ #  # ]:          0 :     Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY );
     125                 :            :     OSL_ASSERT( xProps.is() );
     126 [ #  # ][ #  # ]:          0 :     OSL_VERIFY( xProps->getPropertyValue(
         [ #  # ][ #  # ]
     127                 :            :         OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
     128                 :            : 
     129                 :            :     Reference< lang::XMultiComponentFactory > xSMgr(
     130 [ #  # ][ #  # ]:          0 :         xContext->getServiceManager() );
     131                 :            : 
     132         [ #  # ]:          0 :     if (! xSMgr.is())
     133                 :            :     {
     134                 :          0 :         return sal_False;
     135                 :            :     }
     136                 :            : 
     137                 :            :     Reference< xml::sax::XParser > xParser(
     138         [ #  # ]:          0 :         xSMgr->createInstanceWithContext(
     139                 :            :             OUString( RTL_CONSTASCII_USTRINGPARAM(
     140                 :            :                 "com.sun.star.xml.sax.Parser" ) ),
     141                 :          0 :             xContext ),
     142 [ #  # ][ #  # ]:          0 :         UNO_QUERY );
                 [ #  # ]
     143                 :            : 
     144                 :            :     Reference< xml::sax::XExtendedDocumentHandler > xWriter(
     145         [ #  # ]:          0 :         xSMgr->createInstanceWithContext(
     146                 :            :             OUString( RTL_CONSTASCII_USTRINGPARAM(
     147                 :            :                 "com.sun.star.xml.sax.Writer" ) ),
     148                 :          0 :             xContext ),
     149 [ #  # ][ #  # ]:          0 :         UNO_QUERY );
                 [ #  # ]
     150                 :            : 
     151         [ #  # ]:          0 :     Reference< io::XActiveDataSource > xSource( xWriter, UNO_QUERY );
     152 [ #  # ][ #  # ]:          0 :     xSource->setOutputStream( xOutput );
     153                 :            : 
     154 [ #  # ][ #  # ]:          0 :     if ( !xParser.is() || !xWriter.is() )
                 [ #  # ]
     155                 :            :     {
     156                 :          0 :         return sal_False;
     157                 :            :     }
     158                 :            : 
     159         [ #  # ]:          0 :     Sequence<Any> aArgs( 1 );
     160 [ #  # ][ #  # ]:          0 :     aArgs[0] <<= xWriter;
     161                 :            : 
     162                 :            :     Reference< xml::sax::XDocumentHandler > xHandler(
     163         [ #  # ]:          0 :         xSMgr->createInstanceWithArgumentsAndContext(
     164                 :            :             OUString( RTL_CONSTASCII_USTRINGPARAM(
     165                 :            :                 "com.sun.star.comp.Oasis2OOoTransformer" ) ),
     166                 :          0 :             aArgs, xContext ),
     167 [ #  # ][ #  # ]:          0 :         UNO_QUERY );
                 [ #  # ]
     168                 :            : 
     169 [ #  # ][ #  # ]:          0 :     xParser->setDocumentHandler( xHandler );
     170                 :            : 
     171         [ #  # ]:          0 :     xml::sax::InputSource source;
     172         [ #  # ]:          0 :     source.aInputStream = xInput;
     173         [ #  # ]:          0 :     source.sSystemId = OUString(RTL_CONSTASCII_USTRINGPARAM("virtual file"));
     174                 :            : 
     175 [ #  # ][ #  # ]:          0 :     xParser->parseStream( source );
     176                 :            : 
     177 [ #  # ][ #  # ]:          0 :     return sal_True;
     178                 :            : }
     179                 :            : 
     180                 :          0 : void SAL_CALL SfxDialogLibraryContainer::writeLibraryElement
     181                 :            : (
     182                 :            :     const Reference < XNameContainer >& xLib,
     183                 :            :     const OUString& aElementName,
     184                 :            :     const Reference< XOutputStream >& xOutput
     185                 :            : )
     186                 :            :     throw(Exception)
     187                 :            : {
     188 [ #  # ][ #  # ]:          0 :     Any aElement = xLib->getByName( aElementName );
     189                 :          0 :     Reference< XInputStreamProvider > xISP;
     190         [ #  # ]:          0 :     aElement >>= xISP;
     191         [ #  # ]:          0 :     if( !xISP.is() )
     192                 :          0 :         return;
     193                 :            : 
     194 [ #  # ][ #  # ]:          0 :     Reference< XInputStream > xInput( xISP->createInputStream() );
     195                 :            : 
     196                 :          0 :     bool bComplete = false;
     197         [ #  # ]:          0 :     if ( mbOasis2OOoFormat )
     198                 :            :     {
     199         [ #  # ]:          0 :         bComplete = writeOasis2OOoLibraryElement( xInput, xOutput );
     200                 :            :     }
     201                 :            : 
     202         [ #  # ]:          0 :     if ( bComplete == sal_False )
     203                 :            :     {
     204         [ #  # ]:          0 :         Sequence< sal_Int8 > bytes;
     205 [ #  # ][ #  # ]:          0 :         sal_Int32 nRead = xInput->readBytes( bytes, xInput->available() );
         [ #  # ][ #  # ]
     206                 :          0 :         for (;;)
     207                 :            :         {
     208         [ #  # ]:          0 :             if( nRead )
     209 [ #  # ][ #  # ]:          0 :                 xOutput->writeBytes( bytes );
     210                 :            : 
     211 [ #  # ][ #  # ]:          0 :             nRead = xInput->readBytes( bytes, 1024 );
     212         [ #  # ]:          0 :             if (! nRead)
     213                 :          0 :                 break;
     214         [ #  # ]:          0 :         }
     215                 :            :     }
     216 [ #  # ][ #  # ]:          0 :     xInput->closeInput();
         [ #  # ][ #  # ]
     217                 :            : }
     218                 :            : 
     219                 :         28 : void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< embed::XStorage >& xStorage ) throw ( RuntimeException )
     220                 :            : {
     221         [ +  - ]:         28 :     LibraryContainerMethodGuard aGuard( *this );
     222                 :         28 :     mbOasis2OOoFormat = false;
     223                 :            : 
     224 [ +  - ][ +  - ]:         28 :     if ( mxStorage.is() && xStorage.is() )
                 [ +  - ]
     225                 :            :     {
     226                 :            :         try
     227                 :            :         {
     228         [ +  - ]:         28 :             long nSource = SotStorage::GetVersion( mxStorage );
     229         [ +  - ]:         28 :             long nTarget = SotStorage::GetVersion( xStorage );
     230                 :            : 
     231 [ +  - ][ +  + ]:         28 :             if ( nSource == SOFFICE_FILEFORMAT_CURRENT &&
     232                 :            :                 nTarget != SOFFICE_FILEFORMAT_CURRENT )
     233                 :            :             {
     234                 :         10 :                 mbOasis2OOoFormat = true;
     235                 :            :             }
     236                 :            :         }
     237         [ #  # ]:          0 :         catch (const Exception& )
     238                 :            :         {
     239                 :            :             // if we cannot get the version then the
     240                 :            :             // Oasis2OOoTransformer will not be used
     241                 :            :             OSL_ASSERT(sal_False);
     242                 :            :         }
     243                 :            :     }
     244                 :            : 
     245         [ +  - ]:         28 :     SfxLibraryContainer::storeLibrariesToStorage( xStorage );
     246                 :            : 
     247                 :            :     // we need to export out any embedded image object(s)
     248                 :            :     // associated with any Dialogs. First, we need to actually gather any such urls
     249                 :            :     // for each dialog in this container
     250         [ +  - ]:         28 :     Sequence< OUString > sLibraries = getElementNames();
     251         [ +  + ]:         56 :     for ( sal_Int32 i=0; i < sLibraries.getLength(); ++i )
     252                 :            :     {
     253 [ +  - ][ +  - ]:         28 :         loadLibrary( sLibraries[ i ] );
     254                 :         28 :         Reference< XNameContainer > xLib;
     255 [ +  - ][ +  - ]:         28 :         getByName( sLibraries[ i ] ) >>= xLib;
                 [ +  - ]
     256         [ +  - ]:         28 :         if ( xLib.is() )
     257                 :            :         {
     258 [ +  - ][ +  - ]:         28 :             Sequence< OUString > sDialogs = xLib->getElementNames();
     259                 :         28 :             sal_Int32 nDialogs( sDialogs.getLength() );
     260         [ -  + ]:         28 :             for ( sal_Int32 j=0; j < nDialogs; ++j )
     261                 :            :             {
     262                 :            :                 // Each Dialog has an associated xISP
     263                 :          0 :                 Reference< io::XInputStreamProvider > xISP;
     264 [ #  # ][ #  # ]:          0 :                 xLib->getByName( sDialogs[ j ] ) >>= xISP;
         [ #  # ][ #  # ]
     265         [ #  # ]:          0 :                 if ( xISP.is() )
     266                 :            :                 {
     267 [ #  # ][ #  # ]:          0 :                     Reference< io::XInputStream > xInput( xISP->createInputStream() );
     268         [ #  # ]:          0 :                     Reference< XNameContainer > xDialogModel( mxMSF->createInstance
     269 [ #  # ][ #  # ]:          0 :                         ( OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY );
                 [ #  # ]
     270                 :          0 :                     Reference< XComponentContext > xContext;
     271         [ #  # ]:          0 :                     Reference< beans::XPropertySet > xProps( mxMSF, UNO_QUERY );
     272                 :            :                     OSL_ASSERT( xProps.is() );
     273 [ #  # ][ #  # ]:          0 :                     OSL_VERIFY( xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
         [ #  # ][ #  # ]
     274 [ #  # ][ #  # ]:          0 :                     ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, mxOwnerDocument );
     275         [ #  # ]:          0 :                     std::vector< rtl::OUString > vEmbeddedImageURLs;
     276 [ #  # ][ #  # ]:          0 :                     GraphicObject::InspectForGraphicObjectImageURL( Reference< XInterface >( xDialogModel, UNO_QUERY ),  vEmbeddedImageURLs );
     277         [ #  # ]:          0 :                     if ( !vEmbeddedImageURLs.empty() )
     278                 :            :                     {
     279                 :            :                         // Export the images to the storage
     280         [ #  # ]:          0 :                         Sequence< Any > aArgs( 1 );
     281 [ #  # ][ #  # ]:          0 :                         aArgs[ 0 ] <<= xStorage;
     282 [ #  # ][ #  # ]:          0 :                         Reference< document::XGraphicObjectResolver > xGraphicResolver( mxMSF->createInstanceWithArguments(  OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Svx.GraphicExportHelper" ) ), aArgs ), UNO_QUERY );
         [ #  # ][ #  # ]
     283                 :          0 :                         std::vector< rtl::OUString >::iterator it = vEmbeddedImageURLs.begin();
     284                 :          0 :                         std::vector< rtl::OUString >::iterator it_end = vEmbeddedImageURLs.end();
     285         [ #  # ]:          0 :                         if ( xGraphicResolver.is() )
     286                 :            :                         {
     287 [ #  # ][ #  # ]:          0 :                             for ( sal_Int32 count = 0; it != it_end; ++it, ++count )
     288 [ #  # ][ #  # ]:          0 :                                 xGraphicResolver->resolveGraphicObjectURL( *it );
     289         [ #  # ]:          0 :                         }
     290                 :          0 :                     }
     291                 :            :                 }
     292         [ +  - ]:         28 :             }
     293                 :            :         }
     294                 :         28 :     }
     295 [ +  - ][ +  - ]:         28 :     mbOasis2OOoFormat = false;
     296         [ #  # ]:         28 : }
     297                 :            : 
     298                 :            : 
     299                 :          0 : Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement
     300                 :            :     ( const Reference < XNameContainer >& /*xLib*/,
     301                 :            :       const OUString& /*aElementName */, const OUString& aFile,
     302                 :            :       const uno::Reference< io::XInputStream >& xElementStream )
     303                 :            : {
     304                 :          0 :     Any aRetAny;
     305                 :            : 
     306                 :            :     // TODO: Member because later it will be a component
     307                 :            :     //Reference< XMultiServiceFactory > xMSF( comphelper::getProcessServiceFactory() );
     308                 :            :     //if( !xMSF.is() )
     309                 :            :     //{
     310                 :            :     //  OSL_FAIL( "### couldn't get ProcessServiceFactory\n" );
     311                 :            :     //  return aRetAny;
     312                 :            :     //}
     313                 :            : 
     314         [ #  # ]:          0 :     Reference< XParser > xParser( mxMSF->createInstance(
     315 [ #  # ][ #  # ]:          0 :         OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ) ), UNO_QUERY );
                 [ #  # ]
     316         [ #  # ]:          0 :     if( !xParser.is() )
     317                 :            :     {
     318                 :            :         OSL_FAIL( "### couldn't create sax parser component\n" );
     319                 :            :         return aRetAny;
     320                 :            :     }
     321                 :            : 
     322         [ #  # ]:          0 :     Reference< XNameContainer > xDialogModel( mxMSF->createInstance
     323 [ #  # ][ #  # ]:          0 :         ( OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY );
                 [ #  # ]
     324         [ #  # ]:          0 :     if( !xDialogModel.is() )
     325                 :            :     {
     326                 :            :         OSL_FAIL( "### couldn't create com.sun.star.awt.UnoControlDialogModel component\n" );
     327                 :            :         return aRetAny;
     328                 :            :     }
     329                 :            : 
     330                 :            :     // Read from storage?
     331                 :          0 :     sal_Bool bStorage = xElementStream.is();
     332                 :          0 :     Reference< XInputStream > xInput;
     333                 :            : 
     334         [ #  # ]:          0 :     if( bStorage )
     335                 :            :     {
     336         [ #  # ]:          0 :         xInput = xElementStream;
     337                 :            :     }
     338                 :            :     else
     339                 :            :     {
     340                 :            :         try
     341                 :            :         {
     342 [ #  # ][ #  # ]:          0 :             xInput = mxSFI->openFileRead( aFile );
         [ #  # ][ #  # ]
     343                 :            :         }
     344         [ #  # ]:          0 :         catch(const Exception& )
     345                 :            :         //catch( Exception& e )
     346                 :            :         {
     347                 :            :             // TODO:
     348                 :            :             //throw WrappedTargetException( e );
     349                 :            :         }
     350                 :            :     }
     351         [ #  # ]:          0 :     if( !xInput.is() )
     352                 :            :         return aRetAny;
     353                 :            : 
     354                 :          0 :     Reference< XComponentContext > xContext;
     355         [ #  # ]:          0 :     Reference< beans::XPropertySet > xProps( mxMSF, UNO_QUERY );
     356                 :            :     OSL_ASSERT( xProps.is() );
     357 [ #  # ][ #  # ]:          0 :     OSL_VERIFY( xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
         [ #  # ][ #  # ]
     358                 :            : 
     359         [ #  # ]:          0 :     InputSource source;
     360         [ #  # ]:          0 :     source.aInputStream = xInput;
     361                 :          0 :     source.sSystemId    = aFile;
     362                 :            : 
     363                 :            :     try {
     364                 :            :         // start parsing
     365 [ #  # ][ #  # ]:          0 :         xParser->setDocumentHandler( ::xmlscript::importDialogModel( xDialogModel, xContext, mxOwnerDocument ) );
         [ #  # ][ #  # ]
     366 [ #  # ][ #  # ]:          0 :         xParser->parseStream( source );
     367                 :            :     }
     368   [ #  #  #  # ]:          0 :     catch(const Exception& )
     369                 :            :     {
     370                 :            :         OSL_FAIL( "Parsing error\n" );
     371   [ #  #  #  #  :          0 :         SfxErrorContext aEc( ERRCTX_SFX_LOADBASIC, aFile );
                   #  # ]
     372                 :          0 :         sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
     373         [ #  # ]:          0 :         ErrorHandler::HandleError( nErrorCode );
     374         [ #  # ]:          0 :         return aRetAny;
     375                 :            :     }
     376                 :            : 
     377                 :            :     // Create InputStream, TODO: Implement own InputStreamProvider
     378                 :            :     // to avoid creating the DialogModel here!
     379 [ #  # ][ #  # ]:          0 :     Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, mxOwnerDocument );
     380         [ #  # ]:          0 :     aRetAny <<= xISP;
     381         [ #  # ]:          0 :     return aRetAny;
     382                 :            : }
     383                 :            : 
     384                 :          0 : void SAL_CALL SfxDialogLibraryContainer::importFromOldStorage( const OUString& )
     385                 :            : {
     386                 :            :     // Nothing to do here, old dialogs cannot be imported
     387                 :          0 : }
     388                 :            : 
     389                 :          0 : SfxLibraryContainer* SfxDialogLibraryContainer::createInstanceImpl( void )
     390                 :            : {
     391         [ #  # ]:          0 :     return new SfxDialogLibraryContainer();
     392                 :            : }
     393                 :            : 
     394                 :            : const char aResourceFileNameBase[] = "DialogStrings";
     395                 :            : const char aResourceFileCommentBase[] = "# Strings for Dialog Library ";
     396                 :            : 
     397                 :            : // Resource handling
     398                 :            : Reference< ::com::sun::star::resource::XStringResourcePersistence >
     399                 :          0 :     SfxDialogLibraryContainer::implCreateStringResource( SfxDialogLibrary* pDialogLibrary )
     400                 :            : {
     401                 :          0 :     Reference< resource::XStringResourcePersistence > xRet;
     402                 :          0 :     OUString aLibName = pDialogLibrary->getName();
     403                 :          0 :     bool bReadOnly = pDialogLibrary->mbReadOnly;
     404                 :            : 
     405                 :            :     // get ui locale
     406 [ #  # ][ #  # ]:          0 :     ::com::sun  ::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
     407                 :            : 
     408                 :          0 :     OUString aComment(aResourceFileCommentBase);
     409                 :          0 :     aComment += aLibName;
     410                 :            : 
     411                 :          0 :     sal_Bool bStorage = mxStorage.is();
     412         [ #  # ]:          0 :     if( bStorage )
     413                 :            :     {
     414         [ #  # ]:          0 :         Sequence<Any> aArgs( 5 );
     415 [ #  # ][ #  # ]:          0 :         aArgs[1] <<= bReadOnly;
     416 [ #  # ][ #  # ]:          0 :         aArgs[2] <<= aLocale;
     417 [ #  # ][ #  # ]:          0 :         aArgs[3] <<= rtl::OUString(aResourceFileNameBase);
     418 [ #  # ][ #  # ]:          0 :         aArgs[4] <<= aComment;
     419                 :            : 
     420                 :            :         // TODO: Ctor
     421         [ #  # ]:          0 :         xRet = Reference< resource::XStringResourcePersistence >( mxMSF->createInstance
     422 [ #  # ][ #  # ]:          0 :             ( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.resource.StringResourceWithStorage")) ), UNO_QUERY );
         [ #  # ][ #  # ]
     423                 :            : 
     424                 :          0 :         uno::Reference< embed::XStorage > xLibrariesStor;
     425                 :          0 :         uno::Reference< embed::XStorage > xLibraryStor;
     426                 :            :         try {
     427 [ #  # ][ #  # ]:          0 :             xLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READ );
                 [ #  # ]
     428                 :            :                 // TODO: Should be READWRITE with new storage concept using store() instead of storeTo()
     429         [ #  # ]:          0 :             if ( !xLibrariesStor.is() )
     430         [ #  # ]:          0 :                 throw uno::RuntimeException();
     431                 :            : 
     432 [ #  # ][ #  # ]:          0 :             xLibraryStor = xLibrariesStor->openStorageElement( aLibName, embed::ElementModes::READ );
                 [ #  # ]
     433                 :            :                 // TODO: Should be READWRITE with new storage concept using store() instead of storeTo()
     434         [ #  # ]:          0 :             if ( !xLibraryStor.is() )
     435 [ #  # ][ #  # ]:          0 :                 throw uno::RuntimeException();
     436                 :            : 
     437 [ #  # ][ #  # ]:          0 :             aArgs[0] <<= xLibraryStor;
     438                 :            :         }
     439         [ #  # ]:          0 :         catch(const uno::Exception& )
     440                 :            :         {
     441                 :            :             // TODO: Error handling?
     442                 :            :             return xRet;
     443                 :            :         }
     444                 :            : 
     445                 :            :         // TODO: Ctor
     446         [ #  # ]:          0 :         if( xRet.is() )
     447                 :            :         {
     448         [ #  # ]:          0 :             Reference< XInitialization > xInit( xRet, UNO_QUERY );
     449         [ #  # ]:          0 :             if( xInit.is() )
     450 [ #  # ][ #  # ]:          0 :                 xInit->initialize( aArgs );
     451 [ #  # ][ #  # ]:          0 :         }
         [ #  # ][ #  # ]
     452                 :            :     }
     453                 :            :     else
     454                 :            :     {
     455         [ #  # ]:          0 :         Sequence<Any> aArgs( 6 );
     456                 :            : 
     457         [ #  # ]:          0 :         OUString aLocation = createAppLibraryFolder( pDialogLibrary, aLibName );
     458 [ #  # ][ #  # ]:          0 :         aArgs[0] <<= aLocation;
     459 [ #  # ][ #  # ]:          0 :         aArgs[1] <<= bReadOnly;
     460 [ #  # ][ #  # ]:          0 :         aArgs[2] <<= aLocale;
     461 [ #  # ][ #  # ]:          0 :         aArgs[3] <<= rtl::OUString(aResourceFileNameBase);
     462 [ #  # ][ #  # ]:          0 :         aArgs[4] <<= aComment;
     463                 :            : 
     464                 :            :         // TODO: Real handler?
     465                 :          0 :         Reference< task::XInteractionHandler > xDummyHandler;
     466 [ #  # ][ #  # ]:          0 :         aArgs[5] <<= xDummyHandler;
     467                 :            : 
     468                 :            :         // TODO: Ctor
     469         [ #  # ]:          0 :         xRet = Reference< resource::XStringResourcePersistence >( mxMSF->createInstance
     470 [ #  # ][ #  # ]:          0 :             ( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.resource.StringResourceWithLocation")) ), UNO_QUERY );
         [ #  # ][ #  # ]
     471                 :            : 
     472                 :            :         // TODO: Ctor
     473         [ #  # ]:          0 :         if( xRet.is() )
     474                 :            :         {
     475         [ #  # ]:          0 :             Reference< XInitialization > xInit( xRet, UNO_QUERY );
     476         [ #  # ]:          0 :             if( xInit.is() )
     477 [ #  # ][ #  # ]:          0 :                 xInit->initialize( aArgs );
     478         [ #  # ]:          0 :         }
     479                 :            :     }
     480                 :            : 
     481                 :          0 :     return xRet;
     482                 :            : }
     483                 :            : 
     484                 :         36 : void SfxDialogLibraryContainer::onNewRootStorage()
     485                 :            : {
     486                 :            :     // the library container is not modified, go through the libraries and check whether they are modified
     487         [ +  - ]:         36 :     Sequence< OUString > aNames = maNameContainer.getElementNames();
     488                 :         36 :     const OUString* pNames = aNames.getConstArray();
     489                 :         36 :     sal_Int32 nNameCount = aNames.getLength();
     490                 :            : 
     491         [ +  + ]:         72 :     for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
     492                 :            :     {
     493                 :         36 :         OUString aName = pNames[ i ];
     494 [ +  - ][ +  - ]:         36 :         SfxDialogLibrary* pDialogLibrary = static_cast<SfxDialogLibrary*>( getImplLib( aName ) );
                 [ +  - ]
     495                 :            : 
     496                 :            :         Reference< resource::XStringResourcePersistence > xStringResourcePersistence =
     497         [ +  - ]:         36 :             pDialogLibrary->getStringResourcePersistence();
     498                 :            : 
     499         [ -  + ]:         36 :         if( xStringResourcePersistence.is() )
     500                 :            :         {
     501                 :          0 :             Reference< embed::XStorage > xLibrariesStor;
     502                 :          0 :             Reference< embed::XStorage > xLibraryStor;
     503                 :            :             try {
     504 [ #  # ][ #  # ]:          0 :                 xLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READWRITE );
                 [ #  # ]
     505         [ #  # ]:          0 :                 if ( !xLibrariesStor.is() )
     506         [ #  # ]:          0 :                     throw uno::RuntimeException();
     507                 :            : 
     508                 :          0 :                 OUString aLibName = pDialogLibrary->getName();
     509 [ #  # ][ #  # ]:          0 :                 xLibraryStor = xLibrariesStor->openStorageElement( aLibName, embed::ElementModes::READWRITE );
                 [ #  # ]
     510         [ #  # ]:          0 :                 if ( !xLibraryStor.is() )
     511         [ #  # ]:          0 :                     throw uno::RuntimeException();
     512                 :            : 
     513                 :            :                 Reference< resource::XStringResourceWithStorage >
     514         [ #  # ]:          0 :                     xStringResourceWithStorage( xStringResourcePersistence, UNO_QUERY );
     515         [ #  # ]:          0 :                 if( xStringResourceWithStorage.is() )
     516 [ #  # ][ #  # ]:          0 :                     xStringResourceWithStorage->setStorage( xLibraryStor );
                 [ #  # ]
     517                 :            :             }
     518         [ #  # ]:          0 :             catch(const uno::Exception& )
     519                 :            :             {
     520                 :            :                 // TODO: Error handling?
     521                 :          0 :             }
     522                 :            :         }
     523         [ +  - ]:         72 :     }
     524                 :         36 : }
     525                 :            : 
     526                 :            : sal_Bool SAL_CALL
     527                 :          0 : SfxDialogLibraryContainer:: HasExecutableCode( const ::rtl::OUString& /*Library*/ ) throw (uno::RuntimeException)
     528                 :            : {
     529                 :          0 :     return sal_False; // dialog library has no executable code
     530                 :            : }
     531                 :            : //============================================================================
     532                 :            : // Service
     533                 :            : 
     534                 :        123 : void createRegistryInfo_SfxDialogLibraryContainer()
     535                 :            : {
     536 [ +  + ][ +  - ]:        123 :     static OAutoRegistration< SfxDialogLibraryContainer > aAutoRegistration;
         [ +  - ][ #  # ]
     537                 :        123 : }
     538                 :            : 
     539                 :          0 : ::rtl::OUString SAL_CALL SfxDialogLibraryContainer::getImplementationName( ) throw (RuntimeException)
     540                 :            : {
     541                 :          0 :     return getImplementationName_static();
     542                 :            : }
     543                 :            : 
     544                 :          0 : Sequence< ::rtl::OUString > SAL_CALL SfxDialogLibraryContainer::getSupportedServiceNames( ) throw (RuntimeException)
     545                 :            : {
     546                 :          0 :     return getSupportedServiceNames_static();
     547                 :            : }
     548                 :            : 
     549                 :         97 : Sequence< OUString > SfxDialogLibraryContainer::getSupportedServiceNames_static()
     550                 :            : {
     551                 :         97 :     Sequence< OUString > aServiceNames( 2 );
     552 [ +  - ][ +  - ]:         97 :     aServiceNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.DocumentDialogLibraryContainer"));
     553                 :            :     // plus, for compatibility:
     554 [ +  - ][ +  - ]:         97 :     aServiceNames[1] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.DialogLibraryContainer"));
     555                 :         97 :     return aServiceNames;
     556                 :            : }
     557                 :            : 
     558                 :         97 : OUString SfxDialogLibraryContainer::getImplementationName_static()
     559                 :            : {
     560                 :         97 :     return OUString("com.sun.star.comp.sfx2.DialogLibraryContainer");
     561                 :            : }
     562                 :            : 
     563                 :         65 : Reference< XInterface > SAL_CALL SfxDialogLibraryContainer::Create( const Reference< XComponentContext >& ) throw( Exception )
     564                 :            : {
     565                 :            :     Reference< XInterface > xRet =
     566 [ +  - ][ +  - ]:         65 :         static_cast< XInterface* >( static_cast< OWeakObject* >(new SfxDialogLibraryContainer()) );
     567                 :         65 :     return xRet;
     568                 :            : }
     569                 :            : 
     570                 :            : 
     571                 :            : //============================================================================
     572                 :            : // Implementation class SfxDialogLibrary
     573                 :            : 
     574                 :            : // Ctor
     575                 :        127 : SfxDialogLibrary::SfxDialogLibrary( ModifiableHelper& _rModifiable,
     576                 :            :                                     const ::rtl::OUString& aName,
     577                 :            :                                     const Reference< XMultiServiceFactory >& xMSF,
     578                 :            :                                     const Reference< XSimpleFileAccess2 >& xSFI,
     579                 :            :                                     SfxDialogLibraryContainer* pParent )
     580                 :        127 :     : SfxLibrary( _rModifiable, getCppuType( (const Reference< XInputStreamProvider > *)0 ), xMSF, xSFI )
     581                 :            :     , m_pParent( pParent )
     582                 :        127 :     , m_aName( aName )
     583                 :            : {
     584                 :        127 : }
     585                 :            : 
     586                 :        558 : SfxDialogLibrary::SfxDialogLibrary( ModifiableHelper& _rModifiable,
     587                 :            :                                     const ::rtl::OUString& aName,
     588                 :            :                                     const Reference< XMultiServiceFactory >& xMSF,
     589                 :            :                                     const Reference< XSimpleFileAccess2 >& xSFI,
     590                 :            :                                     const OUString& aLibInfoFileURL,
     591                 :            :                                     const OUString& aStorageURL,
     592                 :            :                                     sal_Bool ReadOnly,
     593                 :            :                                     SfxDialogLibraryContainer* pParent )
     594                 :        558 :     : SfxLibrary( _rModifiable, getCppuType( (const Reference< XInputStreamProvider > *)0 ),
     595                 :            :                        xMSF, xSFI, aLibInfoFileURL, aStorageURL, ReadOnly)
     596                 :            :     , m_pParent( pParent )
     597                 :        558 :     , m_aName( aName )
     598                 :            : {
     599                 :        558 : }
     600                 :            : 
     601 [ -  + ][ #  # ]:      26060 : IMPLEMENT_FORWARD_XINTERFACE2( SfxDialogLibrary, SfxLibrary, SfxDialogLibrary_BASE );
     602 [ #  # ][ #  # ]:          0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( SfxDialogLibrary, SfxLibrary, SfxDialogLibrary_BASE );
                 [ #  # ]
     603                 :            : 
     604                 :            : // Provide modify state including resources
     605                 :         28 : sal_Bool SfxDialogLibrary::isModified( void )
     606                 :            : {
     607                 :         28 :     sal_Bool bRet = implIsModified();
     608                 :            : 
     609 [ #  # ][ -  + ]:         28 :     if( !bRet && m_xStringResourcePersistence.is() )
                 [ -  + ]
     610                 :          0 :         bRet = m_xStringResourcePersistence->isModified();
     611                 :            :     // else: Resources not accessed so far -> not modified
     612                 :            : 
     613                 :         28 :     return bRet;
     614                 :            : }
     615                 :            : 
     616                 :          0 : void SfxDialogLibrary::storeResources( void )
     617                 :            : {
     618         [ #  # ]:          0 :     if( m_xStringResourcePersistence.is() )
     619                 :          0 :         m_xStringResourcePersistence->store();
     620                 :          0 : }
     621                 :            : 
     622                 :          0 : void SfxDialogLibrary::storeResourcesAsURL
     623                 :            :     ( const ::rtl::OUString& URL, const ::rtl::OUString& NewName )
     624                 :            : {
     625                 :          0 :     OUString aComment(aResourceFileCommentBase);
     626                 :          0 :     m_aName = NewName;
     627                 :          0 :     aComment += m_aName;
     628                 :            : 
     629         [ #  # ]:          0 :     if( m_xStringResourcePersistence.is() )
     630                 :            :     {
     631 [ #  # ][ #  # ]:          0 :         m_xStringResourcePersistence->setComment( aComment );
     632                 :            : 
     633                 :            :         Reference< resource::XStringResourceWithLocation >
     634         [ #  # ]:          0 :             xStringResourceWithLocation( m_xStringResourcePersistence, UNO_QUERY );
     635         [ #  # ]:          0 :         if( xStringResourceWithLocation.is() )
     636 [ #  # ][ #  # ]:          0 :             xStringResourceWithLocation->storeAsURL( URL );
     637                 :          0 :     }
     638                 :          0 : }
     639                 :            : 
     640                 :          0 : void SfxDialogLibrary::storeResourcesToURL( const OUString& URL,
     641                 :            :     const Reference< task::XInteractionHandler >& xHandler )
     642                 :            : {
     643                 :          0 :     OUString aComment(aResourceFileCommentBase);
     644                 :          0 :     aComment += m_aName;
     645                 :            : 
     646         [ #  # ]:          0 :     if( m_xStringResourcePersistence.is() )
     647                 :            :     {
     648         [ #  # ]:          0 :         m_xStringResourcePersistence->storeToURL
     649         [ #  # ]:          0 :             ( URL, rtl::OUString(aResourceFileNameBase), aComment, xHandler );
     650                 :          0 :     }
     651                 :          0 : }
     652                 :            : 
     653                 :          0 : void SfxDialogLibrary::storeResourcesToStorage( const ::com::sun::star::uno::Reference
     654                 :            :     < ::com::sun::star::embed::XStorage >& xStorage )
     655                 :            : {
     656                 :          0 :     OUString aComment(aResourceFileCommentBase);
     657                 :          0 :     aComment += m_aName;
     658                 :            : 
     659         [ #  # ]:          0 :     if( m_xStringResourcePersistence.is() )
     660                 :            :     {
     661         [ #  # ]:          0 :         m_xStringResourcePersistence->storeToStorage
     662         [ #  # ]:          0 :             ( xStorage, rtl::OUString(aResourceFileNameBase), aComment );
     663                 :          0 :     }
     664                 :          0 : }
     665                 :            : 
     666                 :            : 
     667                 :            : // XStringResourceSupplier
     668                 :            : Reference< resource::XStringResourceResolver >
     669                 :          0 :     SAL_CALL SfxDialogLibrary::getStringResource(  ) throw (RuntimeException)
     670                 :            : {
     671         [ #  # ]:          0 :     if( !m_xStringResourcePersistence.is() )
     672         [ #  # ]:          0 :         m_xStringResourcePersistence = m_pParent->implCreateStringResource( this );
     673                 :            : 
     674                 :          0 :     Reference< resource::XStringResourceResolver > xRet( m_xStringResourcePersistence, UNO_QUERY );
     675                 :          0 :     return xRet;
     676                 :            : }
     677                 :            : 
     678                 :          0 : bool SfxDialogLibrary::containsValidDialog( const ::com::sun::star::uno::Any& aElement )
     679                 :            : {
     680                 :          0 :     Reference< XInputStreamProvider > xISP;
     681         [ #  # ]:          0 :     aElement >>= xISP;
     682                 :          0 :     return xISP.is();
     683                 :            : }
     684                 :            : 
     685                 :          0 : bool SAL_CALL SfxDialogLibrary::isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const
     686                 :            : {
     687                 :          0 :     return SfxDialogLibrary::containsValidDialog( aElement );
     688                 :            : }
     689                 :            : 
     690                 :            : }
     691                 :            : 
     692                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10