LCOV - code coverage report
Current view: top level - basic/source/uno - namecont.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 803 1618 49.6 %
Date: 2014-04-11 Functions: 70 116 60.3 %
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 <config_features.h>
      21             : #include <config_folders.h>
      22             : 
      23             : #include <com/sun/star/container/XNameContainer.hpp>
      24             : #include <com/sun/star/container/XContainer.hpp>
      25             : #include <com/sun/star/embed/ElementModes.hpp>
      26             : #include <com/sun/star/embed/XTransactedObject.hpp>
      27             : #include <com/sun/star/lang/XServiceInfo.hpp>
      28             : #include <vcl/svapp.hxx>
      29             : #include <osl/mutex.hxx>
      30             : #include <tools/errinf.hxx>
      31             : #include <rtl/ustring.hxx>
      32             : #include <rtl/uri.hxx>
      33             : #include <rtl/strbuf.hxx>
      34             : #include <comphelper/processfactory.hxx>
      35             : #include <comphelper/anytostring.hxx>
      36             : 
      37             : #include "namecont.hxx"
      38             : #include <basic/basicmanagerrepository.hxx>
      39             : #include <tools/diagnose_ex.h>
      40             : #include <tools/urlobj.hxx>
      41             : #include <unotools/streamwrap.hxx>
      42             : #include <unotools/pathoptions.hxx>
      43             : #include <svtools/sfxecode.hxx>
      44             : #include <svtools/ehdl.hxx>
      45             : #include <basic/basmgr.hxx>
      46             : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
      47             : #include <com/sun/star/xml/sax/Parser.hpp>
      48             : #include <com/sun/star/xml/sax/InputSource.hpp>
      49             : #include <com/sun/star/io/XOutputStream.hpp>
      50             : #include <com/sun/star/xml/sax/Writer.hpp>
      51             : #include <com/sun/star/io/XInputStream.hpp>
      52             : #include <com/sun/star/io/XActiveDataSource.hpp>
      53             : #include <com/sun/star/beans/XPropertySet.hpp>
      54             : #include <com/sun/star/uno/DeploymentException.hpp>
      55             : #include <com/sun/star/lang/DisposedException.hpp>
      56             : #include <com/sun/star/script/LibraryNotLoadedException.hpp>
      57             : #include <com/sun/star/script/vba/VBAScriptEventId.hpp>
      58             : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
      59             : #include <com/sun/star/util/PathSubstitution.hpp>
      60             : #include <com/sun/star/util/theMacroExpander.hpp>
      61             : #include <com/sun/star/deployment/ExtensionManager.hpp>
      62             : #include <comphelper/storagehelper.hxx>
      63             : #include <cppuhelper/exc_hlp.hxx>
      64             : #include <cppuhelper/supportsservice.hxx>
      65             : #include <basic/sbmod.hxx>
      66             : #include <boost/scoped_ptr.hpp>
      67             : 
      68             : namespace basic
      69             : {
      70             : 
      71             : using namespace com::sun::star::document;
      72             : using namespace com::sun::star::container;
      73             : using namespace com::sun::star::uno;
      74             : using namespace com::sun::star::lang;
      75             : using namespace com::sun::star::io;
      76             : using namespace com::sun::star::ucb;
      77             : using namespace com::sun::star::script;
      78             : using namespace com::sun::star::beans;
      79             : using namespace com::sun::star::xml::sax;
      80             : using namespace com::sun::star::util;
      81             : using namespace com::sun::star::task;
      82             : using namespace com::sun::star::embed;
      83             : using namespace com::sun::star::frame;
      84             : using namespace com::sun::star::deployment;
      85             : using namespace com::sun::star;
      86             : using namespace cppu;
      87             : using namespace osl;
      88             : 
      89             : using com::sun::star::uno::Reference;
      90             : 
      91             : using ::rtl::Uri;
      92             : 
      93             : // #i34411: Flag for error handling during migration
      94             : static bool GbMigrationSuppressErrors = false;
      95             : 
      96             : 
      97             : // Implementation class NameContainer
      98             : 
      99             : // Methods XElementAccess
     100           0 : Type NameContainer::getElementType()
     101             :     throw(RuntimeException, std::exception)
     102             : {
     103           0 :     return mType;
     104             : }
     105             : 
     106        6789 : sal_Bool NameContainer::hasElements()
     107             :     throw(RuntimeException, std::exception)
     108             : {
     109        6789 :     bool bRet = (mnElementCount > 0);
     110        6789 :     return bRet;
     111             : }
     112             : 
     113             : // Methods XNameAccess
     114       17137 : Any NameContainer::getByName( const OUString& aName )
     115             :     throw(NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
     116             : {
     117       17137 :     NameContainerNameMap::iterator aIt = mHashMap.find( aName );
     118       17137 :     if( aIt == mHashMap.end() )
     119             :     {
     120           0 :         throw NoSuchElementException();
     121             :     }
     122       17137 :     sal_Int32 iHashResult = (*aIt).second;
     123       17137 :     Any aRetAny = mValues.getConstArray()[ iHashResult ];
     124       17137 :     return aRetAny;
     125             : }
     126             : 
     127       12360 : Sequence< OUString > NameContainer::getElementNames()
     128             :     throw(RuntimeException, std::exception)
     129             : {
     130       12360 :     return mNames;
     131             : }
     132             : 
     133        8989 : sal_Bool NameContainer::hasByName( const OUString& aName )
     134             :     throw(RuntimeException, std::exception)
     135             : {
     136        8989 :     NameContainerNameMap::iterator aIt = mHashMap.find( aName );
     137        8989 :     bool bRet = ( aIt != mHashMap.end() );
     138        8989 :     return bRet;
     139             : }
     140             : 
     141             : 
     142             : // Methods XNameReplace
     143          37 : void NameContainer::replaceByName( const OUString& aName, const Any& aElement )
     144             :     throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
     145             : {
     146          37 :     Type aAnyType = aElement.getValueType();
     147          37 :     if( mType != aAnyType )
     148             :     {
     149           0 :         throw IllegalArgumentException();
     150             :     }
     151          37 :     NameContainerNameMap::iterator aIt = mHashMap.find( aName );
     152          37 :     if( aIt == mHashMap.end() )
     153             :     {
     154           0 :         throw NoSuchElementException();
     155             :     }
     156          37 :     sal_Int32 iHashResult = (*aIt).second;
     157          74 :     Any aOldElement = mValues.getConstArray()[ iHashResult ];
     158          37 :     mValues.getArray()[ iHashResult ] = aElement;
     159             : 
     160             : 
     161             :     // Fire event
     162          37 :     if( maContainerListeners.getLength() > 0 )
     163             :     {
     164           0 :         ContainerEvent aEvent;
     165           0 :         aEvent.Source = mpxEventSource;
     166           0 :         aEvent.Accessor <<= aName;
     167           0 :         aEvent.Element = aElement;
     168           0 :         aEvent.ReplacedElement = aOldElement;
     169           0 :         maContainerListeners.notifyEach( &XContainerListener::elementReplaced, aEvent );
     170             :     }
     171             : 
     172             :     /*  After the container event has been fired (one listener will update the
     173             :         core Basic manager), fire change event. Listeners can rely that the
     174             :         Basic source code of the core Basic manager is up-to-date. */
     175          37 :     if( maChangesListeners.getLength() > 0 )
     176             :     {
     177           0 :         ChangesEvent aEvent;
     178           0 :         aEvent.Source = mpxEventSource;
     179           0 :         aEvent.Base <<= aEvent.Source;
     180           0 :         aEvent.Changes.realloc( 1 );
     181           0 :         aEvent.Changes[ 0 ].Accessor <<= aName;
     182           0 :         aEvent.Changes[ 0 ].Element <<= aElement;
     183           0 :         aEvent.Changes[ 0 ].ReplacedElement = aOldElement;
     184           0 :         maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
     185          37 :     }
     186          37 : }
     187             : 
     188             : 
     189             : // Methods XNameContainer
     190       10572 : void NameContainer::insertByName( const OUString& aName, const Any& aElement )
     191             :     throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException, std::exception)
     192             : {
     193       10572 :     Type aAnyType = aElement.getValueType();
     194       10572 :     if( mType != aAnyType )
     195             :     {
     196           0 :         throw IllegalArgumentException();
     197             :     }
     198       10572 :     NameContainerNameMap::iterator aIt = mHashMap.find( aName );
     199       10572 :     if( aIt != mHashMap.end() )
     200             :     {
     201           0 :         throw ElementExistException();
     202             :     }
     203             : 
     204       10572 :     sal_Int32 nCount = mNames.getLength();
     205       10572 :     mNames.realloc( nCount + 1 );
     206       10572 :     mValues.realloc( nCount + 1 );
     207       10572 :     mNames.getArray()[ nCount ] = aName;
     208       10572 :     mValues.getArray()[ nCount ] = aElement;
     209             : 
     210       10572 :     mHashMap[ aName ] = nCount;
     211       10572 :     mnElementCount++;
     212             : 
     213             :     // Fire event
     214       10572 :     if( maContainerListeners.getLength() > 0 )
     215             :     {
     216        1485 :         ContainerEvent aEvent;
     217        1485 :         aEvent.Source = mpxEventSource;
     218        1485 :         aEvent.Accessor <<= aName;
     219        1485 :         aEvent.Element = aElement;
     220        1485 :         maContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent );
     221             :     }
     222             : 
     223             :     /*  After the container event has been fired (one listener will update the
     224             :         core Basic manager), fire change event. Listeners can rely that the
     225             :         Basic source code of the core Basic manager is up-to-date. */
     226       10572 :     if( maChangesListeners.getLength() > 0 )
     227             :     {
     228           0 :         ChangesEvent aEvent;
     229           0 :         aEvent.Source = mpxEventSource;
     230           0 :         aEvent.Base <<= aEvent.Source;
     231           0 :         aEvent.Changes.realloc( 1 );
     232           0 :         aEvent.Changes[ 0 ].Accessor <<= aName;
     233           0 :         aEvent.Changes[ 0 ].Element <<= aElement;
     234           0 :         maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
     235       10572 :     }
     236       10572 : }
     237             : 
     238           0 : void NameContainer::removeByName( const OUString& aName )
     239             :     throw(NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
     240             : {
     241           0 :     NameContainerNameMap::iterator aIt = mHashMap.find( aName );
     242           0 :     if( aIt == mHashMap.end() )
     243             :     {
     244           0 :         OUString sMessage = "\"" + aName + "\" not found";
     245           0 :         throw NoSuchElementException(sMessage, uno::Reference< uno::XInterface >());
     246             :     }
     247             : 
     248           0 :     sal_Int32 iHashResult = (*aIt).second;
     249           0 :     Any aOldElement = mValues.getConstArray()[ iHashResult ];
     250           0 :     mHashMap.erase( aIt );
     251           0 :     sal_Int32 iLast = mNames.getLength() - 1;
     252           0 :     if( iLast != iHashResult )
     253             :     {
     254           0 :         OUString* pNames = mNames.getArray();
     255           0 :         Any* pValues = mValues.getArray();
     256           0 :         pNames[ iHashResult ] = pNames[ iLast ];
     257           0 :         pValues[ iHashResult ] = pValues[ iLast ];
     258           0 :         mHashMap[ pNames[ iHashResult ] ] = iHashResult;
     259             :     }
     260           0 :     mNames.realloc( iLast );
     261           0 :     mValues.realloc( iLast );
     262           0 :     mnElementCount--;
     263             : 
     264             :     // Fire event
     265           0 :     if( maContainerListeners.getLength() > 0 )
     266             :     {
     267           0 :         ContainerEvent aEvent;
     268           0 :         aEvent.Source = mpxEventSource;
     269           0 :         aEvent.Accessor <<= aName;
     270           0 :         aEvent.Element = aOldElement;
     271           0 :         maContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvent );
     272             :     }
     273             : 
     274             :     /*  After the container event has been fired (one listener will update the
     275             :         core Basic manager), fire change event. Listeners can rely that the
     276             :         Basic source code of the core Basic manager is up-to-date. */
     277           0 :     if( maChangesListeners.getLength() > 0 )
     278             :     {
     279           0 :         ChangesEvent aEvent;
     280           0 :         aEvent.Source = mpxEventSource;
     281           0 :         aEvent.Base <<= aEvent.Source;
     282           0 :         aEvent.Changes.realloc( 1 );
     283           0 :         aEvent.Changes[ 0 ].Accessor <<= aName;
     284             :         // aEvent.Changes[ 0 ].Element remains empty (meaning "replaced with nothing")
     285           0 :         aEvent.Changes[ 0 ].ReplacedElement = aOldElement;
     286           0 :         maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
     287           0 :     }
     288           0 : }
     289             : 
     290             : 
     291             : // Methods XContainer
     292        3398 : void SAL_CALL NameContainer::addContainerListener( const Reference< XContainerListener >& xListener )
     293             :     throw (RuntimeException, std::exception)
     294             : {
     295        3398 :     if( !xListener.is() )
     296             :     {
     297             :         throw RuntimeException("addContainerListener called with null xListener",
     298           0 :                                static_cast< cppu::OWeakObject * >(this));
     299             :     }
     300        3398 :     maContainerListeners.addInterface( xListener );
     301        3398 : }
     302             : 
     303           0 : void SAL_CALL NameContainer::removeContainerListener( const Reference< XContainerListener >& xListener )
     304             :     throw (RuntimeException, std::exception)
     305             : {
     306           0 :     if( !xListener.is() )
     307             :     {
     308           0 :         throw RuntimeException();
     309             :     }
     310           0 :     maContainerListeners.removeInterface( xListener );
     311           0 : }
     312             : 
     313             : // Methods XChangesNotifier
     314          26 : void SAL_CALL NameContainer::addChangesListener( const Reference< XChangesListener >& xListener )
     315             :     throw (RuntimeException, std::exception)
     316             : {
     317          26 :     if( !xListener.is() )
     318             :     {
     319           0 :         throw RuntimeException();
     320             :     }
     321          26 :     maChangesListeners.addInterface( xListener );
     322          26 : }
     323             : 
     324           0 : void SAL_CALL NameContainer::removeChangesListener( const Reference< XChangesListener >& xListener )
     325             :     throw (RuntimeException, std::exception)
     326             : {
     327           0 :     if( !xListener.is() )
     328             :     {
     329           0 :         throw RuntimeException();
     330             :     }
     331           0 :     maChangesListeners.removeInterface( xListener );
     332           0 : }
     333             : 
     334             : 
     335             : // ModifiableHelper
     336             : 
     337        8025 : void ModifiableHelper::setModified( bool _bModified )
     338             : {
     339        8025 :     if ( _bModified == mbModified )
     340             :     {
     341        8088 :         return;
     342             :     }
     343        7962 :     mbModified = _bModified;
     344             : 
     345        7962 :     if ( m_aModifyListeners.getLength() == 0 )
     346             :     {
     347        7962 :         return;
     348             :     }
     349           0 :     EventObject aModifyEvent( m_rEventSource );
     350           0 :     m_aModifyListeners.notifyEach( &XModifyListener::modified, aModifyEvent );
     351             : }
     352             : 
     353             : 
     354             : 
     355        3979 : VBAScriptListenerContainer::VBAScriptListenerContainer( ::osl::Mutex& rMutex ) :
     356        3979 :     VBAScriptListenerContainer_BASE( rMutex )
     357             : {
     358        3979 : }
     359             : 
     360           0 : bool VBAScriptListenerContainer::implTypedNotify( const Reference< vba::XVBAScriptListener >& rxListener, const vba::VBAScriptEvent& rEvent )
     361             :     throw (Exception)
     362             : {
     363           0 :     rxListener->notifyVBAScriptEvent( rEvent );
     364           0 :     return true;    // notify all other listeners too
     365             : }
     366             : 
     367             : // Ctor
     368        3979 : SfxLibraryContainer::SfxLibraryContainer( void )
     369             :     : SfxLibraryContainer_BASE( maMutex )
     370             : 
     371             :     , maVBAScriptListeners( maMutex )
     372             :     , mnRunningVBAScripts( 0 )
     373             :     , mbVBACompat( false )
     374             :     , maModifiable( *this, maMutex )
     375        3979 :     , maNameContainer( getCppuType( (Reference< XNameAccess >*) NULL ) )
     376             :     , mbOldInfoFormat( false )
     377             :     , mbOasis2OOoFormat( false )
     378             :     , mpBasMgr( NULL )
     379             :     , mbOwnBasMgr( false )
     380        7958 :     , meInitMode(DEFAULT)
     381             : {
     382        3979 :     mxContext = comphelper::getProcessComponentContext();
     383             : 
     384        3979 :     mxSFI = ucb::SimpleFileAccess::create( mxContext );
     385             : 
     386        3979 :     mxStringSubstitution = util::PathSubstitution::create( mxContext );
     387        3979 : }
     388             : 
     389        2486 : SfxLibraryContainer::~SfxLibraryContainer()
     390             : {
     391        1243 :     if( mbOwnBasMgr )
     392             :     {
     393           0 :         BasicManager::LegacyDeleteBasicManager( mpBasMgr );
     394             :     }
     395        1243 : }
     396             : 
     397       43524 : void SfxLibraryContainer::checkDisposed() const
     398             : {
     399       43524 :     if ( isDisposed() )
     400             :     {
     401             :         throw DisposedException( OUString(),
     402           0 :                                  *const_cast< SfxLibraryContainer* >( this ) );
     403             :     }
     404       43524 : }
     405             : 
     406       43524 : void SfxLibraryContainer::enterMethod()
     407             : {
     408       43524 :     maMutex.acquire();
     409       43524 :     checkDisposed();
     410       43524 : }
     411             : 
     412       43524 : void SfxLibraryContainer::leaveMethod()
     413             : {
     414       43524 :     maMutex.release();
     415       43524 : }
     416             : 
     417          57 : BasicManager* SfxLibraryContainer::getBasicManager( void )
     418             : {
     419          57 :     if ( mpBasMgr )
     420             :     {
     421          28 :         return mpBasMgr;
     422             :     }
     423          29 :     Reference< XModel > xDocument( mxOwnerDocument.get(), UNO_QUERY );
     424             :     SAL_WARN_IF(
     425             :         !xDocument.is(), "basic",
     426             :         ("SfxLibraryContainer::getBasicManager: cannot obtain a BasicManager"
     427             :          " without document!"));
     428          29 :     if ( xDocument.is() )
     429             :     {
     430          29 :         mpBasMgr = BasicManagerRepository::getDocumentBasicManager( xDocument );
     431             :     }
     432          29 :     return mpBasMgr;
     433             : }
     434             : 
     435             : // Methods XStorageBasedLibraryContainer
     436           0 : Reference< XStorage > SAL_CALL SfxLibraryContainer::getRootStorage() throw (RuntimeException, std::exception)
     437             : {
     438           0 :     LibraryContainerMethodGuard aGuard( *this );
     439           0 :     return mxStorage;
     440             : }
     441             : 
     442        2298 : void SAL_CALL SfxLibraryContainer::setRootStorage( const Reference< XStorage >& _rxRootStorage )
     443             :     throw (IllegalArgumentException, RuntimeException, std::exception)
     444             : {
     445        2298 :     LibraryContainerMethodGuard aGuard( *this );
     446        2298 :     if ( !_rxRootStorage.is() )
     447             :     {
     448           0 :         throw IllegalArgumentException();
     449             :     }
     450        2298 :     mxStorage = _rxRootStorage;
     451        2298 :     onNewRootStorage();
     452        2298 : }
     453             : 
     454        1208 : void SAL_CALL SfxLibraryContainer::storeLibrariesToStorage( const Reference< XStorage >& _rxRootStorage )
     455             :     throw (IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
     456             : {
     457        1208 :     LibraryContainerMethodGuard aGuard( *this );
     458        1208 :     if ( !_rxRootStorage.is() )
     459             :     {
     460           0 :         throw IllegalArgumentException();
     461             :     }
     462             :     try
     463             :     {
     464        1208 :         storeLibraries_Impl( _rxRootStorage, true );
     465             :     }
     466           0 :     catch( const Exception& )
     467             :     {
     468             :         throw WrappedTargetException( OUString(),
     469           0 :                                       *this, ::cppu::getCaughtException() );
     470        1208 :     }
     471        1208 : }
     472             : 
     473             : 
     474             : // Methods XModifiable
     475           0 : sal_Bool SfxLibraryContainer::isModified()
     476             :     throw (RuntimeException, std::exception)
     477             : {
     478           0 :     LibraryContainerMethodGuard aGuard( *this );
     479           0 :     if ( maModifiable.isModified() )
     480             :     {
     481           0 :         return sal_True;
     482             :     }
     483             :     // the library container is not modified, go through the libraries and check whether they are modified
     484           0 :     Sequence< OUString > aNames = maNameContainer.getElementNames();
     485           0 :     const OUString* pNames = aNames.getConstArray();
     486           0 :     sal_Int32 nNameCount = aNames.getLength();
     487             : 
     488           0 :     for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
     489             :     {
     490           0 :         OUString aName = pNames[ i ];
     491           0 :         SfxLibrary* pImplLib = getImplLib( aName );
     492           0 :         if( pImplLib->isModified() )
     493             :         {
     494           0 :             if ( aName == "Standard" )
     495             :             {
     496             :                 // this is a workaround that has to be implemented because
     497             :                 // empty standard library should stay marked as modified
     498             :                 // but should not be treated as modified while it is empty
     499           0 :                 if ( pImplLib->hasElements() )
     500           0 :                     return sal_True;
     501             :             }
     502             :             else
     503             :             {
     504           0 :                 return sal_True;
     505             :             }
     506             :         }
     507           0 :     }
     508             : 
     509           0 :     return sal_False;
     510             : }
     511             : 
     512        2630 : void SAL_CALL SfxLibraryContainer::setModified( sal_Bool _bModified )
     513             :     throw (PropertyVetoException, RuntimeException, std::exception)
     514             : {
     515        2630 :     LibraryContainerMethodGuard aGuard( *this );
     516        2630 :     maModifiable.setModified( _bModified );
     517        2630 : }
     518             : 
     519           0 : void SAL_CALL SfxLibraryContainer::addModifyListener( const Reference< XModifyListener >& _rxListener )
     520             :     throw (RuntimeException, std::exception)
     521             : {
     522           0 :     LibraryContainerMethodGuard aGuard( *this );
     523           0 :     maModifiable.addModifyListener( _rxListener );
     524           0 : }
     525             : 
     526           0 : void SAL_CALL SfxLibraryContainer::removeModifyListener( const Reference< XModifyListener >& _rxListener )
     527             :     throw (RuntimeException, std::exception)
     528             : {
     529           0 :     LibraryContainerMethodGuard aGuard( *this );
     530           0 :     maModifiable.removeModifyListener( _rxListener );
     531           0 : }
     532             : 
     533             : // Methods XPersistentLibraryContainer
     534           0 : Any SAL_CALL SfxLibraryContainer::getRootLocation() throw (RuntimeException, std::exception)
     535             : {
     536           0 :     LibraryContainerMethodGuard aGuard( *this );
     537           0 :     return makeAny( getRootStorage() );
     538             : }
     539             : 
     540           0 : OUString SAL_CALL SfxLibraryContainer::getContainerLocationName() throw (RuntimeException, std::exception)
     541             : {
     542           0 :     LibraryContainerMethodGuard aGuard( *this );
     543           0 :     return maLibrariesDir;
     544             : }
     545             : 
     546          62 : void SAL_CALL SfxLibraryContainer::storeLibraries(  )
     547             :     throw (WrappedTargetException, RuntimeException, std::exception)
     548             : {
     549          62 :     LibraryContainerMethodGuard aGuard( *this );
     550             :     try
     551             :     {
     552          62 :         storeLibraries_Impl( mxStorage, mxStorage.is()  );
     553             :         // we need to store *all* libraries if and only if we are based on a storage:
     554             :         // in this case, storeLibraries_Impl will remove the source storage, after loading
     555             :         // all libraries, so we need to force them to be stored, again
     556             :     }
     557           0 :     catch( const Exception& )
     558             :     {
     559           0 :         throw WrappedTargetException( OUString(), *this, ::cppu::getCaughtException() );
     560          62 :     }
     561          62 : }
     562             : 
     563           0 : static void checkAndCopyFileImpl( const INetURLObject& rSourceFolderInetObj,
     564             :                                   const INetURLObject& rTargetFolderInetObj,
     565             :                                   const OUString& rCheckFileName,
     566             :                                   const OUString& rCheckExtension,
     567             :                                   Reference< XSimpleFileAccess3 > xSFI )
     568             : {
     569           0 :     INetURLObject aTargetFolderInetObj( rTargetFolderInetObj );
     570             :     aTargetFolderInetObj.insertName( rCheckFileName, true, INetURLObject::LAST_SEGMENT,
     571           0 :                                      true, INetURLObject::ENCODE_ALL );
     572           0 :     aTargetFolderInetObj.setExtension( rCheckExtension );
     573           0 :     OUString aTargetFile = aTargetFolderInetObj.GetMainURL( INetURLObject::NO_DECODE );
     574           0 :     if( !xSFI->exists( aTargetFile ) )
     575             :     {
     576           0 :         INetURLObject aSourceFolderInetObj( rSourceFolderInetObj );
     577             :         aSourceFolderInetObj.insertName( rCheckFileName, true, INetURLObject::LAST_SEGMENT,
     578           0 :                                          true, INetURLObject::ENCODE_ALL );
     579           0 :         aSourceFolderInetObj.setExtension( rCheckExtension );
     580           0 :         OUString aSourceFile = aSourceFolderInetObj.GetMainURL( INetURLObject::NO_DECODE );
     581           0 :         xSFI->copy( aSourceFile, aTargetFile );
     582           0 :     }
     583           0 : }
     584             : 
     585        2773 : static void createVariableURL( OUString& rStr, const OUString& rLibName,
     586             :                                const OUString& rInfoFileName, bool bUser )
     587             : {
     588        2773 :     if( bUser )
     589             :     {
     590        2773 :         rStr = "$(USER)/basic/";
     591             :     }
     592             :     else
     593             :     {
     594           0 :         rStr = "$(INST)/" LIBO_SHARE_FOLDER "/basic/";
     595             :     }
     596        2773 :     rStr += rLibName;
     597        2773 :     rStr += "/";
     598        2773 :     rStr += rInfoFileName;
     599        2773 :     rStr += ".xlb/";
     600        2773 : }
     601             : 
     602        3907 : void SfxLibraryContainer::init( const OUString& rInitialDocumentURL, const uno::Reference< embed::XStorage >& rxInitialStorage )
     603             : {
     604             :     // this might be called from within the ctor, and the impl_init might (indirectly) create
     605             :     // an UNO reference to ourself.
     606             :     // Ensure that we're not destroyed while we're in here
     607        3907 :     osl_atomic_increment( &m_refCount );
     608        3907 :     init_Impl( rInitialDocumentURL, rxInitialStorage );
     609        3906 :     osl_atomic_decrement( &m_refCount );
     610        3906 : }
     611             : 
     612        3907 : void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
     613             :                                      const uno::Reference< embed::XStorage >& rxInitialStorage )
     614             : {
     615        3907 :     uno::Reference< embed::XStorage > xStorage = rxInitialStorage;
     616             : 
     617        3907 :     maInitialDocumentURL = rInitialDocumentURL;
     618        3907 :     maInfoFileName = OUString::createFromAscii( getInfoFileName() );
     619        3907 :     maOldInfoFileName = OUString::createFromAscii( getOldInfoFileName() );
     620        3907 :     maLibElementFileExtension = OUString::createFromAscii( getLibElementFileExtension() );
     621        3907 :     maLibrariesDir = OUString::createFromAscii( getLibrariesDir() );
     622             : 
     623        3907 :     meInitMode = DEFAULT;
     624        7814 :     INetURLObject aInitUrlInetObj( maInitialDocumentURL );
     625        7814 :     OUString aInitFileName = aInitUrlInetObj.GetMainURL( INetURLObject::NO_DECODE );
     626        3907 :     if( !aInitFileName.isEmpty() )
     627             :     {
     628             :         // We need a BasicManager to avoid problems
     629           0 :         StarBASIC* pBas = new StarBASIC();
     630           0 :         mpBasMgr = new BasicManager( pBas );
     631           0 :         mbOwnBasMgr = true;
     632             : 
     633           0 :         OUString aExtension = aInitUrlInetObj.getExtension();
     634           0 :         if( aExtension == "xlc" )
     635             :         {
     636           0 :             meInitMode = CONTAINER_INIT_FILE;
     637           0 :             INetURLObject aLibPathInetObj( aInitUrlInetObj );
     638           0 :             aLibPathInetObj.removeSegment();
     639           0 :             maLibraryPath = aLibPathInetObj.GetMainURL( INetURLObject::NO_DECODE );
     640             :         }
     641           0 :         else if( aExtension == "xlb" )
     642             :         {
     643           0 :             meInitMode = LIBRARY_INIT_FILE;
     644           0 :             uno::Reference< embed::XStorage > xDummyStor;
     645           0 :             ::xmlscript::LibDescriptor aLibDesc;
     646           0 :             implLoadLibraryIndexFile( NULL, aLibDesc, xDummyStor, aInitFileName );
     647           0 :             return;
     648             :         }
     649             :         else
     650             :         {
     651             :             // Decide between old and new document
     652           0 :             bool bOldStorage = SotStorage::IsOLEStorage( aInitFileName );
     653           0 :             if ( bOldStorage )
     654             :             {
     655           0 :                 meInitMode = OLD_BASIC_STORAGE;
     656           0 :                 importFromOldStorage( aInitFileName );
     657           0 :                 return;
     658             :             }
     659             :             else
     660             :             {
     661           0 :                 meInitMode = OFFICE_DOCUMENT;
     662             :                 try
     663             :                 {
     664           0 :                     xStorage = ::comphelper::OStorageHelper::GetStorageFromURL( aInitFileName, embed::ElementModes::READ );
     665             :                 }
     666           0 :                 catch (const uno::Exception& )
     667             :                 {
     668             :                     // TODO: error handling
     669             :                 }
     670             :             }
     671           0 :         }
     672             :     }
     673             :     else
     674             :     {
     675             :         // Default paths
     676        3907 :         maLibraryPath = SvtPathOptions().GetBasicPath();
     677             :     }
     678             : 
     679        7813 :     Reference< XParser > xParser = xml::sax::Parser::create(mxContext);
     680             : 
     681        7812 :     uno::Reference< io::XInputStream > xInput;
     682             : 
     683        3906 :     mxStorage = xStorage;
     684        3906 :     bool bStorage = mxStorage.is();
     685             : 
     686             : 
     687             :     // #110009: Scope to force the StorageRefs to be destructed and
     688             :     // so the streams to be closed before the preload operation
     689             :     {
     690             : 
     691        3906 :     uno::Reference< embed::XStorage > xLibrariesStor;
     692        7812 :     OUString aFileName;
     693             : 
     694        3906 :     int nPassCount = 1;
     695        3906 :     if( !bStorage && meInitMode == DEFAULT )
     696             :     {
     697         142 :         nPassCount = 2;
     698             :     }
     699        7954 :     for( int nPass = 0 ; nPass < nPassCount ; nPass++ )
     700             :     {
     701        4048 :         if( bStorage )
     702             :         {
     703             :             SAL_WARN_IF(
     704             :                 meInitMode != DEFAULT && meInitMode != OFFICE_DOCUMENT, "basic",
     705             :                 "Wrong InitMode for document");
     706             :             try
     707             :             {
     708        3764 :                 uno::Reference< io::XStream > xStream;
     709        3764 :                 xLibrariesStor = xStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READ );
     710             : 
     711           6 :                 if ( xLibrariesStor.is() )
     712             :                 {
     713           6 :                     aFileName = maInfoFileName;
     714           6 :                     aFileName += "-lc.xml";
     715             : 
     716             :                     try
     717             :                     {
     718           6 :                         xStream = xLibrariesStor->openStreamElement( aFileName, embed::ElementModes::READ );
     719             :                     }
     720           0 :                     catch(const uno::Exception& )
     721             :                     {}
     722             : 
     723           6 :                     if( !xStream.is() )
     724             :                     {
     725           0 :                         mbOldInfoFormat = true;
     726             : 
     727             :                         // Check old version
     728           0 :                         aFileName = maOldInfoFileName;
     729           0 :                         aFileName += ".xml";
     730             : 
     731             :                         try
     732             :                         {
     733           0 :                             xStream = xLibrariesStor->openStreamElement( aFileName, embed::ElementModes::READ );
     734             :                         }
     735           0 :                         catch(const uno::Exception& )
     736             :                         {}
     737             : 
     738           0 :                         if( !xStream.is() )
     739             :                         {
     740             :                             // Check for EA2 document version with wrong extensions
     741           0 :                             aFileName = maOldInfoFileName;
     742           0 :                             aFileName += ".xli";
     743           0 :                             xStream = xLibrariesStor->openStreamElement( aFileName, embed::ElementModes::READ );
     744             :                         }
     745             :                     }
     746             :                 }
     747             : 
     748           6 :                 if ( xStream.is() )
     749             :                 {
     750           6 :                     xInput = xStream->getInputStream();
     751        3764 :                 }
     752             :             }
     753        3758 :             catch(const uno::Exception& )
     754             :             {
     755             :                 // TODO: error handling?
     756             :             }
     757             :         }
     758             :         else
     759             :         {
     760         284 :             INetURLObject* pLibInfoInetObj = NULL;
     761         284 :             if( meInitMode == CONTAINER_INIT_FILE )
     762             :             {
     763           0 :                 aFileName = aInitFileName;
     764             :             }
     765             :             else
     766             :             {
     767         284 :                 if( nPass == 1 )
     768             :                 {
     769         142 :                     pLibInfoInetObj = new INetURLObject( maLibraryPath.getToken(0, (sal_Unicode)';') );
     770             :                 }
     771             :                 else
     772             :                 {
     773         142 :                     pLibInfoInetObj = new INetURLObject( maLibraryPath.getToken(1, (sal_Unicode)';') );
     774             :                 }
     775         284 :                 pLibInfoInetObj->insertName( maInfoFileName, false, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
     776         284 :                 pLibInfoInetObj->setExtension( OUString("xlc") );
     777         284 :                 aFileName = pLibInfoInetObj->GetMainURL( INetURLObject::NO_DECODE );
     778             :             }
     779             : 
     780             :             try
     781             :             {
     782         284 :                 xInput = mxSFI->openFileRead( aFileName );
     783             :             }
     784          86 :             catch(const Exception& )
     785             :             {
     786             :                 // Silently tolerate empty or missing files
     787          86 :                 xInput.clear();
     788             :             }
     789             : 
     790             :             // Old variant?
     791         284 :             if( !xInput.is() && nPass == 0 )
     792             :             {
     793          86 :                 INetURLObject aLibInfoInetObj( maLibraryPath.getToken(1, (sal_Unicode)';') );
     794          86 :                 aLibInfoInetObj.insertName( maOldInfoFileName, false, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
     795          86 :                 aLibInfoInetObj.setExtension( OUString( "xli") );
     796          86 :                 aFileName = aLibInfoInetObj.GetMainURL( INetURLObject::NO_DECODE );
     797             : 
     798             :                 try
     799             :                 {
     800          86 :                     xInput = mxSFI->openFileRead( aFileName );
     801           0 :                     mbOldInfoFormat = true;
     802             :                 }
     803          86 :                 catch(const Exception& )
     804             :                 {
     805          86 :                     xInput.clear();
     806          86 :                 }
     807             :             }
     808             : 
     809         284 :             delete pLibInfoInetObj;
     810             :         }
     811             : 
     812        4048 :         if( xInput.is() )
     813             :         {
     814         204 :             InputSource source;
     815         204 :             source.aInputStream = xInput;
     816         204 :             source.sSystemId    = aFileName;
     817             : 
     818             :             // start parsing
     819         204 :             ::xmlscript::LibDescriptorArray* pLibArray = new ::xmlscript::LibDescriptorArray();
     820             : 
     821             :             try
     822             :             {
     823         204 :                 xParser->setDocumentHandler( ::xmlscript::importLibraryContainer( pLibArray ) );
     824         204 :                 xParser->parseStream( source );
     825             :             }
     826           0 :             catch ( const xml::sax::SAXException& e )
     827             :             {
     828             :                 SAL_WARN("basic", e.Message);
     829           0 :                 return;
     830             :             }
     831           0 :             catch ( const io::IOException& e )
     832             :             {
     833             :                 SAL_WARN("basic", e.Message);
     834           0 :                 return;
     835             :             }
     836             : 
     837         204 :             sal_Int32 nLibCount = pLibArray->mnLibCount;
     838        1544 :             for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
     839             :             {
     840        1340 :                 ::xmlscript::LibDescriptor& rLib = pLibArray->mpLibs[i];
     841             : 
     842             :                 // Check storage URL
     843        1340 :                 OUString aStorageURL = rLib.aStorageURL;
     844        1340 :                 if( !bStorage && aStorageURL.isEmpty() && nPass == 0 )
     845             :                 {
     846          56 :                     OUString aLibraryPath;
     847          56 :                     if( meInitMode == CONTAINER_INIT_FILE )
     848             :                     {
     849           0 :                         aLibraryPath = maLibraryPath;
     850             :                     }
     851             :                     else
     852             :                     {
     853          56 :                         aLibraryPath = maLibraryPath.getToken(1, (sal_Unicode)';');
     854             :                     }
     855         112 :                     INetURLObject aInetObj( aLibraryPath );
     856             : 
     857             :                     aInetObj.insertName( rLib.aName, true, INetURLObject::LAST_SEGMENT,
     858          56 :                                          true, INetURLObject::ENCODE_ALL );
     859         112 :                     OUString aLibDirPath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
     860          56 :                     if( mxSFI->isFolder( aLibDirPath ) )
     861             :                     {
     862          56 :                         createVariableURL( rLib.aStorageURL, rLib.aName, maInfoFileName, true );
     863          56 :                         maModifiable.setModified( true );
     864             :                     }
     865           0 :                     else if( rLib.bLink )
     866             :                     {
     867             :                         // Check "share" path
     868           0 :                         INetURLObject aShareInetObj( maLibraryPath.getToken(0, (sal_Unicode)';') );
     869             :                         aShareInetObj.insertName( rLib.aName, true, INetURLObject::LAST_SEGMENT,
     870           0 :                                                   true, INetURLObject::ENCODE_ALL );
     871           0 :                         OUString aShareLibDirPath = aShareInetObj.GetMainURL( INetURLObject::NO_DECODE );
     872           0 :                         if( mxSFI->isFolder( aShareLibDirPath ) )
     873             :                         {
     874           0 :                             createVariableURL( rLib.aStorageURL, rLib.aName, maInfoFileName, false );
     875           0 :                             maModifiable.setModified( true );
     876             :                         }
     877             :                         else
     878             :                         {
     879             :                             // #i25537: Ignore lib if library folder does not really exist
     880           0 :                             continue;
     881           0 :                         }
     882          56 :                     }
     883             :                 }
     884             : 
     885        2680 :                 OUString aLibName = rLib.aName;
     886             : 
     887             :                 // If the same library name is used by the shared and the
     888             :                 // user lib container index files the user file wins
     889        1340 :                 if( nPass == 1 && hasByName( aLibName ) )
     890             :                 {
     891           0 :                     continue;
     892             :                 }
     893             :                 SfxLibrary* pImplLib;
     894        1340 :                 if( rLib.bLink )
     895             :                 {
     896             :                     Reference< XNameAccess > xLib =
     897        1278 :                         createLibraryLink( aLibName, rLib.aStorageURL, rLib.bReadOnly );
     898        1278 :                     pImplLib = static_cast< SfxLibrary* >( xLib.get() );
     899             :                 }
     900             :                 else
     901             :                 {
     902          62 :                     Reference< XNameContainer > xLib = createLibrary( aLibName );
     903          62 :                     pImplLib = static_cast< SfxLibrary* >( xLib.get() );
     904          62 :                     pImplLib->mbLoaded = false;
     905          62 :                     pImplLib->mbReadOnly = rLib.bReadOnly;
     906          62 :                     if( !bStorage )
     907             :                     {
     908             :                         checkStorageURL( rLib.aStorageURL, pImplLib->maLibInfoFileURL,
     909          56 :                                          pImplLib->maStorageURL, pImplLib->maUnexpandedStorageURL );
     910          62 :                     }
     911             :                 }
     912        1340 :                 maModifiable.setModified( false );
     913             : 
     914             :                 // Read library info files
     915        1340 :                 if( !mbOldInfoFormat )
     916             :                 {
     917        1340 :                     uno::Reference< embed::XStorage > xLibraryStor;
     918        1340 :                     if( !pImplLib->mbInitialised && bStorage )
     919             :                     {
     920             :                         try
     921             :                         {
     922          18 :                             xLibraryStor = xLibrariesStor->openStorageElement( rLib.aName,
     923          12 :                                                                                 embed::ElementModes::READ );
     924             :                         }
     925           0 :                         catch(const uno::Exception& )
     926             :                         {
     927             :                             #if OSL_DEBUG_LEVEL > 0
     928             :                             Any aError( ::cppu::getCaughtException() );
     929             :                             SAL_WARN(
     930             :                                 "basic",
     931             :                                 "couldn't open sub storage for library \""
     932             :                                     << rLib.aName << "\". Exception: "
     933             :                                     << comphelper::anyToString(aError));
     934             :                             #endif
     935             :                         }
     936             :                     }
     937             : 
     938             :                     // Link is already initialised in createLibraryLink()
     939        1340 :                     if( !pImplLib->mbInitialised && (!bStorage || xLibraryStor.is()) )
     940             :                     {
     941          62 :                         OUString aIndexFileName;
     942          62 :                         bool bLoaded = implLoadLibraryIndexFile( pImplLib, rLib, xLibraryStor, aIndexFileName );
     943             :                         SAL_WARN_IF(
     944             :                             bLoaded && aLibName != rLib.aName, "basic",
     945             :                             ("Different library names in library container and"
     946             :                              " library info files!"));
     947          62 :                         if( GbMigrationSuppressErrors && !bLoaded )
     948             :                         {
     949           0 :                             removeLibrary( aLibName );
     950          62 :                         }
     951        1340 :                     }
     952             :                 }
     953           0 :                 else if( !bStorage )
     954             :                 {
     955             :                     // Write new index file immediately because otherwise
     956             :                     // the library elements will be lost when storing into
     957             :                     // the new info format
     958           0 :                     uno::Reference< embed::XStorage > xTmpStorage;
     959           0 :                     implStoreLibraryIndexFile( pImplLib, rLib, xTmpStorage );
     960             :                 }
     961             : 
     962        1340 :                 implImportLibDescriptor( pImplLib, rLib );
     963             : 
     964        1340 :                 if( nPass == 1 )
     965             :                 {
     966        1278 :                     pImplLib->mbSharedIndexFile = true;
     967        1278 :                     pImplLib->mbReadOnly = true;
     968             :                 }
     969        1340 :             }
     970             : 
     971             :             // Keep flag for documents to force writing the new index files
     972         204 :             if( !bStorage )
     973             :             {
     974         198 :                 mbOldInfoFormat = false;
     975             :             }
     976         204 :             delete pLibArray;
     977             :         }
     978        3906 :     }
     979             : 
     980             :     // #110009: END Scope to force the StorageRefs to be destructed
     981             :     }
     982             : 
     983        3906 :     if( !bStorage && meInitMode == DEFAULT )
     984             :     {
     985             :         try
     986             :         {
     987         142 :             implScanExtensions();
     988             :         }
     989          12 :         catch(const uno::Exception& )
     990             :         {
     991             :             // TODO: error handling?
     992             :             SAL_WARN("basic", "Cannot access extensions!");
     993             :         }
     994             :     }
     995             : 
     996             :     // Preload?
     997             :     {
     998        3906 :         Sequence< OUString > aNames = maNameContainer.getElementNames();
     999        3906 :         const OUString* pNames = aNames.getConstArray();
    1000        3906 :         sal_Int32 nNameCount = aNames.getLength();
    1001        5246 :         for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
    1002             :         {
    1003        1340 :             OUString aName = pNames[ i ];
    1004        1340 :             SfxLibrary* pImplLib = getImplLib( aName );
    1005        1340 :             if( pImplLib->mbPreload )
    1006             :             {
    1007           0 :                 loadLibrary( aName );
    1008             :             }
    1009        5246 :         }
    1010             :     }
    1011             : 
    1012        3906 :     if( meInitMode == DEFAULT )
    1013             :     {
    1014        3906 :         INetURLObject aUserBasicInetObj( maLibraryPath.getToken(1, (sal_Unicode)';') );
    1015        7812 :         OUString aStandardStr("Standard");
    1016             : 
    1017        7812 :         INetURLObject aPrevUserBasicInetObj_1( aUserBasicInetObj );
    1018        3906 :         aPrevUserBasicInetObj_1.removeSegment();
    1019        7812 :         INetURLObject aPrevUserBasicInetObj_2 = aPrevUserBasicInetObj_1;
    1020        3906 :         aPrevUserBasicInetObj_1.Append( "__basic_80" );
    1021        3906 :         aPrevUserBasicInetObj_2.Append( "__basic_80_2" );
    1022             : 
    1023             :         // #i93163
    1024        3906 :         bool bCleanUp = false;
    1025             :         try
    1026             :         {
    1027        3906 :             INetURLObject aPrevUserBasicInetObj = aPrevUserBasicInetObj_1;
    1028        7812 :             OUString aPrevFolder = aPrevUserBasicInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1029        3906 :             if( mxSFI->isFolder( aPrevFolder ) )
    1030             :             {
    1031             :                 // Check if Standard folder exists and is complete
    1032           0 :                 INetURLObject aUserBasicStandardInetObj( aUserBasicInetObj );
    1033             :                 aUserBasicStandardInetObj.insertName( aStandardStr, true, INetURLObject::LAST_SEGMENT,
    1034           0 :                                                       true, INetURLObject::ENCODE_ALL );
    1035           0 :                 INetURLObject aPrevUserBasicStandardInetObj( aPrevUserBasicInetObj );
    1036             :                 aPrevUserBasicStandardInetObj.insertName( aStandardStr, true, INetURLObject::LAST_SEGMENT,
    1037           0 :                                                         true, INetURLObject::ENCODE_ALL );
    1038           0 :                 OUString aPrevStandardFolder = aPrevUserBasicStandardInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1039           0 :                 if( mxSFI->isFolder( aPrevStandardFolder ) )
    1040             :                 {
    1041           0 :                     OUString aXlbExtension( "xlb" );
    1042           0 :                     OUString aCheckFileName;
    1043             : 
    1044             :                     // Check if script.xlb exists
    1045           0 :                     aCheckFileName = "script";
    1046             :                     checkAndCopyFileImpl( aUserBasicStandardInetObj,
    1047             :                                           aPrevUserBasicStandardInetObj,
    1048           0 :                                           aCheckFileName, aXlbExtension, mxSFI );
    1049             : 
    1050             :                     // Check if dialog.xlb exists
    1051           0 :                     aCheckFileName = "dialog";
    1052             :                     checkAndCopyFileImpl( aUserBasicStandardInetObj,
    1053             :                                           aPrevUserBasicStandardInetObj,
    1054           0 :                                           aCheckFileName, aXlbExtension, mxSFI );
    1055             : 
    1056             :                     // Check if module1.xba exists
    1057           0 :                     OUString aXbaExtension("xba");
    1058           0 :                     aCheckFileName = "Module1";
    1059             :                     checkAndCopyFileImpl( aUserBasicStandardInetObj,
    1060             :                                           aPrevUserBasicStandardInetObj,
    1061           0 :                                           aCheckFileName, aXbaExtension, mxSFI );
    1062             :                 }
    1063             :                 else
    1064             :                 {
    1065           0 :                     OUString aStandardFolder = aUserBasicStandardInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1066           0 :                     mxSFI->copy( aStandardFolder, aPrevStandardFolder );
    1067             :                 }
    1068             : 
    1069           0 :                 OUString aPrevCopyToFolder = aPrevUserBasicInetObj_2.GetMainURL( INetURLObject::NO_DECODE );
    1070           0 :                 mxSFI->copy( aPrevFolder, aPrevCopyToFolder );
    1071             :             }
    1072             :             else
    1073             :             {
    1074        3906 :                 aPrevUserBasicInetObj = aPrevUserBasicInetObj_2;
    1075        3906 :                 aPrevFolder = aPrevUserBasicInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1076             :             }
    1077        3906 :             if( mxSFI->isFolder( aPrevFolder ) )
    1078             :             {
    1079           0 :                 SfxLibraryContainer* pPrevCont = createInstanceImpl();
    1080           0 :                 Reference< XInterface > xRef = static_cast< XInterface* >( static_cast< OWeakObject* >(pPrevCont) );
    1081             : 
    1082             :                 // Rename previous basic folder to make storage URLs correct during initialisation
    1083           0 :                 OUString aFolderUserBasic = aUserBasicInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1084           0 :                 INetURLObject aUserBasicTmpInetObj( aUserBasicInetObj );
    1085           0 :                 aUserBasicTmpInetObj.removeSegment();
    1086           0 :                 aUserBasicTmpInetObj.Append( "__basic_tmp" );
    1087           0 :                 OUString aFolderTmp = aUserBasicTmpInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1088             : 
    1089           0 :                 mxSFI->move( aFolderUserBasic, aFolderTmp );
    1090             :                 try
    1091             :                 {
    1092           0 :                     mxSFI->move( aPrevFolder, aFolderUserBasic );
    1093             :                 }
    1094           0 :                 catch(const Exception& )
    1095             :                 {
    1096             :                     // Move back user/basic folder
    1097             :                     try
    1098             :                     {
    1099           0 :                            mxSFI->kill( aFolderUserBasic );
    1100             :                     }
    1101           0 :                     catch(const Exception& )
    1102             :                     {}
    1103           0 :                     mxSFI->move( aFolderTmp, aFolderUserBasic );
    1104           0 :                     throw;
    1105             :                 }
    1106             : 
    1107           0 :                 INetURLObject aPrevUserBasicLibInfoInetObj( aUserBasicInetObj );
    1108             :                 aPrevUserBasicLibInfoInetObj.insertName( maInfoFileName, false, INetURLObject::LAST_SEGMENT,
    1109           0 :                                                     true, INetURLObject::ENCODE_ALL );
    1110           0 :                 aPrevUserBasicLibInfoInetObj.setExtension( OUString("xlc"));
    1111           0 :                 OUString aLibInfoFileName = aPrevUserBasicLibInfoInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1112           0 :                 Sequence<Any> aInitSeq( 1 );
    1113           0 :                 aInitSeq.getArray()[0] <<= aLibInfoFileName;
    1114           0 :                 GbMigrationSuppressErrors = true;
    1115           0 :                 pPrevCont->initialize( aInitSeq );
    1116           0 :                 GbMigrationSuppressErrors = false;
    1117             : 
    1118             :                 // Rename folders back
    1119           0 :                 mxSFI->move( aFolderUserBasic, aPrevFolder );
    1120           0 :                 mxSFI->move( aFolderTmp, aFolderUserBasic );
    1121             : 
    1122           0 :                 OUString aUserSearchStr("vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE");
    1123           0 :                 OUString aSharedSearchStr("vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE");
    1124           0 :                 OUString aBundledSearchStr("vnd.sun.star.expand:$BUNDLED_EXTENSIONS");
    1125           0 :                 OUString aInstSearchStr("$(INST)");
    1126             : 
    1127           0 :                 Sequence< OUString > aNames = pPrevCont->getElementNames();
    1128           0 :                 const OUString* pNames = aNames.getConstArray();
    1129           0 :                 sal_Int32 nNameCount = aNames.getLength();
    1130             : 
    1131           0 :                 for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
    1132             :                 {
    1133           0 :                     OUString aLibName = pNames[ i ];
    1134           0 :                     if( hasByName( aLibName ) )
    1135             :                     {
    1136           0 :                         if( aLibName == aStandardStr )
    1137             :                         {
    1138           0 :                             SfxLibrary* pImplLib = getImplLib( aStandardStr );
    1139           0 :                             OUString aStandardFolder = pImplLib->maStorageURL;
    1140           0 :                             mxSFI->kill( aStandardFolder );
    1141             :                         }
    1142             :                         else
    1143             :                         {
    1144           0 :                             continue;
    1145             :                         }
    1146             :                     }
    1147             : 
    1148           0 :                     SfxLibrary* pImplLib = pPrevCont->getImplLib( aLibName );
    1149           0 :                     if( pImplLib->mbLink )
    1150             :                     {
    1151           0 :                         OUString aStorageURL = pImplLib->maUnexpandedStorageURL;
    1152           0 :                         bool bCreateLink = true;
    1153           0 :                         if( aStorageURL.indexOf( aUserSearchStr   ) != -1 ||
    1154           0 :                             aStorageURL.indexOf( aSharedSearchStr ) != -1 ||
    1155           0 :                             aStorageURL.indexOf( aBundledSearchStr ) != -1 ||
    1156           0 :                             aStorageURL.indexOf( aInstSearchStr   ) != -1 )
    1157             :                         {
    1158           0 :                             bCreateLink = false;
    1159             :                         }
    1160           0 :                         if( bCreateLink )
    1161             :                         {
    1162           0 :                             createLibraryLink( aLibName, pImplLib->maStorageURL, pImplLib->mbReadOnly );
    1163           0 :                         }
    1164             :                     }
    1165             :                     else
    1166             :                     {
    1167             :                         // Move folder if not already done
    1168           0 :                         INetURLObject aUserBasicLibFolderInetObj( aUserBasicInetObj );
    1169           0 :                         aUserBasicLibFolderInetObj.Append( aLibName );
    1170           0 :                         OUString aLibFolder = aUserBasicLibFolderInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1171             : 
    1172           0 :                         INetURLObject aPrevUserBasicLibFolderInetObj( aPrevUserBasicInetObj );
    1173           0 :                         aPrevUserBasicLibFolderInetObj.Append( aLibName );
    1174           0 :                         OUString aPrevLibFolder = aPrevUserBasicLibFolderInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1175             : 
    1176           0 :                         if( mxSFI->isFolder( aPrevLibFolder ) && !mxSFI->isFolder( aLibFolder ) )
    1177             :                         {
    1178           0 :                             mxSFI->move( aPrevLibFolder, aLibFolder );
    1179             :                         }
    1180             : 
    1181           0 :                         if( aLibName == aStandardStr )
    1182             :                         {
    1183           0 :                             maNameContainer.removeByName( aLibName );
    1184             :                         }
    1185             : 
    1186             :                         // Create library
    1187           0 :                         Reference< XNameContainer > xLib = createLibrary( aLibName );
    1188           0 :                            SfxLibrary* pNewLib = static_cast< SfxLibrary* >( xLib.get() );
    1189           0 :                         pNewLib->mbLoaded = false;
    1190           0 :                         pNewLib->implSetModified( false );
    1191             :                         checkStorageURL( aLibFolder, pNewLib->maLibInfoFileURL,
    1192           0 :                                          pNewLib->maStorageURL, pNewLib->maUnexpandedStorageURL );
    1193             : 
    1194           0 :                         uno::Reference< embed::XStorage > xDummyStor;
    1195           0 :                         ::xmlscript::LibDescriptor aLibDesc;
    1196           0 :                         implLoadLibraryIndexFile( pNewLib, aLibDesc, xDummyStor, pNewLib->maLibInfoFileURL );
    1197           0 :                         implImportLibDescriptor( pNewLib, aLibDesc );
    1198             :                     }
    1199           0 :                 }
    1200           0 :                 mxSFI->kill( aPrevFolder );
    1201        3906 :             }
    1202             :         }
    1203           0 :         catch(const Exception& e)
    1204             :         {
    1205           0 :             bCleanUp = true;
    1206             :             SAL_WARN("basic", "Upgrade of Basic installation failed somehow: " << e.Message);
    1207             :         }
    1208             : 
    1209             :         // #i93163
    1210        3906 :         if( bCleanUp )
    1211             :         {
    1212           0 :             INetURLObject aPrevUserBasicInetObj_Err( aUserBasicInetObj );
    1213           0 :             aPrevUserBasicInetObj_Err.removeSegment();
    1214           0 :             aPrevUserBasicInetObj_Err.Append( "__basic_80_err" );
    1215           0 :             OUString aPrevFolder_Err = aPrevUserBasicInetObj_Err.GetMainURL( INetURLObject::NO_DECODE );
    1216             : 
    1217           0 :             bool bSaved = false;
    1218             :             try
    1219             :             {
    1220           0 :                 OUString aPrevFolder_1 = aPrevUserBasicInetObj_1.GetMainURL( INetURLObject::NO_DECODE );
    1221           0 :                 if( mxSFI->isFolder( aPrevFolder_1 ) )
    1222             :                 {
    1223           0 :                     mxSFI->move( aPrevFolder_1, aPrevFolder_Err );
    1224           0 :                     bSaved = true;
    1225           0 :                 }
    1226             :             }
    1227           0 :             catch(const Exception& )
    1228             :             {}
    1229             :             try
    1230             :             {
    1231           0 :                 OUString aPrevFolder_2 = aPrevUserBasicInetObj_2.GetMainURL( INetURLObject::NO_DECODE );
    1232           0 :                 if( !bSaved && mxSFI->isFolder( aPrevFolder_2 ) )
    1233             :                 {
    1234           0 :                     mxSFI->move( aPrevFolder_2, aPrevFolder_Err );
    1235             :                 }
    1236             :                 else
    1237             :                 {
    1238           0 :                     mxSFI->kill( aPrevFolder_2 );
    1239           0 :                 }
    1240             :             }
    1241           0 :             catch(const Exception& )
    1242           0 :             {}
    1243        3906 :         }
    1244        3907 :     }
    1245             : }
    1246             : 
    1247         142 : void SfxLibraryContainer::implScanExtensions( void )
    1248             : {
    1249             : #if HAVE_FEATURE_EXTENSIONS
    1250         142 :     ScriptExtensionIterator aScriptIt;
    1251         284 :     OUString aLibURL;
    1252             : 
    1253         142 :     bool bPureDialogLib = false;
    1254         284 :     while ( !(aLibURL = aScriptIt.nextBasicOrDialogLibrary( bPureDialogLib )).isEmpty())
    1255             :     {
    1256           0 :         if( bPureDialogLib && maInfoFileName == "script" )
    1257             :         {
    1258           0 :             continue;
    1259             :         }
    1260             :         // Extract lib name
    1261           0 :         sal_Int32 nLen = aLibURL.getLength();
    1262           0 :         sal_Int32 indexLastSlash = aLibURL.lastIndexOf( '/' );
    1263           0 :         sal_Int32 nReduceCopy = 0;
    1264           0 :         if( indexLastSlash == nLen - 1 )
    1265             :         {
    1266           0 :             nReduceCopy = 1;
    1267           0 :             indexLastSlash = aLibURL.lastIndexOf( '/', nLen - 1 );
    1268             :         }
    1269             : 
    1270           0 :         OUString aLibName = aLibURL.copy( indexLastSlash + 1, nLen - indexLastSlash - nReduceCopy - 1 );
    1271             : 
    1272             :         // If a library of the same exists the existing library wins
    1273           0 :         if( hasByName( aLibName ) )
    1274             :         {
    1275           0 :             continue;
    1276             :         }
    1277             :         // Add index file to URL
    1278           0 :         OUString aIndexFileURL = aLibURL;
    1279           0 :         if( nReduceCopy == 0 )
    1280             :         {
    1281           0 :             aIndexFileURL += "/";
    1282             :         }
    1283           0 :         aIndexFileURL += maInfoFileName + ".xlb";
    1284             : 
    1285             :         // Create link
    1286           0 :         const bool bReadOnly = false;
    1287           0 :         Reference< XNameAccess > xLib = createLibraryLink( aLibName, aIndexFileURL, bReadOnly );
    1288         142 :     }
    1289             : #endif
    1290         130 : }
    1291             : 
    1292             : // Handle maLibInfoFileURL and maStorageURL correctly
    1293        1334 : void SfxLibraryContainer::checkStorageURL( const OUString& aSourceURL,
    1294             :                                            OUString& aLibInfoFileURL, OUString& aStorageURL,
    1295             :                                            OUString& aUnexpandedStorageURL )
    1296             : {
    1297        1334 :     OUString aExpandedSourceURL = expand_url( aSourceURL );
    1298        1334 :     if( aExpandedSourceURL != aSourceURL )
    1299             :     {
    1300        1334 :         aUnexpandedStorageURL = aSourceURL;
    1301             :     }
    1302        2668 :     INetURLObject aInetObj( aExpandedSourceURL );
    1303        2668 :     OUString aExtension = aInetObj.getExtension();
    1304        1334 :     if( aExtension == "xlb" )
    1305             :     {
    1306             :         // URL to xlb file
    1307        1334 :         aLibInfoFileURL = aExpandedSourceURL;
    1308        1334 :         aInetObj.removeSegment();
    1309        1334 :         aStorageURL = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1310             :     }
    1311             :     else
    1312             :     {
    1313             :         // URL to library folder
    1314           0 :         aStorageURL = aExpandedSourceURL;
    1315           0 :         aInetObj.insertName( maInfoFileName, false, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
    1316           0 :         aInetObj.setExtension( OUString("xlb") );
    1317           0 :         aLibInfoFileURL = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1318        1334 :     }
    1319        1334 : }
    1320             : 
    1321       10609 : SfxLibrary* SfxLibraryContainer::getImplLib( const OUString& rLibraryName )
    1322             : {
    1323       10609 :     Any aLibAny = maNameContainer.getByName( rLibraryName ) ;
    1324       21218 :     Reference< XNameAccess > xNameAccess;
    1325       10609 :     aLibAny >>= xNameAccess;
    1326       10609 :     SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
    1327       21218 :     return pImplLib;
    1328             : }
    1329             : 
    1330             : 
    1331             : // Storing with password encryption
    1332             : 
    1333             : // Empty implementation, avoids unneccesary implementation in dlgcont.cxx
    1334           0 : bool SfxLibraryContainer::implStorePasswordLibrary( SfxLibrary*,
    1335             :                                                     const OUString&,
    1336             :                                                     const uno::Reference< embed::XStorage >&,
    1337             :                                                     const uno::Reference< task::XInteractionHandler >&  )
    1338             : {
    1339           0 :     return false;
    1340             : }
    1341             : 
    1342           0 : bool SfxLibraryContainer::implStorePasswordLibrary(
    1343             :     SfxLibrary* /*pLib*/,
    1344             :     const OUString& /*aName*/,
    1345             :     const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& /*xStorage*/,
    1346             :     const OUString& /*aTargetURL*/,
    1347             :     const Reference< XSimpleFileAccess3 > /*xToUseSFI*/,
    1348             :     const uno::Reference< task::XInteractionHandler >&  )
    1349             : {
    1350           0 :     return false;
    1351             : }
    1352             : 
    1353           0 : bool SfxLibraryContainer::implLoadPasswordLibrary(
    1354             :     SfxLibrary* /*pLib*/,
    1355             :     const OUString& /*Name*/,
    1356             :     bool /*bVerifyPasswordOnly*/ )
    1357             : throw(WrappedTargetException, RuntimeException)
    1358             : {
    1359           0 :     return true;
    1360             : }
    1361             : 
    1362             : 
    1363             : 
    1364             : #define EXPAND_PROTOCOL "vnd.sun.star.expand"
    1365             : 
    1366        1334 : OUString SfxLibraryContainer::createAppLibraryFolder( SfxLibrary* pLib, const OUString& aName )
    1367             : {
    1368        1334 :     OUString aLibDirPath = pLib->maStorageURL;
    1369        1334 :     if( aLibDirPath.isEmpty() )
    1370             :     {
    1371           0 :         INetURLObject aInetObj( maLibraryPath.getToken(1, (sal_Unicode)';') );
    1372           0 :         aInetObj.insertName( aName, true, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
    1373             :         checkStorageURL( aInetObj.GetMainURL( INetURLObject::NO_DECODE ), pLib->maLibInfoFileURL,
    1374           0 :                          pLib->maStorageURL, pLib->maUnexpandedStorageURL );
    1375           0 :         aLibDirPath = pLib->maStorageURL;
    1376             :     }
    1377             : 
    1378        1334 :     if( !mxSFI->isFolder( aLibDirPath ) )
    1379             :     {
    1380             :         try
    1381             :         {
    1382           0 :             mxSFI->createFolder( aLibDirPath );
    1383             :         }
    1384           0 :         catch(const Exception& )
    1385             :         {}
    1386             :     }
    1387             : 
    1388        1334 :     return aLibDirPath;
    1389             : }
    1390             : 
    1391             : // Storing
    1392           2 : void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
    1393             :                                             const OUString& aName,
    1394             :                                             const uno::Reference< embed::XStorage >& xStorage )
    1395             : {
    1396           2 :     OUString aDummyLocation;
    1397           4 :     Reference< XSimpleFileAccess3 > xDummySFA;
    1398           4 :     Reference< XInteractionHandler > xDummyHandler;
    1399           4 :     implStoreLibrary( pLib, aName, xStorage, aDummyLocation, xDummySFA, xDummyHandler );
    1400           2 : }
    1401             : 
    1402             : // New variant for library export
    1403           2 : void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
    1404             :                                             const OUString& aName,
    1405             :                                             const uno::Reference< embed::XStorage >& xStorage,
    1406             :                                             const OUString& aTargetURL,
    1407             :                                             Reference< XSimpleFileAccess3 > xToUseSFI,
    1408             :                                             const Reference< XInteractionHandler >& xHandler )
    1409             : {
    1410           2 :     bool bLink = pLib->mbLink;
    1411           2 :     bool bStorage = xStorage.is() && !bLink;
    1412             : 
    1413           2 :     Sequence< OUString > aElementNames = pLib->getElementNames();
    1414           2 :     sal_Int32 nNameCount = aElementNames.getLength();
    1415           2 :     const OUString* pNames = aElementNames.getConstArray();
    1416             : 
    1417           2 :     if( bStorage )
    1418             :     {
    1419           4 :         for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
    1420             :         {
    1421           2 :             OUString aElementName = pNames[ i ];
    1422           4 :             OUString aStreamName = aElementName;
    1423           2 :             aStreamName += ".xml";
    1424             : 
    1425           2 :             if( !isLibraryElementValid( pLib->getByName( aElementName ) ) )
    1426             :             {
    1427             :                 SAL_WARN(
    1428             :                     "basic",
    1429             :                     "invalid library element \"" << aElementName << '"');
    1430           0 :                 continue;
    1431             :             }
    1432             :             try
    1433             :             {
    1434           2 :                 uno::Reference< io::XStream > xElementStream = xStorage->openStreamElement(
    1435             :                                                                     aStreamName,
    1436           2 :                                                                     embed::ElementModes::READWRITE );
    1437             :                 //    throw uno::RuntimeException(); // TODO: method must either return the stream or throw an exception
    1438             : 
    1439           4 :                 OUString aMime( "text/xml" );
    1440             : 
    1441           4 :                 uno::Reference< beans::XPropertySet > xProps( xElementStream, uno::UNO_QUERY );
    1442             :                 SAL_WARN_IF(
    1443             :                     !xProps.is(), "basic",
    1444             :                     "The StorageStream must implement XPropertySet interface!");
    1445             :                 //if ( !xProps.is() ) //TODO
    1446             : 
    1447           2 :                 if ( xProps.is() )
    1448             :                 {
    1449           2 :                     xProps->setPropertyValue("MediaType", uno::makeAny( aMime ) );
    1450             : 
    1451             :                     // #87671 Allow encryption
    1452           2 :                     xProps->setPropertyValue("UseCommonStoragePasswordEncryption", uno::makeAny( sal_True ) );
    1453             : 
    1454           2 :                     Reference< XOutputStream > xOutput = xElementStream->getOutputStream();
    1455           4 :                     Reference< XNameContainer > xLib( pLib );
    1456           4 :                     writeLibraryElement( xLib, aElementName, xOutput );
    1457           2 :                 }
    1458             :             }
    1459           0 :             catch(const uno::Exception& )
    1460             :             {
    1461             :                 SAL_WARN("basic", "Problem during storing of library!");
    1462             :                 // TODO: error handling?
    1463             :             }
    1464           2 :         }
    1465           2 :         pLib->storeResourcesToStorage( xStorage );
    1466             :     }
    1467             :     else
    1468             :     {
    1469             :         // Export?
    1470           0 :         bool bExport = !aTargetURL.isEmpty();
    1471             :         try
    1472             :         {
    1473           0 :             Reference< XSimpleFileAccess3 > xSFI = mxSFI;
    1474           0 :             if( xToUseSFI.is() )
    1475             :             {
    1476           0 :                 xSFI = xToUseSFI;
    1477             :             }
    1478           0 :             OUString aLibDirPath;
    1479           0 :             if( bExport )
    1480             :             {
    1481           0 :                 INetURLObject aInetObj( aTargetURL );
    1482           0 :                 aInetObj.insertName( aName, true, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
    1483           0 :                 aLibDirPath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1484             : 
    1485           0 :                 if( !xSFI->isFolder( aLibDirPath ) )
    1486             :                 {
    1487           0 :                     xSFI->createFolder( aLibDirPath );
    1488             :                 }
    1489           0 :                 pLib->storeResourcesToURL( aLibDirPath, xHandler );
    1490             :             }
    1491             :             else
    1492             :             {
    1493           0 :                 aLibDirPath = createAppLibraryFolder( pLib, aName );
    1494           0 :                 pLib->storeResources();
    1495             :             }
    1496             : 
    1497           0 :             for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
    1498             :             {
    1499           0 :                 OUString aElementName = pNames[ i ];
    1500             : 
    1501           0 :                 INetURLObject aElementInetObj( aLibDirPath );
    1502             :                 aElementInetObj.insertName( aElementName, false,
    1503             :                                             INetURLObject::LAST_SEGMENT, true,
    1504           0 :                                             INetURLObject::ENCODE_ALL );
    1505           0 :                 aElementInetObj.setExtension( maLibElementFileExtension );
    1506           0 :                 OUString aElementPath( aElementInetObj.GetMainURL( INetURLObject::NO_DECODE ) );
    1507             : 
    1508           0 :                 if( !isLibraryElementValid( pLib->getByName( aElementName ) ) )
    1509             :                 {
    1510             :                     SAL_WARN(
    1511             :                         "basic",
    1512             :                         "invalid library element \"" << aElementName << '"');
    1513           0 :                     continue;
    1514             :                 }
    1515             : 
    1516             :                 // TODO: Check modified
    1517             :                 try
    1518             :                 {
    1519           0 :                     if( xSFI->exists( aElementPath ) )
    1520             :                     {
    1521           0 :                         xSFI->kill( aElementPath );
    1522             :                     }
    1523           0 :                     Reference< XOutputStream > xOutput = xSFI->openFileWrite( aElementPath );
    1524           0 :                     Reference< XNameContainer > xLib( pLib );
    1525           0 :                     writeLibraryElement( xLib, aElementName, xOutput );
    1526           0 :                     xOutput->closeOutput();
    1527             :                 }
    1528           0 :                 catch(const Exception& )
    1529             :                 {
    1530           0 :                     if( bExport )
    1531             :                     {
    1532           0 :                         throw;
    1533             :                     }
    1534           0 :                     SfxErrorContext aEc( ERRCTX_SFX_SAVEDOC, aElementPath );
    1535           0 :                     ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
    1536             :                 }
    1537           0 :             }
    1538             :         }
    1539           0 :         catch(const Exception& )
    1540             :         {
    1541           0 :             if( bExport )
    1542             :             {
    1543           0 :                 throw;
    1544             :             }
    1545             :         }
    1546           2 :     }
    1547           2 : }
    1548             : 
    1549           2 : void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
    1550             :                                                      const ::xmlscript::LibDescriptor& rLib,
    1551             :                                                      const uno::Reference< embed::XStorage >& xStorage )
    1552             : {
    1553           2 :     OUString aDummyLocation;
    1554           4 :     Reference< XSimpleFileAccess3 > xDummySFA;
    1555           4 :     implStoreLibraryIndexFile( pLib, rLib, xStorage, aDummyLocation, xDummySFA );
    1556           2 : }
    1557             : 
    1558             : // New variant for library export
    1559           2 : void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
    1560             :                                                      const ::xmlscript::LibDescriptor& rLib,
    1561             :                                                      const uno::Reference< embed::XStorage >& xStorage,
    1562             :                                                      const OUString& aTargetURL,
    1563             :                                                      Reference< XSimpleFileAccess3 > xToUseSFI )
    1564             : {
    1565             :     // Create sax writer
    1566           2 :     Reference< XWriter > xWriter = xml::sax::Writer::create(mxContext);
    1567             : 
    1568           2 :     bool bLink = pLib->mbLink;
    1569           2 :     bool bStorage = xStorage.is() && !bLink;
    1570             : 
    1571             :     // Write info file
    1572           4 :     uno::Reference< io::XOutputStream > xOut;
    1573           4 :     uno::Reference< io::XStream > xInfoStream;
    1574           2 :     if( bStorage )
    1575             :     {
    1576           2 :         OUString aStreamName( maInfoFileName );
    1577           2 :         aStreamName += "-lb.xml";
    1578             : 
    1579             :         try
    1580             :         {
    1581           2 :             xInfoStream = xStorage->openStreamElement( aStreamName, embed::ElementModes::READWRITE );
    1582             :             SAL_WARN_IF(!xInfoStream.is(), "basic", "No stream!");
    1583           2 :             uno::Reference< beans::XPropertySet > xProps( xInfoStream, uno::UNO_QUERY );
    1584             :             //    throw uno::RuntimeException(); // TODO
    1585             : 
    1586           2 :             if ( xProps.is() )
    1587             :             {
    1588           2 :                 OUString aMime("text/xml");
    1589           2 :                 xProps->setPropertyValue("MediaType", uno::makeAny( aMime ) );
    1590             : 
    1591             :                 // #87671 Allow encryption
    1592           2 :                 xProps->setPropertyValue("UseCommonStoragePasswordEncryption", uno::makeAny( sal_True ) );
    1593             : 
    1594           2 :                 xOut = xInfoStream->getOutputStream();
    1595           2 :             }
    1596             :         }
    1597           0 :         catch(const uno::Exception& )
    1598             :         {
    1599             :             SAL_WARN("basic", "Problem during storing of library index file!");
    1600             :             // TODO: error handling?
    1601           2 :         }
    1602             :     }
    1603             :     else
    1604             :     {
    1605             :         // Export?
    1606           0 :         bool bExport = !aTargetURL.isEmpty();
    1607           0 :         Reference< XSimpleFileAccess3 > xSFI = mxSFI;
    1608           0 :         if( xToUseSFI.is() )
    1609             :         {
    1610           0 :             xSFI = xToUseSFI;
    1611             :         }
    1612           0 :         OUString aLibInfoPath;
    1613           0 :         if( bExport )
    1614             :         {
    1615           0 :             INetURLObject aInetObj( aTargetURL );
    1616           0 :             aInetObj.insertName( rLib.aName, true, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
    1617           0 :             OUString aLibDirPath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1618           0 :             if( !xSFI->isFolder( aLibDirPath ) )
    1619             :             {
    1620           0 :                 xSFI->createFolder( aLibDirPath );
    1621             :             }
    1622           0 :             aInetObj.insertName( maInfoFileName, false, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
    1623           0 :             aInetObj.setExtension( OUString( "xlb" ) );
    1624           0 :             aLibInfoPath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
    1625             :         }
    1626             :         else
    1627             :         {
    1628           0 :             createAppLibraryFolder( pLib, rLib.aName );
    1629           0 :             aLibInfoPath = pLib->maLibInfoFileURL;
    1630             :         }
    1631             : 
    1632             :         try
    1633             :         {
    1634           0 :             if( xSFI->exists( aLibInfoPath ) )
    1635             :             {
    1636           0 :                 xSFI->kill( aLibInfoPath );
    1637             :             }
    1638           0 :             xOut = xSFI->openFileWrite( aLibInfoPath );
    1639             :         }
    1640           0 :         catch(const Exception& )
    1641             :         {
    1642           0 :             if( bExport )
    1643             :             {
    1644           0 :                 throw;
    1645             :             }
    1646           0 :             SfxErrorContext aEc( ERRCTX_SFX_SAVEDOC, aLibInfoPath );
    1647           0 :             ErrorHandler::HandleError(  ERRCODE_IO_GENERAL );
    1648           0 :         }
    1649             :     }
    1650           2 :     if( !xOut.is() )
    1651             :     {
    1652             :         SAL_WARN("basic", "couldn't open output stream");
    1653           2 :         return;
    1654             :     }
    1655           2 :     xWriter->setOutputStream( xOut );
    1656           4 :     xmlscript::exportLibrary( xWriter, rLib );
    1657             : }
    1658             : 
    1659             : 
    1660        1340 : bool SfxLibraryContainer::implLoadLibraryIndexFile(  SfxLibrary* pLib,
    1661             :                                                      ::xmlscript::LibDescriptor& rLib,
    1662             :                                                      const uno::Reference< embed::XStorage >& xStorage,
    1663             :                                                      const OUString& aIndexFileName )
    1664             : {
    1665        1340 :     Reference< XParser > xParser = xml::sax::Parser::create(mxContext);
    1666             : 
    1667        1340 :     bool bLink = false;
    1668        1340 :     bool bStorage = false;
    1669        1340 :     if( pLib )
    1670             :     {
    1671        1340 :         bLink = pLib->mbLink;
    1672        1340 :         bStorage = xStorage.is() && !bLink;
    1673             :     }
    1674             : 
    1675             :     // Read info file
    1676        2680 :     uno::Reference< io::XInputStream > xInput;
    1677        2680 :     OUString aLibInfoPath;
    1678        1340 :     if( bStorage )
    1679             :     {
    1680           6 :         aLibInfoPath = maInfoFileName;
    1681           6 :         aLibInfoPath += "-lb.xml";
    1682             : 
    1683             :         try
    1684             :         {
    1685             :             uno::Reference< io::XStream > xInfoStream =
    1686           6 :                 xStorage->openStreamElement( aLibInfoPath, embed::ElementModes::READ );
    1687           6 :             xInput = xInfoStream->getInputStream();
    1688             :         }
    1689           0 :         catch(const uno::Exception& )
    1690             :         {}
    1691             :     }
    1692             :     else
    1693             :     {
    1694             :         // Create Input stream
    1695             :         //String aLibInfoPath; // attention: THIS PROBLEM MUST BE REVIEWED BY SCRIPTING OWNER!!!
    1696             : 
    1697        1334 :         if( pLib )
    1698             :         {
    1699        1334 :             createAppLibraryFolder( pLib, rLib.aName );
    1700        1334 :             aLibInfoPath = pLib->maLibInfoFileURL;
    1701             :         }
    1702             :         else
    1703             :         {
    1704           0 :             aLibInfoPath = aIndexFileName;
    1705             :         }
    1706             :         try
    1707             :         {
    1708        1334 :             xInput = mxSFI->openFileRead( aLibInfoPath );
    1709             :         }
    1710           0 :         catch(const Exception& )
    1711             :         {
    1712           0 :             xInput.clear();
    1713           0 :             if( !GbMigrationSuppressErrors )
    1714             :             {
    1715           0 :                 SfxErrorContext aEc( ERRCTX_SFX_LOADBASIC, aLibInfoPath );
    1716           0 :                 ErrorHandler::HandleError(  ERRCODE_IO_GENERAL );
    1717             :             }
    1718             :         }
    1719             :     }
    1720        1340 :     if( !xInput.is() )
    1721             :     {
    1722           0 :         return false;
    1723             :     }
    1724             : 
    1725        2680 :     InputSource source;
    1726        1340 :     source.aInputStream = xInput;
    1727        1340 :     source.sSystemId    = aLibInfoPath;
    1728             : 
    1729             :     // start parsing
    1730             :     try
    1731             :     {
    1732        1340 :         xParser->setDocumentHandler( ::xmlscript::importLibrary( rLib ) );
    1733        1340 :         xParser->parseStream( source );
    1734             :     }
    1735           0 :     catch(const Exception& )
    1736             :     {
    1737             :         SAL_WARN("basic", "Parsing error");
    1738           0 :         SfxErrorContext aEc( ERRCTX_SFX_LOADBASIC, aLibInfoPath );
    1739           0 :         ErrorHandler::HandleError(  ERRCODE_IO_GENERAL );
    1740           0 :         return false;
    1741             :     }
    1742             : 
    1743        1340 :     if( !pLib )
    1744             :     {
    1745           0 :         Reference< XNameContainer > xLib = createLibrary( rLib.aName );
    1746           0 :         pLib = static_cast< SfxLibrary* >( xLib.get() );
    1747           0 :         pLib->mbLoaded = false;
    1748           0 :         rLib.aStorageURL = aIndexFileName;
    1749             :         checkStorageURL( rLib.aStorageURL, pLib->maLibInfoFileURL, pLib->maStorageURL,
    1750           0 :                          pLib->maUnexpandedStorageURL );
    1751             : 
    1752           0 :         implImportLibDescriptor( pLib, rLib );
    1753             :     }
    1754             : 
    1755        2680 :     return true;
    1756             : }
    1757             : 
    1758        2618 : void SfxLibraryContainer::implImportLibDescriptor( SfxLibrary* pLib,
    1759             :                                                    ::xmlscript::LibDescriptor& rLib )
    1760             : {
    1761        2618 :     if( !pLib->mbInitialised )
    1762             :     {
    1763        1340 :         sal_Int32 nElementCount = rLib.aElementNames.getLength();
    1764        1340 :         const OUString* pElementNames = rLib.aElementNames.getConstArray();
    1765        1340 :         Any aDummyElement = createEmptyLibraryElement();
    1766        7768 :         for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
    1767             :         {
    1768        6428 :             pLib->maNameContainer.insertByName( pElementNames[i], aDummyElement );
    1769             :         }
    1770        1340 :         pLib->mbPasswordProtected = rLib.bPasswordProtected;
    1771        1340 :         pLib->mbReadOnly = rLib.bReadOnly;
    1772        1340 :         pLib->mbPreload  = rLib.bPreload;
    1773        1340 :         pLib->implSetModified( false );
    1774        1340 :         pLib->mbInitialised = true;
    1775             :     }
    1776        2618 : }
    1777             : 
    1778             : 
    1779             : // Methods of new XLibraryStorage interface?
    1780        1270 : void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XStorage >& i_rStorage,
    1781             :                                                bool bComplete )
    1782             : {
    1783        1270 :     const Sequence< OUString > aNames = maNameContainer.getElementNames();
    1784        1270 :     sal_Int32 nNameCount = aNames.getLength();
    1785        1270 :     const OUString* pName = aNames.getConstArray();
    1786        1270 :     const OUString* pNamesEnd = aNames.getConstArray() + nNameCount;
    1787             : 
    1788             :     // Don't count libs from shared index file
    1789        1270 :     sal_Int32 nLibsToSave = nNameCount;
    1790        3092 :     for( ; pName != pNamesEnd; ++pName )
    1791             :     {
    1792        1822 :         SfxLibrary* pImplLib = getImplLib( *pName );
    1793        1822 :         if( pImplLib->mbSharedIndexFile || pImplLib->mbExtension )
    1794             :         {
    1795         558 :             nLibsToSave--;
    1796             :         }
    1797             :     }
    1798        1270 :     if( !nLibsToSave )
    1799             :     {
    1800           6 :         return;
    1801             :     }
    1802        1266 :     boost::scoped_ptr< ::xmlscript::LibDescriptorArray > pLibArray(new ::xmlscript::LibDescriptorArray(nLibsToSave));
    1803             : 
    1804             :     // Write to storage?
    1805        1264 :     bool bStorage = i_rStorage.is();
    1806        1266 :     uno::Reference< embed::XStorage > xSourceLibrariesStor;
    1807        1266 :     uno::Reference< embed::XStorage > xTargetLibrariesStor;
    1808        1266 :     OUString sTempTargetStorName;
    1809        1264 :     const bool bInplaceStorage = bStorage && ( i_rStorage == mxStorage );
    1810        1264 :     if ( bStorage )
    1811             :     {
    1812             :         // Don't write if only empty standard lib exists
    1813        1208 :         if ( ( nNameCount == 1 ) && ( aNames[0] == "Standard" ) )
    1814             :         {
    1815        1208 :             Any aLibAny = maNameContainer.getByName( aNames[0] );
    1816        1210 :             Reference< XNameAccess > xNameAccess;
    1817        1208 :             aLibAny >>= xNameAccess;
    1818        1208 :             if ( ! ( xNameAccess->hasElements() || ( bInplaceStorage && isModified() ) ) )
    1819             :             {
    1820        1206 :                 return;
    1821           2 :             }
    1822             :         }
    1823             : 
    1824             :         // create the empty target storage
    1825             :         try
    1826             :         {
    1827           2 :             OUString sTargetLibrariesStoreName;
    1828           2 :             if ( bInplaceStorage )
    1829             :             {
    1830             :                 // create a temporary target storage
    1831           2 :                 const OUStringBuffer aTempTargetNameBase = maLibrariesDir + OUString( "_temp_" );
    1832           2 :                 sal_Int32 index = 0;
    1833             :                 do
    1834             :                 {
    1835           2 :                     OUStringBuffer aTempTargetName( aTempTargetNameBase );
    1836           2 :                     aTempTargetName.append( index++ );
    1837             : 
    1838           2 :                     sTargetLibrariesStoreName = aTempTargetName.makeStringAndClear();
    1839           2 :                     if ( !i_rStorage->hasByName( sTargetLibrariesStoreName ) )
    1840             :                     {
    1841           2 :                         break;
    1842           0 :                     }
    1843             :                 }
    1844             :                 while ( true );
    1845           2 :                 sTempTargetStorName = sTargetLibrariesStoreName;
    1846             :             }
    1847             :             else
    1848             :             {
    1849           0 :                 sTargetLibrariesStoreName = maLibrariesDir;
    1850           0 :                 if ( i_rStorage->hasByName( sTargetLibrariesStoreName ) )
    1851             :                 {
    1852           0 :                     i_rStorage->removeElement( sTargetLibrariesStoreName );
    1853             :                 }
    1854             :             }
    1855             : 
    1856           2 :             xTargetLibrariesStor.set( i_rStorage->openStorageElement( sTargetLibrariesStoreName, embed::ElementModes::READWRITE ), UNO_QUERY_THROW );
    1857             :         }
    1858           0 :         catch( const uno::Exception& )
    1859             :         {
    1860             :             DBG_UNHANDLED_EXCEPTION();
    1861           0 :             return;
    1862             :         }
    1863             :     }
    1864             : 
    1865          58 :     int iArray = 0;
    1866          58 :     pName = aNames.getConstArray();
    1867          60 :     ::xmlscript::LibDescriptor aLibDescriptorForExtensionLibs;
    1868         620 :     for( ; pName != pNamesEnd; ++pName )
    1869             :     {
    1870         562 :         SfxLibrary* pImplLib = getImplLib( *pName );
    1871         562 :         if( pImplLib->mbSharedIndexFile )
    1872             :         {
    1873         504 :             continue;
    1874             :         }
    1875          58 :         const bool bExtensionLib = pImplLib->mbExtension;
    1876             :         ::xmlscript::LibDescriptor& rLib = bExtensionLib ?
    1877          58 :               aLibDescriptorForExtensionLibs : pLibArray->mpLibs[iArray];
    1878          58 :         if( !bExtensionLib )
    1879             :         {
    1880          58 :             iArray++;
    1881             :         }
    1882          58 :         rLib.aName = *pName;
    1883             : 
    1884          58 :         rLib.bLink = pImplLib->mbLink;
    1885          58 :         if( !bStorage || pImplLib->mbLink )
    1886             :         {
    1887          56 :             rLib.aStorageURL = ( pImplLib->maUnexpandedStorageURL.getLength() ) ?
    1888          56 :                 pImplLib->maUnexpandedStorageURL : pImplLib->maLibInfoFileURL;
    1889             :         }
    1890          58 :         rLib.bReadOnly = pImplLib->mbReadOnly;
    1891          58 :         rLib.bPreload = pImplLib->mbPreload;
    1892          58 :         rLib.bPasswordProtected = pImplLib->mbPasswordProtected;
    1893          58 :         rLib.aElementNames = pImplLib->getElementNames();
    1894             : 
    1895          58 :         if( pImplLib->implIsModified() || bComplete )
    1896             :         {
    1897             :             {
    1898           2 :             uno::Reference< embed::XStorage > xLibraryStor;
    1899           2 :             if( bStorage )
    1900             :             {
    1901             :                 try
    1902             :                 {
    1903           6 :                     xLibraryStor = xTargetLibrariesStor->openStorageElement(
    1904             :                                                                         rLib.aName,
    1905           4 :                                                                         embed::ElementModes::READWRITE );
    1906             :                 }
    1907           0 :                 catch(const uno::Exception& )
    1908             :                 {
    1909             :                     #if OSL_DEBUG_LEVEL > 0
    1910             :                     Any aError( ::cppu::getCaughtException() );
    1911             :                     SAL_WARN(
    1912             :                         "basic",
    1913             :                         "couldn't create sub storage for library \""
    1914             :                             << rLib.aName << "\". Exception: "
    1915             :                             << comphelper::anyToString(aError));
    1916             :                     #endif
    1917           0 :                     throw;
    1918             :                 }
    1919             :             }
    1920             : 
    1921             :                 // Maybe lib is not loaded?!
    1922           2 :                 if( bComplete )
    1923             :                 {
    1924           2 :                     loadLibrary( rLib.aName );
    1925             :                 }
    1926           2 :                 if( pImplLib->mbPasswordProtected )
    1927             :                 {
    1928           0 :                     implStorePasswordLibrary( pImplLib, rLib.aName, xLibraryStor, uno::Reference< task::XInteractionHandler >() );
    1929             :                     // TODO: Check return value
    1930             :                 }
    1931             :                 else
    1932             :                 {
    1933           2 :                     implStoreLibrary( pImplLib, rLib.aName, xLibraryStor );
    1934             :                 }
    1935           2 :                 implStoreLibraryIndexFile( pImplLib, rLib, xLibraryStor );
    1936           2 :                 if( bStorage )
    1937             :                 {
    1938             :                     try
    1939             :                     {
    1940           2 :                         uno::Reference< embed::XTransactedObject > xTransact( xLibraryStor, uno::UNO_QUERY_THROW );
    1941           2 :                         xTransact->commit();
    1942             :                     }
    1943           0 :                     catch(const uno::Exception& )
    1944             :                     {
    1945             :                         DBG_UNHANDLED_EXCEPTION();
    1946             :                         // TODO: error handling
    1947           0 :                         throw;
    1948             :                     }
    1949           2 :                 }
    1950             :             }
    1951           2 :             maModifiable.setModified( true );
    1952           2 :             pImplLib->implSetModified( false );
    1953             :         }
    1954             : 
    1955             :         // For container info ReadOnly refers to mbReadOnlyLink
    1956          58 :         rLib.bReadOnly = pImplLib->mbReadOnlyLink;
    1957             :     }
    1958             : 
    1959             :     // if we did an in-place save into a storage (i.e. a save into the storage we were already based on),
    1960             :     // then we need to clean up the temporary storage we used for this
    1961          58 :     if ( bInplaceStorage && !sTempTargetStorName.isEmpty() )
    1962             :     {
    1963             :         // open the source storage which might be used to copy yet-unmodified libraries
    1964             :         try
    1965             :         {
    1966           2 :             if ( mxStorage->hasByName( maLibrariesDir ) || bInplaceStorage )
    1967             :             {
    1968           6 :                 xSourceLibrariesStor = mxStorage->openStorageElement( maLibrariesDir,
    1969           4 :                                                    bInplaceStorage ? embed::ElementModes::READWRITE : embed::ElementModes::READ );
    1970             :             }
    1971             :         }
    1972           0 :         catch( const uno::Exception& )
    1973             :         {
    1974             :             DBG_UNHANDLED_EXCEPTION();
    1975           0 :             return;
    1976             :         }
    1977             : 
    1978             :         SAL_WARN_IF(
    1979             :             !xSourceLibrariesStor.is(), "basic",
    1980             :             ("SfxLibrariesContainer::storeLibraries_impl: unexpected: we should"
    1981             :              " have a source storage here!"));
    1982             :         try
    1983             :         {
    1984             :             // for this, we first remove everything from the source storage, then copy the complete content
    1985             :             // from the temporary target storage. From then on, what used to be the "source storage" becomes
    1986             :             // the "targt storage" for all subsequent operations.
    1987             : 
    1988             :             // (We cannot simply remove the storage, denoted by maLibrariesDir, from i_rStorage - there might be
    1989             :             // open references to it.)
    1990             : 
    1991           2 :             if ( xSourceLibrariesStor.is() )
    1992             :             {
    1993             :                 // remove
    1994           2 :                 const Sequence< OUString > aRemoveNames( xSourceLibrariesStor->getElementNames() );
    1995          12 :                 for ( const OUString* pRemoveName = aRemoveNames.getConstArray();
    1996           6 :                       pRemoveName != aRemoveNames.getConstArray() + aRemoveNames.getLength();
    1997             :                       ++pRemoveName
    1998             :                     )
    1999             :                 {
    2000           4 :                     xSourceLibrariesStor->removeElement( *pRemoveName );
    2001             :                 }
    2002             : 
    2003             :                 // copy
    2004           4 :                 const Sequence< OUString > aCopyNames( xTargetLibrariesStor->getElementNames() );
    2005           8 :                 for ( const OUString* pCopyName = aCopyNames.getConstArray();
    2006           4 :                       pCopyName != aCopyNames.getConstArray() + aCopyNames.getLength();
    2007             :                       ++pCopyName
    2008             :                     )
    2009             :                 {
    2010           2 :                     xTargetLibrariesStor->copyElementTo( *pCopyName, xSourceLibrariesStor, *pCopyName );
    2011           2 :                 }
    2012             :             }
    2013             : 
    2014             :             // close and remove temp target
    2015           2 :             xTargetLibrariesStor->dispose();
    2016           2 :             i_rStorage->removeElement( sTempTargetStorName );
    2017           2 :             xTargetLibrariesStor.clear();
    2018           2 :             sTempTargetStorName = "";
    2019             : 
    2020             :             // adjust target
    2021           2 :             xTargetLibrariesStor = xSourceLibrariesStor;
    2022           2 :             xSourceLibrariesStor.clear();
    2023             :         }
    2024           0 :         catch( const Exception& )
    2025             :         {
    2026             :             DBG_UNHANDLED_EXCEPTION();
    2027           0 :             throw;
    2028             :         }
    2029             :     }
    2030             : 
    2031          58 :     if( !mbOldInfoFormat && !maModifiable.isModified() )
    2032             :     {
    2033          56 :         return;
    2034             :     }
    2035           2 :     maModifiable.setModified( false );
    2036           2 :     mbOldInfoFormat = false;
    2037             : 
    2038             :     // Write library container info
    2039             :     // Create sax writer
    2040           4 :     Reference< XWriter > xWriter = xml::sax::Writer::create(mxContext);
    2041             : 
    2042             :     // Write info file
    2043           4 :     uno::Reference< io::XOutputStream > xOut;
    2044           4 :     uno::Reference< io::XStream > xInfoStream;
    2045           2 :     if( bStorage )
    2046             :     {
    2047           2 :         OUString aStreamName( maInfoFileName );
    2048           2 :         aStreamName += "-lc.xml";
    2049             : 
    2050             :         try
    2051             :         {
    2052           2 :             xInfoStream = xTargetLibrariesStor->openStreamElement( aStreamName, embed::ElementModes::READWRITE );
    2053           2 :             uno::Reference< beans::XPropertySet > xProps( xInfoStream, uno::UNO_QUERY );
    2054             :             SAL_WARN_IF(
    2055             :                 !xProps.is(), "basic",
    2056             :                 "The stream must implement XPropertySet!");
    2057           2 :             if ( !xProps.is() )
    2058             :             {
    2059           0 :                 throw uno::RuntimeException();
    2060             :             }
    2061           4 :             OUString aMime( "text/xml" );
    2062           2 :             xProps->setPropertyValue("MediaType", uno::makeAny( aMime ) );
    2063             : 
    2064             :             // #87671 Allow encryption
    2065           2 :             xProps->setPropertyValue("UseCommonStoragePasswordEncryption", uno::makeAny( sal_True ) );
    2066             : 
    2067           4 :             xOut = xInfoStream->getOutputStream();
    2068             :         }
    2069           0 :         catch(const uno::Exception& )
    2070             :         {
    2071           0 :             ErrorHandler::HandleError(  ERRCODE_IO_GENERAL );
    2072           2 :         }
    2073             :     }
    2074             :     else
    2075             :     {
    2076             :         // Create Output stream
    2077           0 :         INetURLObject aLibInfoInetObj( maLibraryPath.getToken(1, (sal_Unicode)';') );
    2078           0 :         aLibInfoInetObj.insertName( maInfoFileName, false, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
    2079           0 :         aLibInfoInetObj.setExtension( OUString("xlc") );
    2080           0 :         OUString aLibInfoPath( aLibInfoInetObj.GetMainURL( INetURLObject::NO_DECODE ) );
    2081             : 
    2082             :         try
    2083             :         {
    2084           0 :             if( mxSFI->exists( aLibInfoPath ) )
    2085             :             {
    2086           0 :                 mxSFI->kill( aLibInfoPath );
    2087             :             }
    2088           0 :             xOut = mxSFI->openFileWrite( aLibInfoPath );
    2089             :         }
    2090           0 :         catch(const Exception& )
    2091             :         {
    2092           0 :             xOut.clear();
    2093           0 :             SfxErrorContext aEc( ERRCTX_SFX_SAVEDOC, aLibInfoPath );
    2094           0 :             ErrorHandler::HandleError(  ERRCODE_IO_GENERAL );
    2095           0 :         }
    2096             : 
    2097             :     }
    2098           2 :     if( !xOut.is() )
    2099             :     {
    2100             :         SAL_WARN("basic", "couldn't open output stream");
    2101           0 :         return;
    2102             :     }
    2103             : 
    2104           2 :     xWriter->setOutputStream( xOut );
    2105             : 
    2106             :     try
    2107             :     {
    2108           2 :         xmlscript::exportLibraryContainer( xWriter, pLibArray.get() );
    2109           2 :         if ( bStorage )
    2110             :         {
    2111           2 :             uno::Reference< embed::XTransactedObject > xTransact( xTargetLibrariesStor, uno::UNO_QUERY );
    2112             :             SAL_WARN_IF(
    2113             :                 !xTransact.is(), "basic",
    2114             :                 "The storage must implement XTransactedObject!");
    2115           2 :             if ( !xTransact.is() )
    2116             :             {
    2117           0 :                 throw uno::RuntimeException();
    2118             :             }
    2119           2 :             xTransact->commit();
    2120             :         }
    2121             :     }
    2122           0 :     catch(const uno::Exception& )
    2123             :     {
    2124             :         SAL_WARN("basic", "Problem during storing of libraries!");
    2125           0 :         ErrorHandler::HandleError(  ERRCODE_IO_GENERAL );
    2126           2 :     }
    2127             : }
    2128             : 
    2129             : 
    2130             : // Methods XElementAccess
    2131           0 : Type SAL_CALL SfxLibraryContainer::getElementType()
    2132             :     throw(RuntimeException, std::exception)
    2133             : {
    2134           0 :     LibraryContainerMethodGuard aGuard( *this );
    2135           0 :     return maNameContainer.getElementType();
    2136             : }
    2137             : 
    2138        3532 : sal_Bool SfxLibraryContainer::hasElements()
    2139             :     throw(RuntimeException, std::exception)
    2140             : {
    2141        3532 :     LibraryContainerMethodGuard aGuard( *this );
    2142        3532 :     bool bRet = maNameContainer.hasElements();
    2143        3532 :     return bRet;
    2144             : }
    2145             : 
    2146             : // Methods XNameAccess
    2147        4638 : Any SfxLibraryContainer::getByName( const OUString& aName )
    2148             :     throw(NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
    2149             : {
    2150        4638 :     LibraryContainerMethodGuard aGuard( *this );
    2151        4638 :     Any aRetAny = maNameContainer.getByName( aName ) ;
    2152        4638 :     return aRetAny;
    2153             : }
    2154             : 
    2155        3961 : Sequence< OUString > SfxLibraryContainer::getElementNames()
    2156             :     throw(RuntimeException, std::exception)
    2157             : {
    2158        3961 :     LibraryContainerMethodGuard aGuard( *this );
    2159        3961 :     return maNameContainer.getElementNames();
    2160             : }
    2161             : 
    2162        8946 : sal_Bool SfxLibraryContainer::hasByName( const OUString& aName )
    2163             :     throw(RuntimeException, std::exception)
    2164             : {
    2165        8946 :     LibraryContainerMethodGuard aGuard( *this );
    2166        8946 :     return maNameContainer.hasByName( aName ) ;
    2167             : }
    2168             : 
    2169             : // Methods XLibraryContainer
    2170        2717 : Reference< XNameContainer > SAL_CALL SfxLibraryContainer::createLibrary( const OUString& Name )
    2171             :     throw(IllegalArgumentException, ElementExistException, RuntimeException, std::exception)
    2172             : {
    2173        2717 :     LibraryContainerMethodGuard aGuard( *this );
    2174        2717 :     SfxLibrary* pNewLib = implCreateLibrary( Name );
    2175        2717 :     pNewLib->maLibElementFileExtension = maLibElementFileExtension;
    2176             : 
    2177        2717 :     createVariableURL( pNewLib->maUnexpandedStorageURL, Name, maInfoFileName, true );
    2178             : 
    2179        5434 :     Reference< XNameAccess > xNameAccess = static_cast< XNameAccess* >( pNewLib );
    2180        5434 :     Any aElement;
    2181        2717 :     aElement <<= xNameAccess;
    2182        2717 :     maNameContainer.insertByName( Name, aElement );
    2183        2717 :     maModifiable.setModified( true );
    2184        2717 :     Reference< XNameContainer > xRet( xNameAccess, UNO_QUERY );
    2185        5434 :     return xRet;
    2186             : }
    2187             : 
    2188        1278 : Reference< XNameAccess > SAL_CALL SfxLibraryContainer::createLibraryLink
    2189             :     ( const OUString& Name, const OUString& StorageURL, sal_Bool ReadOnly )
    2190             :     throw(IllegalArgumentException, ElementExistException, RuntimeException, std::exception)
    2191             : {
    2192        1278 :     LibraryContainerMethodGuard aGuard( *this );
    2193             :     // TODO: Check other reasons to force ReadOnly status
    2194             :     //if( !ReadOnly )
    2195             :     //{
    2196             :     //}
    2197             : 
    2198        2556 :     OUString aLibInfoFileURL;
    2199        2556 :     OUString aLibDirURL;
    2200        2556 :     OUString aUnexpandedStorageURL;
    2201        1278 :     checkStorageURL( StorageURL, aLibInfoFileURL, aLibDirURL, aUnexpandedStorageURL );
    2202             : 
    2203             : 
    2204        1278 :     SfxLibrary* pNewLib = implCreateLibraryLink( Name, aLibInfoFileURL, aLibDirURL, ReadOnly );
    2205        1278 :     pNewLib->maLibElementFileExtension = maLibElementFileExtension;
    2206        1278 :     pNewLib->maUnexpandedStorageURL = aUnexpandedStorageURL;
    2207        1278 :     pNewLib->maOriginalStorageURL = StorageURL;
    2208             : 
    2209        2556 :     OUString aInitFileName;
    2210        2556 :     uno::Reference< embed::XStorage > xDummyStor;
    2211        2556 :     ::xmlscript::LibDescriptor aLibDesc;
    2212        1278 :     implLoadLibraryIndexFile( pNewLib, aLibDesc, xDummyStor, aInitFileName );
    2213        1278 :     implImportLibDescriptor( pNewLib, aLibDesc );
    2214             : 
    2215        1278 :     Reference< XNameAccess > xRet = static_cast< XNameAccess* >( pNewLib );
    2216        2556 :     Any aElement;
    2217        1278 :     aElement <<= xRet;
    2218        1278 :     maNameContainer.insertByName( Name, aElement );
    2219        1278 :     maModifiable.setModified( true );
    2220             : 
    2221        2556 :     OUString aUserSearchStr("vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE");
    2222        2556 :     OUString aSharedSearchStr("vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE");
    2223        2556 :     OUString aBundledSearchStr("vnd.sun.star.expand:$BUNDLED_EXTENSIONS");
    2224        1278 :     if( StorageURL.indexOf( aUserSearchStr ) != -1 )
    2225             :     {
    2226           0 :         pNewLib->mbExtension = true;
    2227             :     }
    2228        1278 :     else if( StorageURL.indexOf( aSharedSearchStr ) != -1 || StorageURL.indexOf( aBundledSearchStr ) != -1 )
    2229             :     {
    2230           0 :         pNewLib->mbExtension = true;
    2231           0 :         pNewLib->mbReadOnly = true;
    2232             :     }
    2233             : 
    2234        2556 :     return xRet;
    2235             : }
    2236             : 
    2237           0 : void SAL_CALL SfxLibraryContainer::removeLibrary( const OUString& Name )
    2238             :     throw(NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
    2239             : {
    2240           0 :     LibraryContainerMethodGuard aGuard( *this );
    2241             :     // Get and hold library before removing
    2242           0 :     Any aLibAny = maNameContainer.getByName( Name ) ;
    2243           0 :     Reference< XNameAccess > xNameAccess;
    2244           0 :     aLibAny >>= xNameAccess;
    2245           0 :     SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
    2246           0 :     if( pImplLib->mbReadOnly && !pImplLib->mbLink )
    2247             :     {
    2248           0 :         throw IllegalArgumentException();
    2249             :     }
    2250             :     // Remove from container
    2251           0 :     maNameContainer.removeByName( Name );
    2252           0 :     maModifiable.setModified( true );
    2253             : 
    2254             :     // Delete library files, but not for linked libraries
    2255           0 :     if( !pImplLib->mbLink )
    2256             :     {
    2257           0 :         if( mxStorage.is() )
    2258             :         {
    2259           0 :             return;
    2260             :         }
    2261           0 :         if( xNameAccess->hasElements() )
    2262             :         {
    2263           0 :             Sequence< OUString > aNames = pImplLib->getElementNames();
    2264           0 :             sal_Int32 nNameCount = aNames.getLength();
    2265           0 :             const OUString* pNames = aNames.getConstArray();
    2266           0 :             for( sal_Int32 i = 0 ; i < nNameCount ; ++i, ++pNames )
    2267             :             {
    2268           0 :                 pImplLib->removeElementWithoutChecks( *pNames, SfxLibrary::LibraryContainerAccess() );
    2269           0 :             }
    2270             :         }
    2271             : 
    2272             :         // Delete index file
    2273           0 :         createAppLibraryFolder( pImplLib, Name );
    2274           0 :         OUString aLibInfoPath = pImplLib->maLibInfoFileURL;
    2275             :         try
    2276             :         {
    2277           0 :             if( mxSFI->exists( aLibInfoPath ) )
    2278             :             {
    2279           0 :                 mxSFI->kill( aLibInfoPath );
    2280             :             }
    2281             :         }
    2282           0 :         catch(const Exception& ) {}
    2283             : 
    2284             :         // Delete folder if empty
    2285           0 :         INetURLObject aInetObj( maLibraryPath.getToken(1, (sal_Unicode)';') );
    2286             :         aInetObj.insertName( Name, true, INetURLObject::LAST_SEGMENT,
    2287           0 :                              true, INetURLObject::ENCODE_ALL );
    2288           0 :         OUString aLibDirPath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
    2289             : 
    2290             :         try
    2291             :         {
    2292           0 :             if( mxSFI->isFolder( aLibDirPath ) )
    2293             :             {
    2294           0 :                 Sequence< OUString > aContentSeq = mxSFI->getFolderContents( aLibDirPath, true );
    2295           0 :                 sal_Int32 nCount = aContentSeq.getLength();
    2296           0 :                 if( !nCount )
    2297             :                 {
    2298           0 :                     mxSFI->kill( aLibDirPath );
    2299           0 :                 }
    2300             :             }
    2301             :         }
    2302           0 :         catch(const Exception& )
    2303             :         {
    2304           0 :         }
    2305           0 :     }
    2306             : }
    2307             : 
    2308        5711 : sal_Bool SAL_CALL SfxLibraryContainer::isLibraryLoaded( const OUString& Name )
    2309             :     throw(NoSuchElementException, RuntimeException, std::exception)
    2310             : {
    2311        5711 :     LibraryContainerMethodGuard aGuard( *this );
    2312        5711 :     SfxLibrary* pImplLib = getImplLib( Name );
    2313        5711 :     bool bRet = pImplLib->mbLoaded;
    2314        5711 :     return bRet;
    2315             : }
    2316             : 
    2317             : 
    2318         639 : void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
    2319             :     throw(NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
    2320             : {
    2321         639 :     LibraryContainerMethodGuard aGuard( *this );
    2322        1278 :     Any aLibAny = maNameContainer.getByName( Name ) ;
    2323        1278 :     Reference< XNameAccess > xNameAccess;
    2324         639 :     aLibAny >>= xNameAccess;
    2325         639 :     SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
    2326             : 
    2327         639 :     bool bLoaded = pImplLib->mbLoaded;
    2328         639 :     pImplLib->mbLoaded = true;
    2329         639 :     if( !bLoaded && xNameAccess->hasElements() )
    2330             :     {
    2331          33 :         if( pImplLib->mbPasswordProtected )
    2332             :         {
    2333           0 :             implLoadPasswordLibrary( pImplLib, Name );
    2334         639 :             return;
    2335             :         }
    2336             : 
    2337          33 :         bool bLink = pImplLib->mbLink;
    2338          33 :         bool bStorage = mxStorage.is() && !bLink;
    2339             : 
    2340          33 :         uno::Reference< embed::XStorage > xLibrariesStor;
    2341          66 :         uno::Reference< embed::XStorage > xLibraryStor;
    2342          33 :         if( bStorage )
    2343             :         {
    2344             :             try
    2345             :             {
    2346           5 :                 xLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READ );
    2347             :                 SAL_WARN_IF(
    2348             :                     !xLibrariesStor.is(), "basic",
    2349             :                     ("The method must either throw exception or return a"
    2350             :                      " storage!"));
    2351           5 :                 if ( !xLibrariesStor.is() )
    2352             :                 {
    2353           0 :                     throw uno::RuntimeException();
    2354             :                 }
    2355             : 
    2356           5 :                 xLibraryStor = xLibrariesStor->openStorageElement( Name, embed::ElementModes::READ );
    2357             :                 SAL_WARN_IF(
    2358             :                     !xLibraryStor.is(), "basic",
    2359             :                     ("The method must either throw exception or return a"
    2360             :                      " storage!"));
    2361           5 :                 if ( !xLibrariesStor.is() )
    2362             :                 {
    2363           0 :                     throw uno::RuntimeException();
    2364             :                 }
    2365             :             }
    2366           0 :             catch(const uno::Exception& )
    2367             :             {
    2368             :             #if OSL_DEBUG_LEVEL > 0
    2369             :                 Any aError( ::cppu::getCaughtException() );
    2370             :                 SAL_WARN(
    2371             :                     "basic",
    2372             :                     "couldn't open sub storage for library \"" << Name
    2373             :                         << "\". Exception: "
    2374             :                         << comphelper::anyToString(aError));
    2375             :             #endif
    2376           0 :                 throw;
    2377             :             }
    2378             :         }
    2379             : 
    2380          66 :         Sequence< OUString > aNames = pImplLib->getElementNames();
    2381          33 :         sal_Int32 nNameCount = aNames.getLength();
    2382          33 :         const OUString* pNames = aNames.getConstArray();
    2383          70 :         for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
    2384             :         {
    2385          37 :             OUString aElementName = pNames[ i ];
    2386             : 
    2387          74 :             OUString aFile;
    2388          74 :             uno::Reference< io::XInputStream > xInStream;
    2389             : 
    2390          37 :             if( bStorage )
    2391             :             {
    2392           9 :                 uno::Reference< io::XStream > xElementStream;
    2393             : 
    2394           9 :                 aFile = aElementName;
    2395           9 :                 aFile += ".xml";
    2396             : 
    2397             :                 try
    2398             :                 {
    2399           9 :                     xElementStream = xLibraryStor->openStreamElement( aFile, embed::ElementModes::READ );
    2400             :                 }
    2401           0 :                 catch(const uno::Exception& )
    2402             :                 {}
    2403             : 
    2404           9 :                 if( !xElementStream.is() )
    2405             :                 {
    2406             :                     // Check for EA2 document version with wrong extensions
    2407           0 :                     aFile = aElementName;
    2408           0 :                     aFile += ".";
    2409           0 :                     aFile += maLibElementFileExtension;
    2410           0 :                     xElementStream = xLibraryStor->openStreamElement( aFile, embed::ElementModes::READ );
    2411             :                 }
    2412             : 
    2413           9 :                 if ( xElementStream.is() )
    2414             :                 {
    2415           9 :                     xInStream = xElementStream->getInputStream();
    2416             :                 }
    2417           9 :                 if ( !xInStream.is() )
    2418             :                 {
    2419             :                     SAL_WARN(
    2420             :                         "basic",
    2421             :                         "couldn't open library element stream - attempted to"
    2422             :                             " open library \"" << Name << '"');
    2423           0 :                     throw RuntimeException("couln't open library element stream", *this);
    2424           9 :                 }
    2425             :             }
    2426             :             else
    2427             :             {
    2428          28 :                 OUString aLibDirPath = pImplLib->maStorageURL;
    2429          56 :                 INetURLObject aElementInetObj( aLibDirPath );
    2430             :                 aElementInetObj.insertName( aElementName, false,
    2431             :                                             INetURLObject::LAST_SEGMENT, true,
    2432          28 :                                             INetURLObject::ENCODE_ALL );
    2433          28 :                 aElementInetObj.setExtension( maLibElementFileExtension );
    2434          56 :                 aFile = aElementInetObj.GetMainURL( INetURLObject::NO_DECODE );
    2435             :             }
    2436             : 
    2437          74 :             Reference< XNameContainer > xLib( pImplLib );
    2438             :             Any aAny = importLibraryElement( xLib, aElementName,
    2439          74 :                                              aFile, xInStream );
    2440          37 :             if( pImplLib->hasByName( aElementName ) )
    2441             :             {
    2442          37 :                 if( aAny.hasValue() )
    2443             :                 {
    2444          37 :                     pImplLib->maNameContainer.replaceByName( aElementName, aAny );
    2445             :                 }
    2446             :             }
    2447             :             else
    2448             :             {
    2449           0 :                 pImplLib->maNameContainer.insertByName( aElementName, aAny );
    2450             :             }
    2451          37 :         }
    2452          66 :         pImplLib->implSetModified( false );
    2453         639 :     }
    2454             : }
    2455             : 
    2456             : // Methods XLibraryContainer2
    2457           0 : sal_Bool SAL_CALL SfxLibraryContainer::isLibraryLink( const OUString& Name )
    2458             :     throw (NoSuchElementException, RuntimeException, std::exception)
    2459             : {
    2460           0 :     LibraryContainerMethodGuard aGuard( *this );
    2461           0 :     SfxLibrary* pImplLib = getImplLib( Name );
    2462           0 :     bool bRet = pImplLib->mbLink;
    2463           0 :     return bRet;
    2464             : }
    2465             : 
    2466           0 : OUString SAL_CALL SfxLibraryContainer::getLibraryLinkURL( const OUString& Name )
    2467             :     throw (IllegalArgumentException, NoSuchElementException, RuntimeException, std::exception)
    2468             : {
    2469           0 :     LibraryContainerMethodGuard aGuard( *this );
    2470           0 :     SfxLibrary* pImplLib = getImplLib( Name );
    2471           0 :     bool bLink = pImplLib->mbLink;
    2472           0 :     if( !bLink )
    2473             :     {
    2474           0 :         throw IllegalArgumentException();
    2475             :     }
    2476           0 :     OUString aRetStr = pImplLib->maLibInfoFileURL;
    2477           0 :     return aRetStr;
    2478             : }
    2479             : 
    2480           0 : sal_Bool SAL_CALL SfxLibraryContainer::isLibraryReadOnly( const OUString& Name )
    2481             :     throw (NoSuchElementException, RuntimeException, std::exception)
    2482             : {
    2483           0 :     LibraryContainerMethodGuard aGuard( *this );
    2484           0 :     SfxLibrary* pImplLib = getImplLib( Name );
    2485           0 :     bool bRet = pImplLib->mbReadOnly || (pImplLib->mbLink && pImplLib->mbReadOnlyLink);
    2486           0 :     return bRet;
    2487             : }
    2488             : 
    2489           0 : void SAL_CALL SfxLibraryContainer::setLibraryReadOnly( const OUString& Name, sal_Bool bReadOnly )
    2490             :     throw (NoSuchElementException, RuntimeException, std::exception)
    2491             : {
    2492           0 :     LibraryContainerMethodGuard aGuard( *this );
    2493           0 :     SfxLibrary* pImplLib = getImplLib( Name );
    2494           0 :     if( pImplLib->mbLink )
    2495             :     {
    2496           0 :         if( (pImplLib->mbReadOnlyLink ? 1 : 0) != bReadOnly )
    2497             :         {
    2498           0 :             pImplLib->mbReadOnlyLink = bReadOnly;
    2499           0 :             pImplLib->implSetModified( true );
    2500           0 :             maModifiable.setModified( true );
    2501             :         }
    2502             :     }
    2503             :     else
    2504             :     {
    2505           0 :         if( (pImplLib->mbReadOnly ? 1 : 0) != bReadOnly )
    2506             :         {
    2507           0 :             pImplLib->mbReadOnly = bReadOnly;
    2508           0 :             pImplLib->implSetModified( true );
    2509             :         }
    2510           0 :     }
    2511           0 : }
    2512             : 
    2513           0 : void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OUString& NewName )
    2514             :     throw (NoSuchElementException, ElementExistException, RuntimeException, std::exception)
    2515             : {
    2516           0 :     LibraryContainerMethodGuard aGuard( *this );
    2517           0 :     if( maNameContainer.hasByName( NewName ) )
    2518             :     {
    2519           0 :         throw ElementExistException();
    2520             :     }
    2521             :     // Get and hold library before removing
    2522           0 :     Any aLibAny = maNameContainer.getByName( Name ) ;
    2523             : 
    2524             :     // #i24094 Maybe lib is not loaded!
    2525           0 :     Reference< XNameAccess > xNameAccess;
    2526           0 :     aLibAny >>= xNameAccess;
    2527           0 :     SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
    2528           0 :     if( pImplLib->mbPasswordProtected && !pImplLib->mbPasswordVerified )
    2529             :     {
    2530           0 :         return;     // Lib with unverified password cannot be renamed
    2531             :     }
    2532           0 :     loadLibrary( Name );
    2533             : 
    2534             :     // Remove from container
    2535           0 :     maNameContainer.removeByName( Name );
    2536           0 :     maModifiable.setModified( true );
    2537             : 
    2538             :     // Rename library folder, but not for linked libraries
    2539           0 :     bool bMovedSuccessful = true;
    2540             : 
    2541             :     // Rename files
    2542           0 :     bool bStorage = mxStorage.is();
    2543           0 :     if( !bStorage && !pImplLib->mbLink )
    2544             :     {
    2545           0 :         bMovedSuccessful = false;
    2546             : 
    2547           0 :         OUString aLibDirPath = pImplLib->maStorageURL;
    2548             : 
    2549           0 :         INetURLObject aDestInetObj( maLibraryPath.getToken(1, (sal_Unicode)';'));
    2550             :         aDestInetObj.insertName( NewName, true, INetURLObject::LAST_SEGMENT,
    2551           0 :                                  true, INetURLObject::ENCODE_ALL );
    2552           0 :         OUString aDestDirPath = aDestInetObj.GetMainURL( INetURLObject::NO_DECODE );
    2553             : 
    2554             :         // Store new URL
    2555           0 :         OUString aLibInfoFileURL = pImplLib->maLibInfoFileURL;
    2556             :         checkStorageURL( aDestDirPath, pImplLib->maLibInfoFileURL, pImplLib->maStorageURL,
    2557           0 :                          pImplLib->maUnexpandedStorageURL );
    2558             : 
    2559             :         try
    2560             :         {
    2561           0 :             if( mxSFI->isFolder( aLibDirPath ) )
    2562             :             {
    2563           0 :                 if( !mxSFI->isFolder( aDestDirPath ) )
    2564             :                 {
    2565           0 :                     mxSFI->createFolder( aDestDirPath );
    2566             :                 }
    2567             :                 // Move index file
    2568             :                 try
    2569             :                 {
    2570           0 :                     if( mxSFI->exists( pImplLib->maLibInfoFileURL ) )
    2571             :                     {
    2572           0 :                         mxSFI->kill( pImplLib->maLibInfoFileURL );
    2573             :                     }
    2574           0 :                     mxSFI->move( aLibInfoFileURL, pImplLib->maLibInfoFileURL );
    2575             :                 }
    2576           0 :                 catch(const Exception& )
    2577             :                 {
    2578             :                 }
    2579             : 
    2580           0 :                 Sequence< OUString > aElementNames = xNameAccess->getElementNames();
    2581           0 :                 sal_Int32 nNameCount = aElementNames.getLength();
    2582           0 :                 const OUString* pNames = aElementNames.getConstArray();
    2583           0 :                 for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
    2584             :                 {
    2585           0 :                     OUString aElementName = pNames[ i ];
    2586             : 
    2587           0 :                     INetURLObject aElementInetObj( aLibDirPath );
    2588             :                     aElementInetObj.insertName( aElementName, false,
    2589           0 :                         INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL );
    2590           0 :                     aElementInetObj.setExtension( maLibElementFileExtension );
    2591           0 :                     OUString aElementPath( aElementInetObj.GetMainURL( INetURLObject::NO_DECODE ) );
    2592             : 
    2593           0 :                     INetURLObject aElementDestInetObj( aDestDirPath );
    2594             :                     aElementDestInetObj.insertName( aElementName, false,
    2595             :                                                     INetURLObject::LAST_SEGMENT, true,
    2596           0 :                                                     INetURLObject::ENCODE_ALL );
    2597           0 :                     aElementDestInetObj.setExtension( maLibElementFileExtension );
    2598           0 :                     OUString aDestElementPath( aElementDestInetObj.GetMainURL( INetURLObject::NO_DECODE ) );
    2599             : 
    2600             :                     try
    2601             :                     {
    2602           0 :                         if( mxSFI->exists( aDestElementPath ) )
    2603             :                         {
    2604           0 :                             mxSFI->kill( aDestElementPath );
    2605             :                         }
    2606           0 :                         mxSFI->move( aElementPath, aDestElementPath );
    2607             :                     }
    2608           0 :                     catch(const Exception& )
    2609             :                     {
    2610             :                     }
    2611           0 :                 }
    2612           0 :                 pImplLib->storeResourcesAsURL( aDestDirPath, NewName );
    2613             : 
    2614             :                 // Delete folder if empty
    2615           0 :                 Sequence< OUString > aContentSeq = mxSFI->getFolderContents( aLibDirPath, true );
    2616           0 :                 sal_Int32 nCount = aContentSeq.getLength();
    2617           0 :                 if( !nCount )
    2618             :                 {
    2619           0 :                     mxSFI->kill( aLibDirPath );
    2620             :                 }
    2621             : 
    2622           0 :                 bMovedSuccessful = true;
    2623           0 :                 pImplLib->implSetModified( true );
    2624             :             }
    2625             :         }
    2626           0 :         catch(const Exception& )
    2627             :         {
    2628             :             // Restore old library
    2629           0 :             maNameContainer.insertByName( Name, aLibAny ) ;
    2630           0 :         }
    2631             :     }
    2632             : 
    2633           0 :     if( bStorage && !pImplLib->mbLink )
    2634             :     {
    2635           0 :         pImplLib->implSetModified( true );
    2636             :     }
    2637           0 :     if( bMovedSuccessful )
    2638             :     {
    2639           0 :            maNameContainer.insertByName( NewName, aLibAny ) ;
    2640           0 :     }
    2641             : }
    2642             : 
    2643             : 
    2644             : // Methods XInitialization
    2645        3836 : void SAL_CALL SfxLibraryContainer::initialize( const Sequence< Any >& _rArguments )
    2646             :     throw (Exception, RuntimeException, std::exception)
    2647             : {
    2648        3836 :     LibraryContainerMethodGuard aGuard( *this );
    2649        3836 :     sal_Int32 nArgCount = _rArguments.getLength();
    2650        3836 :     if ( nArgCount == 1 )
    2651             :     {
    2652        3836 :         OUString sInitialDocumentURL;
    2653        3908 :         Reference< XStorageBasedDocument > xDocument;
    2654        3836 :         if ( _rArguments[0] >>= sInitialDocumentURL )
    2655             :         {
    2656           0 :             initializeFromDocumentURL( sInitialDocumentURL );
    2657           0 :             return;
    2658             :         }
    2659             : 
    2660        3836 :         if ( _rArguments[0] >>= xDocument )
    2661             :         {
    2662        3836 :             initializeFromDocument( xDocument );
    2663        3764 :             return;
    2664          72 :         }
    2665             :     }
    2666             : 
    2667        3764 :     throw IllegalArgumentException();
    2668             : }
    2669             : 
    2670           0 : void SAL_CALL SfxLibraryContainer::initializeFromDocumentURL( const OUString& _rInitialDocumentURL )
    2671             : {
    2672           0 :     init( _rInitialDocumentURL, NULL );
    2673           0 : }
    2674             : 
    2675        3836 : void SAL_CALL SfxLibraryContainer::initializeFromDocument( const Reference< XStorageBasedDocument >& _rxDocument )
    2676             : {
    2677             :     // check whether this is a valid OfficeDocument, and obtain the document's root storage
    2678        3836 :     Reference< XStorage > xDocStorage;
    2679             :     try
    2680             :     {
    2681        3836 :         Reference< XServiceInfo > xSI( _rxDocument, UNO_QUERY_THROW );
    2682        3836 :         if ( xSI->supportsService("com.sun.star.document.OfficeDocument"))
    2683             :         {
    2684        3908 :             xDocStorage.set( _rxDocument->getDocumentStorage(), UNO_QUERY_THROW );
    2685             :         }
    2686        7528 :         Reference< XModel > xDocument( _rxDocument, UNO_QUERY_THROW );
    2687        7528 :         Reference< XComponent > xDocComponent( _rxDocument, UNO_QUERY_THROW );
    2688             : 
    2689        3764 :         mxOwnerDocument = xDocument;
    2690        7600 :         startComponentListening( xDocComponent );
    2691             :     }
    2692          72 :     catch( const Exception& ) { }
    2693             : 
    2694        3836 :     if ( !xDocStorage.is() )
    2695             :     {
    2696          72 :         throw IllegalArgumentException();
    2697             :     }
    2698        3764 :     init( OUString(), xDocStorage );
    2699        3764 : }
    2700             : 
    2701             : // OEventListenerAdapter
    2702        3736 : void SfxLibraryContainer::_disposing( const EventObject& _rSource )
    2703             : {
    2704             : #if OSL_DEBUG_LEVEL > 0
    2705             :     Reference< XModel > xDocument( mxOwnerDocument.get(), UNO_QUERY );
    2706             :     SAL_WARN_IF(
    2707             :         xDocument != _rSource.Source || !xDocument.is(), "basic",
    2708             :         "SfxLibraryContainer::_disposing: where does this come from?");
    2709             : #else
    2710             :     (void)_rSource;
    2711             : #endif
    2712        3736 :     dispose();
    2713        3736 : }
    2714             : 
    2715             : // OComponentHelper
    2716        3870 : void SAL_CALL SfxLibraryContainer::disposing()
    2717             : {
    2718        3870 :     Reference< XModel > xModel = mxOwnerDocument;
    2719        7740 :     EventObject aEvent( xModel.get() );
    2720        3870 :     maVBAScriptListeners.disposing( aEvent );
    2721        3870 :     stopAllComponentListening();
    2722        7740 :     mxOwnerDocument = WeakReference< XModel >();
    2723        3870 : }
    2724             : 
    2725             : // Methods XLibraryContainerPassword
    2726           0 : sal_Bool SAL_CALL SfxLibraryContainer::isLibraryPasswordProtected( const OUString& )
    2727             :     throw (NoSuchElementException, RuntimeException, std::exception)
    2728             : {
    2729           0 :     LibraryContainerMethodGuard aGuard( *this );
    2730           0 :     return sal_False;
    2731             : }
    2732             : 
    2733           0 : sal_Bool SAL_CALL SfxLibraryContainer::isLibraryPasswordVerified( const OUString& )
    2734             :     throw (IllegalArgumentException, NoSuchElementException, RuntimeException, std::exception)
    2735             : {
    2736           0 :     LibraryContainerMethodGuard aGuard( *this );
    2737           0 :     throw IllegalArgumentException();
    2738             : }
    2739             : 
    2740           0 : sal_Bool SAL_CALL SfxLibraryContainer::verifyLibraryPassword( const OUString&, const OUString& )
    2741             :     throw (IllegalArgumentException, NoSuchElementException, RuntimeException, std::exception)
    2742             : {
    2743           0 :     LibraryContainerMethodGuard aGuard( *this );
    2744           0 :     throw IllegalArgumentException();
    2745             : }
    2746             : 
    2747           0 : void SAL_CALL SfxLibraryContainer::changeLibraryPassword(const OUString&, const OUString&, const OUString& )
    2748             :     throw (IllegalArgumentException, NoSuchElementException, RuntimeException, std::exception)
    2749             : {
    2750           0 :     LibraryContainerMethodGuard aGuard( *this );
    2751           0 :     throw IllegalArgumentException();
    2752             : }
    2753             : 
    2754             : // Methods XContainer
    2755        1386 : void SAL_CALL SfxLibraryContainer::addContainerListener( const Reference< XContainerListener >& xListener )
    2756             :     throw (RuntimeException, std::exception)
    2757             : {
    2758        1386 :     LibraryContainerMethodGuard aGuard( *this );
    2759        1386 :     maNameContainer.setEventSource( static_cast< XInterface* >( (OWeakObject*)this ) );
    2760        1386 :     maNameContainer.addContainerListener( xListener );
    2761        1386 : }
    2762             : 
    2763           0 : void SAL_CALL SfxLibraryContainer::removeContainerListener( const Reference< XContainerListener >& xListener )
    2764             :     throw (RuntimeException, std::exception)
    2765             : {
    2766           0 :     LibraryContainerMethodGuard aGuard( *this );
    2767           0 :     maNameContainer.removeContainerListener( xListener );
    2768           0 : }
    2769             : 
    2770             : // Methods XLibraryContainerExport
    2771           0 : void SAL_CALL SfxLibraryContainer::exportLibrary( const OUString& Name, const OUString& URL,
    2772             :     const Reference< XInteractionHandler >& Handler )
    2773             :     throw ( uno::Exception, NoSuchElementException, RuntimeException, std::exception)
    2774             : {
    2775           0 :     LibraryContainerMethodGuard aGuard( *this );
    2776           0 :     SfxLibrary* pImplLib = getImplLib( Name );
    2777             : 
    2778           0 :     Reference< XSimpleFileAccess3 > xToUseSFI;
    2779           0 :     if( Handler.is() )
    2780             :     {
    2781           0 :         xToUseSFI = ucb::SimpleFileAccess::create( mxContext );
    2782           0 :         xToUseSFI->setInteractionHandler( Handler );
    2783             :     }
    2784             : 
    2785             :     // Maybe lib is not loaded?!
    2786           0 :     loadLibrary( Name );
    2787             : 
    2788           0 :     uno::Reference< ::com::sun::star::embed::XStorage > xDummyStor;
    2789           0 :     if( pImplLib->mbPasswordProtected )
    2790             :     {
    2791           0 :         implStorePasswordLibrary( pImplLib, Name, xDummyStor, URL, xToUseSFI, Handler );
    2792             :     }
    2793             :     else
    2794             :     {
    2795           0 :         implStoreLibrary( pImplLib, Name, xDummyStor, URL, xToUseSFI, Handler );
    2796             :     }
    2797           0 :     ::xmlscript::LibDescriptor aLibDesc;
    2798           0 :     aLibDesc.aName = Name;
    2799           0 :     aLibDesc.bLink = false;             // Link status gets lost?
    2800           0 :     aLibDesc.bReadOnly = pImplLib->mbReadOnly;
    2801           0 :     aLibDesc.bPreload = false;          // Preload status gets lost?
    2802           0 :     aLibDesc.bPasswordProtected = pImplLib->mbPasswordProtected;
    2803           0 :     aLibDesc.aElementNames = pImplLib->getElementNames();
    2804             : 
    2805           0 :     implStoreLibraryIndexFile( pImplLib, aLibDesc, xDummyStor, URL, xToUseSFI );
    2806           0 : }
    2807             : 
    2808        1334 : OUString SfxLibraryContainer::expand_url( const OUString& url )
    2809             :     throw(::com::sun::star::uno::RuntimeException)
    2810             : {
    2811        1334 :     if (url.startsWith( EXPAND_PROTOCOL ":" ))
    2812             :     {
    2813           0 :         if( !mxMacroExpander.is() )
    2814             :         {
    2815           0 :             Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(mxContext);
    2816           0 :             MutexGuard guard( Mutex::getGlobalMutex() );
    2817           0 :             if( !mxMacroExpander.is() )
    2818             :             {
    2819           0 :                 mxMacroExpander = xExpander;
    2820           0 :             }
    2821             :         }
    2822             : 
    2823           0 :         if( !mxMacroExpander.is() )
    2824             :         {
    2825           0 :             return url;
    2826             :         }
    2827             :         // cut protocol
    2828           0 :         OUString macro( url.copy( sizeof (EXPAND_PROTOCOL ":") -1 ) );
    2829             :         // decode uric class chars
    2830           0 :         macro = Uri::decode( macro, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
    2831             :         // expand macro string
    2832           0 :         OUString ret( mxMacroExpander->expandMacros( macro ) );
    2833           0 :         return ret;
    2834             :     }
    2835        1334 :     else if( mxStringSubstitution.is() )
    2836             :     {
    2837        1334 :         OUString ret( mxStringSubstitution->substituteVariables( url, false ) );
    2838        1334 :         return ret;
    2839             :     }
    2840             :     else
    2841             :     {
    2842           0 :         return url;
    2843             :     }
    2844             : }
    2845             : 
    2846             : //XLibraryContainer3
    2847           0 : OUString SAL_CALL SfxLibraryContainer::getOriginalLibraryLinkURL( const OUString& Name )
    2848             :     throw (IllegalArgumentException, NoSuchElementException, RuntimeException, std::exception)
    2849             : {
    2850           0 :     LibraryContainerMethodGuard aGuard( *this );
    2851           0 :     SfxLibrary* pImplLib = getImplLib( Name );
    2852           0 :     bool bLink = pImplLib->mbLink;
    2853           0 :     if( !bLink )
    2854             :     {
    2855           0 :         throw IllegalArgumentException();
    2856             :     }
    2857           0 :     OUString aRetStr = pImplLib->maOriginalStorageURL;
    2858           0 :     return aRetStr;
    2859             : }
    2860             : 
    2861             : 
    2862             : // XVBACompatibility
    2863        1480 : sal_Bool SAL_CALL SfxLibraryContainer::getVBACompatibilityMode() throw (RuntimeException, std::exception)
    2864             : {
    2865        1480 :     return mbVBACompat;
    2866             : }
    2867             : 
    2868          29 : void SAL_CALL SfxLibraryContainer::setVBACompatibilityMode( sal_Bool _vbacompatmodeon ) throw (RuntimeException, std::exception)
    2869             : {
    2870             :     /*  The member variable mbVBACompat must be set first, the following call
    2871             :         to getBasicManager() may call getVBACompatibilityMode() which returns
    2872             :         this value. */
    2873          29 :     mbVBACompat = _vbacompatmodeon;
    2874          29 :     if( BasicManager* pBasMgr = getBasicManager() )
    2875             :     {
    2876             :         // get the standard library
    2877          29 :         OUString aLibName = pBasMgr->GetName();
    2878          29 :         if ( aLibName.isEmpty())
    2879             :         {
    2880          28 :             aLibName = "Standard";
    2881             :         }
    2882          29 :         if( StarBASIC* pBasic = pBasMgr->GetLib( aLibName ) )
    2883             :         {
    2884          29 :             pBasic->SetVBAEnabled( _vbacompatmodeon );
    2885             :         }
    2886             :         /*  If in VBA compatibility mode, force creation of the VBA Globals
    2887             :             object. Each application will create an instance of its own
    2888             :             implementation and store it in its Basic manager. Implementations
    2889             :             will do all necessary additional initialization, such as
    2890             :             registering the global "This***Doc" UNO constant, starting the
    2891             :             document events processor etc.
    2892             :          */
    2893          29 :         if( mbVBACompat ) try
    2894             :         {
    2895          29 :             Reference< XModel > xModel( mxOwnerDocument );   // weak-ref -> ref
    2896          58 :             Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW );
    2897          61 :             xFactory->createInstance("ooo.vba.VBAGlobals");
    2898             :         }
    2899           3 :         catch(const Exception& )
    2900             :         {
    2901          29 :         }
    2902             :     }
    2903          29 : }
    2904             : 
    2905          28 : void SAL_CALL SfxLibraryContainer::setProjectName( const OUString& _projectname ) throw (RuntimeException, std::exception)
    2906             : {
    2907          28 :     msProjectName = _projectname;
    2908          28 :     BasicManager* pBasMgr = getBasicManager();
    2909             :     // Temporary HACK
    2910             :     // Some parts of the VBA handling ( e.g. in core basic )
    2911             :     // code expect the name of the VBA project to be set as the name of
    2912             :     // the basic manager. Provide fail back here.
    2913          28 :     if( pBasMgr )
    2914             :     {
    2915          28 :         pBasMgr->SetName( msProjectName );
    2916             :     }
    2917          28 : }
    2918             : 
    2919           0 : sal_Int32 SAL_CALL SfxLibraryContainer::getRunningVBAScripts() throw (RuntimeException, std::exception)
    2920             : {
    2921           0 :     LibraryContainerMethodGuard aGuard( *this );
    2922           0 :     return mnRunningVBAScripts;
    2923             : }
    2924             : 
    2925           0 : void SAL_CALL SfxLibraryContainer::addVBAScriptListener( const Reference< vba::XVBAScriptListener >& rxListener ) throw (RuntimeException, std::exception)
    2926             : {
    2927           0 :     maVBAScriptListeners.addTypedListener( rxListener );
    2928           0 : }
    2929             : 
    2930           0 : void SAL_CALL SfxLibraryContainer::removeVBAScriptListener( const Reference< vba::XVBAScriptListener >& rxListener ) throw (RuntimeException, std::exception)
    2931             : {
    2932           0 :     maVBAScriptListeners.removeTypedListener( rxListener );
    2933           0 : }
    2934             : 
    2935          52 : void SAL_CALL SfxLibraryContainer::broadcastVBAScriptEvent( sal_Int32 nIdentifier, const OUString& rModuleName ) throw (RuntimeException, std::exception)
    2936             : {
    2937             :     // own lock for accessing the number of running scripts
    2938          52 :     enterMethod();
    2939          52 :     switch( nIdentifier )
    2940             :     {
    2941             :     case vba::VBAScriptEventId::SCRIPT_STARTED:
    2942          25 :         ++mnRunningVBAScripts;
    2943          25 :         break;
    2944             :     case vba::VBAScriptEventId::SCRIPT_STOPPED:
    2945          25 :         --mnRunningVBAScripts;
    2946          25 :         break;
    2947             :     }
    2948          52 :     leaveMethod();
    2949             : 
    2950          52 :     Reference< XModel > xModel = mxOwnerDocument;  // weak-ref -> ref
    2951         104 :     vba::VBAScriptEvent aEvent( xModel, nIdentifier, rModuleName );
    2952         104 :     maVBAScriptListeners.notify( aEvent );
    2953          52 : }
    2954             : 
    2955             : // Methods XServiceInfo
    2956           0 : sal_Bool SAL_CALL SfxLibraryContainer::supportsService( const OUString& _rServiceName )
    2957             :     throw (RuntimeException, std::exception)
    2958             : {
    2959           0 :     return cppu::supportsService(this, _rServiceName);
    2960             : }
    2961             : 
    2962             : // Implementation class SfxLibrary
    2963             : 
    2964             : // Ctor
    2965        2717 : SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
    2966             :     const Reference< XComponentContext >& xContext, const Reference< XSimpleFileAccess3 >& xSFI )
    2967             :         : OComponentHelper( m_aMutex )
    2968             :         , mxContext( xContext )
    2969             :         , mxSFI( xSFI )
    2970             :         , mrModifiable( _rModifiable )
    2971             :         , maNameContainer( aType )
    2972             :         , mbLoaded( true )
    2973             :         , mbIsModified( true )
    2974             :         , mbInitialised( false )
    2975             :         , mbLink( false )
    2976             :         , mbReadOnly( false )
    2977             :         , mbReadOnlyLink( false )
    2978             :         , mbPreload( false )
    2979             :         , mbPasswordProtected( false )
    2980             :         , mbPasswordVerified( false )
    2981             :         , mbDoc50Password( false )
    2982             :         , mbSharedIndexFile( false )
    2983        2717 :         , mbExtension( false )
    2984             : {
    2985        2717 : }
    2986             : 
    2987        1278 : SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
    2988             :     const Reference< XComponentContext >& xContext, const Reference< XSimpleFileAccess3 >& xSFI,
    2989             :     const OUString& aLibInfoFileURL, const OUString& aStorageURL, bool ReadOnly )
    2990             :         : OComponentHelper( m_aMutex )
    2991             :         , mxContext( xContext )
    2992             :         , mxSFI( xSFI )
    2993             :         , mrModifiable( _rModifiable )
    2994             :         , maNameContainer( aType )
    2995             :         , mbLoaded( false )
    2996             :         , mbIsModified( true )
    2997             :         , mbInitialised( false )
    2998             :         , maLibInfoFileURL( aLibInfoFileURL )
    2999             :         , maStorageURL( aStorageURL )
    3000             :         , mbLink( true )
    3001             :         , mbReadOnly( false )
    3002             :         , mbReadOnlyLink( ReadOnly )
    3003             :         , mbPreload( false )
    3004             :         , mbPasswordProtected( false )
    3005             :         , mbPasswordVerified( false )
    3006             :         , mbDoc50Password( false )
    3007             :         , mbSharedIndexFile( false )
    3008        1278 :         , mbExtension( false )
    3009             : {
    3010        1278 : }
    3011             : 
    3012        1524 : void SfxLibrary::implSetModified( bool _bIsModified )
    3013             : {
    3014        1524 :     if ( mbIsModified == _bIsModified )
    3015             :     {
    3016        1708 :         return;
    3017             :     }
    3018        1340 :     mbIsModified = _bIsModified;
    3019        1340 :     if ( mbIsModified )
    3020             :     {
    3021           0 :         mrModifiable.setModified( true );
    3022             :     }
    3023             : }
    3024             : 
    3025             : // Methods XInterface
    3026        7677 : Any SAL_CALL SfxLibrary::queryInterface( const Type& rType )
    3027             :     throw( RuntimeException, std::exception )
    3028             : {
    3029        7677 :     Any aRet;
    3030             : 
    3031       15354 :     aRet = Any(
    3032             :         ::cppu::queryInterface(
    3033             :             rType,
    3034             :             static_cast< XContainer * >( this ),
    3035             :             static_cast< XNameContainer * >( this ),
    3036             :             static_cast< XNameAccess * >( this ),
    3037             :             static_cast< XElementAccess * >( this ),
    3038        7677 :             static_cast< XChangesNotifier * >( this ) ) );
    3039        7677 :     if( !aRet.hasValue() )
    3040             :     {
    3041         975 :         aRet = OComponentHelper::queryInterface( rType );
    3042             :     }
    3043        7677 :     return aRet;
    3044             : }
    3045             : 
    3046             : // Methods XElementAccess
    3047           0 : Type SfxLibrary::getElementType()
    3048             :     throw(RuntimeException, std::exception)
    3049             : {
    3050           0 :     return maNameContainer.getElementType();
    3051             : }
    3052             : 
    3053        3257 : sal_Bool SfxLibrary::hasElements()
    3054             :     throw(RuntimeException, std::exception)
    3055             : {
    3056        3257 :     bool bRet = maNameContainer.hasElements();
    3057        3257 :     return bRet;
    3058             : }
    3059             : 
    3060             : // Methods XNameAccess
    3061          43 : Any SfxLibrary::getByName( const OUString& aName )
    3062             :     throw(NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
    3063             : {
    3064          43 :     impl_checkLoaded();
    3065             : 
    3066          43 :     Any aRetAny = maNameContainer.getByName( aName ) ;
    3067          43 :     return aRetAny;
    3068             : }
    3069             : 
    3070        2075 : Sequence< OUString > SfxLibrary::getElementNames()
    3071             :     throw(RuntimeException, std::exception)
    3072             : {
    3073        2075 :     return maNameContainer.getElementNames();
    3074             : }
    3075             : 
    3076          43 : sal_Bool SfxLibrary::hasByName( const OUString& aName )
    3077             :     throw(RuntimeException, std::exception)
    3078             : {
    3079          43 :     bool bRet = maNameContainer.hasByName( aName );
    3080          43 :     return bRet;
    3081             : }
    3082             : 
    3083         149 : void SfxLibrary::impl_checkReadOnly()
    3084             : {
    3085         149 :     if( mbReadOnly || (mbLink && mbReadOnlyLink) )
    3086             :     {
    3087             :         throw IllegalArgumentException(
    3088             :             OUString("Library is readonly."),
    3089             :             // TODO: resource
    3090             :             *this, 0
    3091           0 :         );
    3092             :     }
    3093         149 : }
    3094             : 
    3095         192 : void SfxLibrary::impl_checkLoaded()
    3096             : {
    3097         192 :     if ( !mbLoaded )
    3098             :     {
    3099             :         throw WrappedTargetException(
    3100             :             OUString(),
    3101             :             *this,
    3102             :             makeAny( LibraryNotLoadedException(
    3103             :                 OUString(),
    3104             :                 *this
    3105             :             ) )
    3106           0 :         );
    3107             :     }
    3108         192 : }
    3109             : 
    3110             : // Methods XNameReplace
    3111           0 : void SfxLibrary::replaceByName( const OUString& aName, const Any& aElement )
    3112             :     throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
    3113             : {
    3114           0 :     impl_checkReadOnly();
    3115           0 :     impl_checkLoaded();
    3116             : 
    3117             :     SAL_WARN_IF(
    3118             :         !isLibraryElementValid(aElement), "basic",
    3119             :         "SfxLibrary::replaceByName: replacing element is invalid!");
    3120             : 
    3121           0 :     maNameContainer.replaceByName( aName, aElement );
    3122           0 :     implSetModified( true );
    3123           0 : }
    3124             : 
    3125             : 
    3126             : // Methods XNameContainer
    3127         149 : void SfxLibrary::insertByName( const OUString& aName, const Any& aElement )
    3128             :     throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException, std::exception)
    3129             : {
    3130         149 :     impl_checkReadOnly();
    3131         149 :     impl_checkLoaded();
    3132             : 
    3133             :     SAL_WARN_IF(
    3134             :         !isLibraryElementValid(aElement), "basic",
    3135             :         "SfxLibrary::insertByName: to-be-inserted element is invalid!");
    3136             : 
    3137         149 :     maNameContainer.insertByName( aName, aElement );
    3138         149 :     implSetModified( true );
    3139         149 : }
    3140             : 
    3141           0 : void SfxLibrary::impl_removeWithoutChecks( const OUString& _rElementName )
    3142             : {
    3143           0 :     maNameContainer.removeByName( _rElementName );
    3144           0 :     implSetModified( true );
    3145             : 
    3146             :     // Remove element file
    3147           0 :     if( !maStorageURL.isEmpty() )
    3148             :     {
    3149           0 :         INetURLObject aElementInetObj( maStorageURL );
    3150             :         aElementInetObj.insertName( _rElementName, false,
    3151             :                                     INetURLObject::LAST_SEGMENT, true,
    3152           0 :                                     INetURLObject::ENCODE_ALL );
    3153           0 :         aElementInetObj.setExtension( maLibElementFileExtension );
    3154           0 :         OUString aFile = aElementInetObj.GetMainURL( INetURLObject::NO_DECODE );
    3155             : 
    3156             :         try
    3157             :         {
    3158           0 :             if( mxSFI->exists( aFile ) )
    3159             :             {
    3160           0 :                 mxSFI->kill( aFile );
    3161             :             }
    3162             :         }
    3163           0 :         catch(const Exception& )
    3164             :         {
    3165             :             DBG_UNHANDLED_EXCEPTION();
    3166           0 :         }
    3167             :     }
    3168           0 : }
    3169             : 
    3170           0 : void SfxLibrary::removeByName( const OUString& Name )
    3171             :     throw(NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
    3172             : {
    3173           0 :     impl_checkReadOnly();
    3174           0 :     impl_checkLoaded();
    3175           0 :     impl_removeWithoutChecks( Name );
    3176           0 : }
    3177             : 
    3178             : // XTypeProvider
    3179           0 : Sequence< Type > SfxLibrary::getTypes()
    3180             :     throw( RuntimeException, std::exception )
    3181             : {
    3182             :     static OTypeCollection * s_pTypes_NameContainer = 0;
    3183             :     {
    3184           0 :         if( !s_pTypes_NameContainer )
    3185             :         {
    3186           0 :             MutexGuard aGuard( Mutex::getGlobalMutex() );
    3187           0 :             if( !s_pTypes_NameContainer )
    3188             :             {
    3189             :                 static OTypeCollection s_aTypes_NameContainer(
    3190           0 :                     ::getCppuType( (const Reference< XNameContainer > *)0 ),
    3191           0 :                     ::getCppuType( (const Reference< XContainer > *)0 ),
    3192           0 :                     ::getCppuType( (const Reference< XChangesNotifier > *)0 ),
    3193           0 :                     OComponentHelper::getTypes() );
    3194           0 :                 s_pTypes_NameContainer = &s_aTypes_NameContainer;
    3195           0 :             }
    3196             :         }
    3197           0 :         return s_pTypes_NameContainer->getTypes();
    3198             :     }
    3199             : }
    3200             : 
    3201             : 
    3202           0 : Sequence< sal_Int8 > SfxLibrary::getImplementationId()
    3203             :     throw( RuntimeException, std::exception )
    3204             : {
    3205           0 :     return css::uno::Sequence<sal_Int8>();
    3206             : }
    3207             : 
    3208             : // Methods XContainer
    3209        2012 : void SAL_CALL SfxLibrary::addContainerListener( const Reference< XContainerListener >& xListener )
    3210             :     throw (RuntimeException, std::exception)
    3211             : {
    3212        2012 :     maNameContainer.setEventSource( static_cast< XInterface* >( (OWeakObject*)this ) );
    3213        2012 :     maNameContainer.addContainerListener( xListener );
    3214        2012 : }
    3215             : 
    3216           0 : void SAL_CALL SfxLibrary::removeContainerListener( const Reference< XContainerListener >& xListener )
    3217             :     throw (RuntimeException, std::exception)
    3218             : {
    3219           0 :     maNameContainer.removeContainerListener( xListener );
    3220           0 : }
    3221             : 
    3222             : // Methods XChangesNotifier
    3223          26 : void SAL_CALL SfxLibrary::addChangesListener( const Reference< XChangesListener >& xListener )
    3224             :     throw (RuntimeException, std::exception)
    3225             : {
    3226          26 :     maNameContainer.setEventSource( static_cast< XInterface* >( (OWeakObject*)this ) );
    3227          26 :     maNameContainer.addChangesListener( xListener );
    3228          26 : }
    3229             : 
    3230           0 : void SAL_CALL SfxLibrary::removeChangesListener( const Reference< XChangesListener >& xListener )
    3231             :     throw (RuntimeException, std::exception)
    3232             : {
    3233           0 :     maNameContainer.removeChangesListener( xListener );
    3234           0 : }
    3235             : 
    3236             : 
    3237             : // Implementation class ScriptExtensionIterator
    3238             : 
    3239             : #define sBasicLibMediaType "application/vnd.sun.star.basic-library"
    3240             : #define sDialogLibMediaType "application/vnd.sun.star.dialog-library"
    3241             : 
    3242         142 : ScriptExtensionIterator::ScriptExtensionIterator( void )
    3243             :     : m_xContext( comphelper::getProcessComponentContext() )
    3244             :     , m_eState( USER_EXTENSIONS )
    3245             :     , m_bUserPackagesLoaded( false )
    3246             :     , m_bSharedPackagesLoaded( false )
    3247             :     , m_bBundledPackagesLoaded( false )
    3248             :     , m_iUserPackage( 0 )
    3249             :     , m_iSharedPackage( 0 )
    3250             :        , m_iBundledPackage( 0 )
    3251         142 :     , m_pScriptSubPackageIterator( NULL )
    3252         142 : {}
    3253             : 
    3254         142 : OUString ScriptExtensionIterator::nextBasicOrDialogLibrary( bool& rbPureDialogLib )
    3255             : {
    3256         142 :     OUString aRetLib;
    3257             : 
    3258         526 :     while( aRetLib.isEmpty() && m_eState != END_REACHED )
    3259             :     {
    3260         254 :         switch( m_eState )
    3261             :         {
    3262             :             case USER_EXTENSIONS:
    3263             :             {
    3264             :                 Reference< deployment::XPackage > xScriptPackage =
    3265         142 :                     implGetNextUserScriptPackage( rbPureDialogLib );
    3266         130 :                 if( !xScriptPackage.is() )
    3267             :                 {
    3268         130 :                     break;
    3269             :                 }
    3270           0 :                 aRetLib = xScriptPackage->getURL();
    3271           0 :                 break;
    3272             :             }
    3273             : 
    3274             :             case SHARED_EXTENSIONS:
    3275             :             {
    3276             :                 Reference< deployment::XPackage > xScriptPackage =
    3277          56 :                     implGetNextSharedScriptPackage( rbPureDialogLib );
    3278          56 :                 if( !xScriptPackage.is() )
    3279             :                 {
    3280          56 :                     break;
    3281             :                 }
    3282           0 :                 aRetLib = xScriptPackage->getURL();
    3283           0 :                 break;
    3284             :             }
    3285             :             case BUNDLED_EXTENSIONS:
    3286             :             {
    3287             :                 Reference< deployment::XPackage > xScriptPackage =
    3288          56 :                     implGetNextBundledScriptPackage( rbPureDialogLib );
    3289          56 :                 if( !xScriptPackage.is() )
    3290             :                 {
    3291          56 :                     break;
    3292             :                 }
    3293           0 :                 aRetLib = xScriptPackage->getURL();
    3294           0 :                 break;
    3295             :             }
    3296             :             case END_REACHED:
    3297             :                 SAL_WARN(
    3298             :                     "basic",
    3299             :                     ("ScriptExtensionIterator::nextBasicOrDialogLibrary():"
    3300             :                      " Invalid case END_REACHED"));
    3301           0 :                 break;
    3302             :         }
    3303             :     }
    3304             : 
    3305         130 :     return aRetLib;
    3306             : }
    3307             : 
    3308           0 : ScriptSubPackageIterator::ScriptSubPackageIterator( Reference< deployment::XPackage > xMainPackage )
    3309             :     : m_xMainPackage( xMainPackage )
    3310             :     , m_bIsValid( false )
    3311             :     , m_bIsBundle( false )
    3312             :     , m_nSubPkgCount( 0 )
    3313           0 :     , m_iNextSubPkg( 0 )
    3314             : {
    3315           0 :     Reference< deployment::XPackage > xScriptPackage;
    3316           0 :     if( !m_xMainPackage.is() )
    3317             :     {
    3318           0 :         return;
    3319             :     }
    3320             :     // Check if parent package is registered
    3321           0 :     beans::Optional< beans::Ambiguous<sal_Bool> > option( m_xMainPackage->isRegistered
    3322           0 :         ( Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>() ) );
    3323           0 :     bool bRegistered = false;
    3324           0 :     if( option.IsPresent )
    3325             :     {
    3326           0 :         beans::Ambiguous<sal_Bool> const & reg = option.Value;
    3327           0 :         if( !reg.IsAmbiguous && reg.Value )
    3328             :         {
    3329           0 :             bRegistered = true;
    3330             :         }
    3331             :     }
    3332           0 :     if( bRegistered )
    3333             :     {
    3334           0 :         m_bIsValid = true;
    3335           0 :         if( m_xMainPackage->isBundle() )
    3336             :         {
    3337           0 :             m_bIsBundle = true;
    3338           0 :             m_aSubPkgSeq = m_xMainPackage->getBundle( Reference<task::XAbortChannel>(),
    3339           0 :                                                       Reference<ucb::XCommandEnvironment>() );
    3340           0 :             m_nSubPkgCount = m_aSubPkgSeq.getLength();
    3341             :         }
    3342           0 :     }
    3343             : }
    3344             : 
    3345           0 : Reference< deployment::XPackage > ScriptSubPackageIterator::getNextScriptSubPackage( bool& rbPureDialogLib )
    3346             : {
    3347           0 :     rbPureDialogLib = false;
    3348             : 
    3349           0 :     Reference< deployment::XPackage > xScriptPackage;
    3350           0 :     if( !m_bIsValid )
    3351             :     {
    3352           0 :         return xScriptPackage;
    3353             :     }
    3354           0 :     if( m_bIsBundle )
    3355             :     {
    3356           0 :         const Reference< deployment::XPackage >* pSeq = m_aSubPkgSeq.getConstArray();
    3357             :         sal_Int32 iPkg;
    3358           0 :         for( iPkg = m_iNextSubPkg ; iPkg < m_nSubPkgCount ; ++iPkg )
    3359             :         {
    3360           0 :             const Reference< deployment::XPackage > xSubPkg = pSeq[ iPkg ];
    3361           0 :             xScriptPackage = implDetectScriptPackage( xSubPkg, rbPureDialogLib );
    3362           0 :             if( xScriptPackage.is() )
    3363             :             {
    3364           0 :                 break;
    3365             :             }
    3366           0 :         }
    3367           0 :         m_iNextSubPkg = iPkg + 1;
    3368             :     }
    3369             :     else
    3370             :     {
    3371           0 :         xScriptPackage = implDetectScriptPackage( m_xMainPackage, rbPureDialogLib );
    3372           0 :         m_bIsValid = false;     // No more script packages
    3373             :     }
    3374             : 
    3375           0 :     return xScriptPackage;
    3376             : }
    3377             : 
    3378           0 : Reference< deployment::XPackage > ScriptSubPackageIterator::implDetectScriptPackage ( const Reference< deployment::XPackage > xPackage,
    3379             :                                                                                       bool& rbPureDialogLib )
    3380             : {
    3381           0 :     Reference< deployment::XPackage > xScriptPackage;
    3382             : 
    3383           0 :     if( xPackage.is() )
    3384             :     {
    3385           0 :         const Reference< deployment::XPackageTypeInfo > xPackageTypeInfo = xPackage->getPackageType();
    3386           0 :         OUString aMediaType = xPackageTypeInfo->getMediaType();
    3387           0 :         if ( aMediaType == sBasicLibMediaType )
    3388             :         {
    3389           0 :             xScriptPackage = xPackage;
    3390             :         }
    3391           0 :         else if ( aMediaType == sDialogLibMediaType )
    3392             :         {
    3393           0 :             rbPureDialogLib = true;
    3394           0 :             xScriptPackage = xPackage;
    3395           0 :         }
    3396             :     }
    3397             : 
    3398           0 :     return xScriptPackage;
    3399             : }
    3400             : 
    3401         142 : Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextUserScriptPackage( bool& rbPureDialogLib )
    3402             : {
    3403         142 :     Reference< deployment::XPackage > xScriptPackage;
    3404             : 
    3405         142 :     if( !m_bUserPackagesLoaded )
    3406             :     {
    3407             :         try
    3408             :         {
    3409         142 :             Reference< XExtensionManager > xManager = ExtensionManager::get( m_xContext );
    3410         192 :             m_aUserPackagesSeq = xManager->getDeployedExtensions(OUString("user"),
    3411             :                                                                  Reference< task::XAbortChannel >(),
    3412         192 :                                                                  Reference< ucb::XCommandEnvironment >() );
    3413             :         }
    3414         148 :         catch(const com::sun::star::uno::DeploymentException& )
    3415             :         {
    3416             :             // Special Office installations may not contain deployment code
    3417          74 :             m_eState = END_REACHED;
    3418          74 :             return xScriptPackage;
    3419             :         }
    3420             : 
    3421          56 :         m_bUserPackagesLoaded = true;
    3422             :     }
    3423             : 
    3424          56 :     if( m_iUserPackage == m_aUserPackagesSeq.getLength() )
    3425             :     {
    3426          56 :         m_eState = SHARED_EXTENSIONS;       // Later: SHARED_MODULE
    3427             :     }
    3428             :     else
    3429             :     {
    3430           0 :         if( m_pScriptSubPackageIterator == NULL )
    3431             :         {
    3432           0 :             const Reference< deployment::XPackage >* pUserPackages = m_aUserPackagesSeq.getConstArray();
    3433           0 :             Reference< deployment::XPackage > xPackage = pUserPackages[ m_iUserPackage ];
    3434             :             SAL_WARN_IF(
    3435             :                 !xPackage.is(), "basic",
    3436             :                 ("ScriptExtensionIterator::implGetNextUserScriptPackage():"
    3437             :                  " Invalid package"));
    3438           0 :             m_pScriptSubPackageIterator = new ScriptSubPackageIterator( xPackage );
    3439             :         }
    3440             : 
    3441           0 :         if( m_pScriptSubPackageIterator != NULL )
    3442             :         {
    3443           0 :             xScriptPackage = m_pScriptSubPackageIterator->getNextScriptSubPackage( rbPureDialogLib );
    3444           0 :             if( !xScriptPackage.is() )
    3445             :             {
    3446           0 :                 delete m_pScriptSubPackageIterator;
    3447           0 :                 m_pScriptSubPackageIterator = NULL;
    3448           0 :                 m_iUserPackage++;
    3449             :             }
    3450             :         }
    3451             :     }
    3452             : 
    3453          56 :     return xScriptPackage;
    3454             : }
    3455             : 
    3456          56 : Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextSharedScriptPackage( bool& rbPureDialogLib )
    3457             : {
    3458          56 :     Reference< deployment::XPackage > xScriptPackage;
    3459             : 
    3460          56 :     if( !m_bSharedPackagesLoaded )
    3461             :     {
    3462             :         try
    3463             :         {
    3464          56 :             Reference< XExtensionManager > xSharedManager = ExtensionManager::get( m_xContext );
    3465         168 :             m_aSharedPackagesSeq = xSharedManager->getDeployedExtensions(OUString("shared"),
    3466             :                                                                          Reference< task::XAbortChannel >(),
    3467         168 :                                                                          Reference< ucb::XCommandEnvironment >() );
    3468             :         }
    3469           0 :         catch(const com::sun::star::uno::DeploymentException& )
    3470             :         {
    3471             :             // Special Office installations may not contain deployment code
    3472           0 :             return xScriptPackage;
    3473             :         }
    3474             : 
    3475          56 :         m_bSharedPackagesLoaded = true;
    3476             :     }
    3477             : 
    3478          56 :     if( m_iSharedPackage == m_aSharedPackagesSeq.getLength() )
    3479             :     {
    3480          56 :         m_eState = BUNDLED_EXTENSIONS;
    3481             :     }
    3482             :     else
    3483             :     {
    3484           0 :         if( m_pScriptSubPackageIterator == NULL )
    3485             :         {
    3486           0 :             const Reference< deployment::XPackage >* pSharedPackages = m_aSharedPackagesSeq.getConstArray();
    3487           0 :             Reference< deployment::XPackage > xPackage = pSharedPackages[ m_iSharedPackage ];
    3488             :             SAL_WARN_IF(
    3489             :                 !xPackage.is(), "basic",
    3490             :                 ("ScriptExtensionIterator::implGetNextSharedScriptPackage():"
    3491             :                  " Invalid package"));
    3492           0 :             m_pScriptSubPackageIterator = new ScriptSubPackageIterator( xPackage );
    3493             :         }
    3494             : 
    3495           0 :         if( m_pScriptSubPackageIterator != NULL )
    3496             :         {
    3497           0 :             xScriptPackage = m_pScriptSubPackageIterator->getNextScriptSubPackage( rbPureDialogLib );
    3498           0 :             if( !xScriptPackage.is() )
    3499             :             {
    3500           0 :                 delete m_pScriptSubPackageIterator;
    3501           0 :                 m_pScriptSubPackageIterator = NULL;
    3502           0 :                 m_iSharedPackage++;
    3503             :             }
    3504             :         }
    3505             :     }
    3506             : 
    3507          56 :     return xScriptPackage;
    3508             : }
    3509             : 
    3510          56 : Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextBundledScriptPackage( bool& rbPureDialogLib )
    3511             : {
    3512          56 :     Reference< deployment::XPackage > xScriptPackage;
    3513             : 
    3514          56 :     if( !m_bBundledPackagesLoaded )
    3515             :     {
    3516             :         try
    3517             :         {
    3518          56 :             Reference< XExtensionManager > xManager = ExtensionManager::get( m_xContext );
    3519         168 :             m_aBundledPackagesSeq = xManager->getDeployedExtensions(OUString("bundled"),
    3520             :                                                                     Reference< task::XAbortChannel >(),
    3521         168 :                                                                     Reference< ucb::XCommandEnvironment >() );
    3522             :         }
    3523           0 :         catch(const com::sun::star::uno::DeploymentException& )
    3524             :         {
    3525             :             // Special Office installations may not contain deployment code
    3526           0 :             return xScriptPackage;
    3527             :         }
    3528             : 
    3529          56 :         m_bBundledPackagesLoaded = true;
    3530             :     }
    3531             : 
    3532          56 :     if( m_iBundledPackage == m_aBundledPackagesSeq.getLength() )
    3533             :     {
    3534          56 :         m_eState = END_REACHED;
    3535             :     }
    3536             :     else
    3537             :     {
    3538           0 :         if( m_pScriptSubPackageIterator == NULL )
    3539             :         {
    3540           0 :             const Reference< deployment::XPackage >* pBundledPackages = m_aBundledPackagesSeq.getConstArray();
    3541           0 :             Reference< deployment::XPackage > xPackage = pBundledPackages[ m_iBundledPackage ];
    3542             :             SAL_WARN_IF(
    3543             :                 !xPackage.is(), "basic",
    3544             :                 ("ScriptExtensionIterator::implGetNextBundledScriptPackage():"
    3545             :                  " Invalid package"));
    3546           0 :             m_pScriptSubPackageIterator = new ScriptSubPackageIterator( xPackage );
    3547             :         }
    3548             : 
    3549           0 :         if( m_pScriptSubPackageIterator != NULL )
    3550             :         {
    3551           0 :             xScriptPackage = m_pScriptSubPackageIterator->getNextScriptSubPackage( rbPureDialogLib );
    3552           0 :             if( !xScriptPackage.is() )
    3553             :             {
    3554           0 :                 delete m_pScriptSubPackageIterator;
    3555           0 :                 m_pScriptSubPackageIterator = NULL;
    3556           0 :                 m_iBundledPackage++;
    3557             :             }
    3558             :         }
    3559             :     }
    3560             : 
    3561          56 :     return xScriptPackage;
    3562             : }
    3563             : 
    3564             : }   // namespace basic
    3565             : 
    3566             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10