LCOV - code coverage report
Current view: top level - basic/source/uno - namecont.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 807 1645 49.1 %
Date: 2012-08-25 Functions: 70 116 60.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 869 3643 23.9 %

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

Generated by: LCOV version 1.10