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

Generated by: LCOV version 1.10