1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: namecont.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basic.hxx"
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include <com/sun/star/container/XContainer.hpp>
35 #include <com/sun/star/embed/ElementModes.hpp>
36 #include <com/sun/star/embed/XTransactedObject.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <vcl/svapp.hxx>
39 #include <vos/mutex.hxx>
40 #ifndef __RSC //autogen
41 #include <tools/errinf.hxx>
43 #include <osl/mutex.hxx>
44 #include <vos/diagnose.hxx>
45 #include <rtl/uri.hxx>
46 #include <rtl/strbuf.hxx>
47 #include <comphelper/processfactory.hxx>
48 #ifndef INCLUDED_COMPHELPER_ANYTOSTRING_HXX
49 #include <comphelper/anytostring.hxx>
52 #include "namecont.hxx"
53 #include <basic/basicmanagerrepository.hxx>
54 #include <tools/diagnose_ex.h>
55 #include <tools/urlobj.hxx>
56 #include <unotools/streamwrap.hxx>
57 #include <svtools/pathoptions.hxx>
58 #include <svtools/sfxecode.hxx>
59 #include <svtools/ehdl.hxx>
60 #include <basic/basmgr.hxx>
61 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
62 #include <com/sun/star/xml/sax/XParser.hpp>
63 #include <com/sun/star/xml/sax/InputSource.hpp>
64 #include <com/sun/star/io/XOutputStream.hpp>
65 #include <com/sun/star/io/XInputStream.hpp>
66 #include <com/sun/star/io/XActiveDataSource.hpp>
67 #include <com/sun/star/beans/XPropertySet.hpp>
68 #include <com/sun/star/uno/DeploymentException.hpp>
69 #include <com/sun/star/lang/DisposedException.hpp>
70 #include <com/sun/star/script/LibraryNotLoadedException.hpp>
71 #include "com/sun/star/deployment/thePackageManagerFactory.hpp"
72 #include <comphelper/storagehelper.hxx>
73 #ifndef _RTL_USTRING_HXX_
74 #include <comphelper/anytostring.hxx>
76 #include <cppuhelper/exc_hlp.hxx>
77 #include <basic/sbmod.hxx>
79 #ifndef _COM_SUN_STAR_SCRIPT_MODULEINFO_HPP_
80 #include <com/sun/star/script/ModuleInfo.hpp>
86 using namespace com::sun::star::document
;
87 using namespace com::sun::star::container
;
88 using namespace com::sun::star::uno
;
89 using namespace com::sun::star::lang
;
90 using namespace com::sun::star::io
;
91 using namespace com::sun::star::ucb
;
92 using namespace com::sun::star::script
;
93 using namespace com::sun::star::beans
;
94 using namespace com::sun::star::xml::sax
;
95 using namespace com::sun::star::util
;
96 using namespace com::sun::star::task
;
97 using namespace com::sun::star::embed
;
98 using namespace com::sun::star::frame
;
99 using namespace com::sun::star::deployment
;
100 using namespace com::sun::star
;
101 using namespace cppu
;
105 using com::sun::star::uno::Reference
;
107 // #i34411: Flag for error handling during migration
108 static bool GbMigrationSuppressErrors
= false;
110 //============================================================================
111 // Implementation class NameContainer
113 // Methods XElementAccess
114 Type
NameContainer::getElementType()
115 throw(RuntimeException
)
120 sal_Bool
NameContainer::hasElements()
121 throw(RuntimeException
)
123 sal_Bool bRet
= (mnElementCount
> 0);
127 // Methods XNameAccess
128 Any
NameContainer::getByName( const OUString
& aName
)
129 throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
131 NameContainerNameMap::iterator aIt
= mHashMap
.find( aName
);
132 if( aIt
== mHashMap
.end() )
134 throw NoSuchElementException();
136 sal_Int32 iHashResult
= (*aIt
).second
;
137 Any aRetAny
= mValues
.getConstArray()[ iHashResult
];
141 Sequence
< OUString
> NameContainer::getElementNames()
142 throw(RuntimeException
)
147 sal_Bool
NameContainer::hasByName( const OUString
& aName
)
148 throw(RuntimeException
)
150 NameContainerNameMap::iterator aIt
= mHashMap
.find( aName
);
151 sal_Bool bRet
= ( aIt
!= mHashMap
.end() );
156 // Methods XNameReplace
157 void NameContainer::replaceByName( const OUString
& aName
, const Any
& aElement
)
158 throw(IllegalArgumentException
, NoSuchElementException
, WrappedTargetException
, RuntimeException
)
160 Type aAnyType
= aElement
.getValueType();
161 if( mType
!= aAnyType
&& aAnyType
!= getCppuType( static_cast< ModuleInfo
* >( NULL
) ) )
162 throw IllegalArgumentException();
164 NameContainerNameMap::iterator aIt
= mHashMap
.find( aName
);
165 if( aIt
== mHashMap
.end() )
167 throw NoSuchElementException();
169 sal_Int32 iHashResult
= (*aIt
).second
;
170 Any aOldElement
= mValues
.getConstArray()[ iHashResult
];
171 mValues
.getArray()[ iHashResult
] = aElement
;
175 ContainerEvent aEvent
;
176 aEvent
.Source
= mpxEventSource
;
177 aEvent
.Accessor
<<= aName
;
178 aEvent
.Element
= aElement
;
179 aEvent
.ReplacedElement
= aOldElement
;
181 OInterfaceIteratorHelper
aIterator( maListenerContainer
);
182 while( aIterator
.hasMoreElements() )
184 Reference
< XInterface
> xIface
= aIterator
.next();
185 Reference
< XContainerListener
> xListener( xIface
, UNO_QUERY
);
188 xListener
->elementReplaced( aEvent
);
190 catch(RuntimeException
&)
198 // Methods XNameContainer
199 void NameContainer::insertByName( const OUString
& aName
, const Any
& aElement
)
200 throw(IllegalArgumentException
, ElementExistException
, WrappedTargetException
, RuntimeException
)
202 Type aAnyType
= aElement
.getValueType();
203 if( mType
!= aAnyType
&& aAnyType
!= getCppuType( static_cast< ModuleInfo
* >( NULL
) ) )
204 throw IllegalArgumentException();
206 NameContainerNameMap::iterator aIt
= mHashMap
.find( aName
);
207 if( aIt
!= mHashMap
.end() )
209 throw ElementExistException();
212 sal_Int32 nCount
= mNames
.getLength();
213 mNames
.realloc( nCount
+ 1 );
214 mValues
.realloc( nCount
+ 1 );
215 mNames
.getArray()[ nCount
] = aName
;
216 mValues
.getArray()[ nCount
] = aElement
;
218 mHashMap
[ aName
] = nCount
;
223 ContainerEvent aEvent
;
224 aEvent
.Source
= mpxEventSource
;
225 aEvent
.Accessor
<<= aName
;
226 aEvent
.Element
= aElement
;
228 OInterfaceIteratorHelper
aIterator( maListenerContainer
);
229 while( aIterator
.hasMoreElements() )
231 Reference
< XInterface
> xIface
= aIterator
.next();
232 Reference
< XContainerListener
> xListener( xIface
, UNO_QUERY
);
235 xListener
->elementInserted( aEvent
);
237 catch(RuntimeException
&)
244 void NameContainer::removeByName( const OUString
& Name
)
245 throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
247 NameContainerNameMap::iterator aIt
= mHashMap
.find( Name
);
248 if( aIt
== mHashMap
.end() )
250 throw NoSuchElementException();
253 sal_Int32 iHashResult
= (*aIt
).second
;
254 Any aOldElement
= mValues
.getConstArray()[ iHashResult
];
255 mHashMap
.erase( aIt
);
256 sal_Int32 iLast
= mNames
.getLength() - 1;
257 if( iLast
!= iHashResult
)
259 OUString
* pNames
= mNames
.getArray();
260 Any
* pValues
= mValues
.getArray();
261 pNames
[ iHashResult
] = pNames
[ iLast
];
262 pValues
[ iHashResult
] = pValues
[ iLast
];
263 mHashMap
[ pNames
[ iHashResult
] ] = iHashResult
;
265 mNames
.realloc( iLast
);
266 mValues
.realloc( iLast
);
271 ContainerEvent aEvent
;
272 aEvent
.Source
= mpxEventSource
;
273 aEvent
.Accessor
<<= Name
;
274 aEvent
.Element
= aOldElement
;
276 OInterfaceIteratorHelper
aIterator( maListenerContainer
);
277 while( aIterator
.hasMoreElements() )
279 Reference
< XInterface
> xIface
= aIterator
.next();
280 Reference
< XContainerListener
> xListener( xIface
, UNO_QUERY
);
283 xListener
->elementRemoved( aEvent
);
285 catch(RuntimeException
&)
293 // Methods XContainer
294 void SAL_CALL
NameContainer::addContainerListener( const Reference
< XContainerListener
>& xListener
)
295 throw (RuntimeException
)
297 if( !xListener
.is() )
298 throw RuntimeException();
299 Reference
< XInterface
> xIface( xListener
, UNO_QUERY
);
300 maListenerContainer
.addInterface( xIface
);
303 void SAL_CALL
NameContainer::removeContainerListener( const Reference
< XContainerListener
>& xListener
)
304 throw (RuntimeException
)
306 if( !xListener
.is() )
307 throw RuntimeException();
308 Reference
< XInterface
> xIface( xListener
, UNO_QUERY
);
309 maListenerContainer
.removeInterface( xIface
);
312 //============================================================================
315 void ModifiableHelper::setModified( sal_Bool _bModified
)
317 if ( _bModified
== mbModified
)
319 mbModified
= _bModified
;
321 if ( m_aModifyListeners
.getLength() == 0 )
324 EventObject
aModifyEvent( m_rEventSource
);
325 m_aModifyListeners
.notifyEach( &XModifyListener::modified
, aModifyEvent
);
328 //============================================================================
330 // Implementation class SfxLibraryContainer
331 DBG_NAME( SfxLibraryContainer
)
334 SfxLibraryContainer::SfxLibraryContainer( void )
335 : LibraryContainerHelper( maMutex
)
336 , maModifiable( *this, maMutex
)
337 , maNameContainer( getCppuType( (Reference
< XNameAccess
>*) NULL
) )
338 , mbOldInfoFormat( sal_False
)
339 , mbOasis2OOoFormat( sal_False
)
341 , mbOwnBasMgr( sal_False
)
343 DBG_CTOR( SfxLibraryContainer
, NULL
);
345 mxMSF
= comphelper::getProcessServiceFactory();
348 OSL_ENSURE( 0, "### couln't get ProcessServiceFactory\n" );
351 mxSFI
= Reference
< XSimpleFileAccess
>( mxMSF
->createInstance
352 ( OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY
);
355 OSL_ENSURE( 0, "### couln't create SimpleFileAccess component\n" );
358 mxStringSubstitution
= Reference
< XStringSubstitution
>( mxMSF
->createInstance
359 ( OUString::createFromAscii( "com.sun.star.util.PathSubstitution" ) ), UNO_QUERY
);
360 if( !mxStringSubstitution
.is() )
362 OSL_ENSURE( 0, "### couln't create PathSubstitution component\n" );
366 SfxLibraryContainer::~SfxLibraryContainer()
369 BasicManager::LegacyDeleteBasicManager( mpBasMgr
);
370 DBG_DTOR( SfxLibraryContainer
, NULL
);
373 void SfxLibraryContainer::checkDisposed() const
376 throw DisposedException( ::rtl::OUString(), *const_cast< SfxLibraryContainer
* >( this ) );
379 void SfxLibraryContainer::enterMethod()
385 void SfxLibraryContainer::leaveMethod()
390 BasicManager
* SfxLibraryContainer::getBasicManager( void )
395 Reference
< XModel
> xDocument( mxOwnerDocument
.get(), UNO_QUERY
);
396 OSL_ENSURE( xDocument
.is(), "SfxLibraryContainer::getBasicManager: cannot obtain a BasicManager without document!" );
397 if ( xDocument
.is() )
398 mpBasMgr
= BasicManagerRepository::getDocumentBasicManager( xDocument
);
403 // Methods XStorageBasedLibraryContainer
404 Reference
< XStorage
> SAL_CALL
SfxLibraryContainer::getRootStorage() throw (RuntimeException
)
406 LibraryContainerMethodGuard
aGuard( *this );
410 void SAL_CALL
SfxLibraryContainer::setRootStorage( const Reference
< XStorage
>& _rxRootStorage
) throw (IllegalArgumentException
, RuntimeException
)
412 LibraryContainerMethodGuard
aGuard( *this );
413 if ( !_rxRootStorage
.is() )
414 throw IllegalArgumentException();
416 mxStorage
= _rxRootStorage
;
420 void SAL_CALL
SfxLibraryContainer::storeLibrariesToStorage( const Reference
< XStorage
>& _rxRootStorage
) throw (IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
422 LibraryContainerMethodGuard
aGuard( *this );
423 if ( !_rxRootStorage
.is() )
424 throw IllegalArgumentException();
428 storeLibraries_Impl( _rxRootStorage
, sal_True
);
430 catch( const Exception
& )
432 throw WrappedTargetException( ::rtl::OUString(), *this, ::cppu::getCaughtException() );
437 // Methods XModifiable
438 sal_Bool
SfxLibraryContainer::isModified() throw (RuntimeException
)
440 LibraryContainerMethodGuard
aGuard( *this );
441 if ( maModifiable
.isModified() )
444 // the library container is not modified, go through the libraries and check whether they are modified
445 Sequence
< OUString
> aNames
= maNameContainer
.getElementNames();
446 const OUString
* pNames
= aNames
.getConstArray();
447 sal_Int32 nNameCount
= aNames
.getLength();
449 for( sal_Int32 i
= 0 ; i
< nNameCount
; i
++ )
451 OUString aName
= pNames
[ i
];
452 SfxLibrary
* pImplLib
= getImplLib( aName
);
453 if( pImplLib
->isModified() )
455 if ( aName
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") ) ) )
457 // this is a workaround that has to be implemented because
458 // empty standard library should stay marked as modified
459 // but should not be treated as modified while it is empty
460 if ( pImplLib
->hasElements() )
471 void SAL_CALL
SfxLibraryContainer::setModified( sal_Bool _bModified
) throw (PropertyVetoException
, RuntimeException
)
473 LibraryContainerMethodGuard
aGuard( *this );
474 maModifiable
.setModified( _bModified
);
477 void SAL_CALL
SfxLibraryContainer::addModifyListener( const Reference
< XModifyListener
>& _rxListener
) throw (RuntimeException
)
479 LibraryContainerMethodGuard
aGuard( *this );
480 maModifiable
.addModifyListener( _rxListener
);
483 void SAL_CALL
SfxLibraryContainer::removeModifyListener( const Reference
< XModifyListener
>& _rxListener
) throw (RuntimeException
)
485 LibraryContainerMethodGuard
aGuard( *this );
486 maModifiable
.removeModifyListener( _rxListener
);
489 // Methods XPersistentLibraryContainer
490 Any SAL_CALL
SfxLibraryContainer::getRootLocation() throw (RuntimeException
)
492 LibraryContainerMethodGuard
aGuard( *this );
493 return makeAny( getRootStorage() );
496 ::rtl::OUString SAL_CALL
SfxLibraryContainer::getContainerLocationName() throw (RuntimeException
)
498 LibraryContainerMethodGuard
aGuard( *this );
499 return maLibrariesDir
;
502 void SAL_CALL
SfxLibraryContainer::storeLibraries( ) throw (WrappedTargetException
, RuntimeException
)
504 LibraryContainerMethodGuard
aGuard( *this );
507 storeLibraries_Impl( mxStorage
, mxStorage
.is() );
508 // we need to store *all* libraries if and only if we are based on a storage:
509 // in this case, storeLibraries_Impl will remove the source storage, after loading
510 // all libraries, so we need to force them to be stored, again
512 catch( const Exception
& )
514 throw WrappedTargetException( ::rtl::OUString(), *this, ::cppu::getCaughtException() );
518 static void checkAndCopyFileImpl( const INetURLObject
& rSourceFolderInetObj
,
519 const INetURLObject
& rTargetFolderInetObj
,
520 const OUString
& rCheckFileName
,
521 const OUString
& rCheckExtension
,
522 Reference
< XSimpleFileAccess
> xSFI
)
524 INetURLObject
aTargetFolderInetObj( rTargetFolderInetObj
);
525 aTargetFolderInetObj
.insertName( rCheckFileName
, sal_True
, INetURLObject::LAST_SEGMENT
,
526 sal_True
, INetURLObject::ENCODE_ALL
);
527 aTargetFolderInetObj
.setExtension( rCheckExtension
);
528 OUString aTargetFile
= aTargetFolderInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
529 if( !xSFI
->exists( aTargetFile
) )
531 INetURLObject
aSourceFolderInetObj( rSourceFolderInetObj
);
532 aSourceFolderInetObj
.insertName( rCheckFileName
, sal_True
, INetURLObject::LAST_SEGMENT
,
533 sal_True
, INetURLObject::ENCODE_ALL
);
534 aSourceFolderInetObj
.setExtension( rCheckExtension
);
535 OUString aSourceFile
= aSourceFolderInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
536 xSFI
->copy( aSourceFile
, aTargetFile
);
540 static void createVariableURL( OUString
& rStr
, const OUString
& rLibName
,
541 const OUString
& rInfoFileName
, bool bUser
)
544 rStr
= OUString::createFromAscii( "$(USER)/basic/" );
546 rStr
= OUString::createFromAscii( "$(INST)/share/basic/" );
549 rStr
+= OUString::createFromAscii( "/" );
550 rStr
+= rInfoFileName
;
551 rStr
+= OUString::createFromAscii( ".xlb/" );
554 sal_Bool
SfxLibraryContainer::init( const OUString
& rInitialDocumentURL
, const uno::Reference
< embed::XStorage
>& rxInitialStorage
)
556 // this might be called from within the ctor, and the impl_init might (indirectly) create
557 // an UNO reference to ourself.
558 // Ensure that we're not destroyed while we're in here
559 osl_incrementInterlockedCount( &m_refCount
);
560 sal_Bool bSuccess
= init_Impl( rInitialDocumentURL
, rxInitialStorage
);
561 osl_decrementInterlockedCount( &m_refCount
);
566 sal_Bool
SfxLibraryContainer::init_Impl(
567 const OUString
& rInitialDocumentURL
, const uno::Reference
< embed::XStorage
>& rxInitialStorage
)
569 uno::Reference
< embed::XStorage
> xStorage
= rxInitialStorage
;
571 maInitialDocumentURL
= rInitialDocumentURL
;
572 maInfoFileName
= OUString::createFromAscii( getInfoFileName() );
573 maOldInfoFileName
= OUString::createFromAscii( getOldInfoFileName() );
574 maLibElementFileExtension
= OUString::createFromAscii( getLibElementFileExtension() );
575 maLibrariesDir
= OUString::createFromAscii( getLibrariesDir() );
577 meInitMode
= DEFAULT
;
578 INetURLObject
aInitUrlInetObj( maInitialDocumentURL
);
579 OUString aInitFileName
= aInitUrlInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
580 if( aInitFileName
.getLength() )
582 // We need a BasicManager to avoid problems
583 StarBASIC
* pBas
= new StarBASIC();
584 mpBasMgr
= new BasicManager( pBas
);
585 mbOwnBasMgr
= sal_True
;
587 OUString aExtension
= aInitUrlInetObj
.getExtension();
588 if( aExtension
.compareToAscii( "xlc" ) == COMPARE_EQUAL
)
590 meInitMode
= CONTAINER_INIT_FILE
;
591 INetURLObject
aLibPathInetObj( aInitUrlInetObj
);
592 aLibPathInetObj
.removeSegment();
593 maLibraryPath
= aLibPathInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
595 else if( aExtension
.compareToAscii( "xlb" ) == COMPARE_EQUAL
)
597 meInitMode
= LIBRARY_INIT_FILE
;
598 uno::Reference
< embed::XStorage
> xDummyStor
;
599 ::xmlscript::LibDescriptor aLibDesc
;
600 sal_Bool bReadIndexFile
= implLoadLibraryIndexFile( NULL
, aLibDesc
, xDummyStor
, aInitFileName
);
601 return bReadIndexFile
;
605 // Decide between old and new document
606 sal_Bool bOldStorage
= SotStorage::IsOLEStorage( aInitFileName
);
609 meInitMode
= OLD_BASIC_STORAGE
;
610 importFromOldStorage( aInitFileName
);
615 meInitMode
= OFFICE_DOCUMENT
;
618 xStorage
= ::comphelper::OStorageHelper::GetStorageFromURL( aInitFileName
, embed::ElementModes::READ
);
620 catch ( uno::Exception
& )
622 // TODO: error handling
630 maLibraryPath
= SvtPathOptions().GetBasicPath();
633 Reference
< XParser
> xParser( mxMSF
->createInstance(
634 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ) ), UNO_QUERY
);
637 OSL_ENSURE( 0, "### couln't create sax parser component\n" );
641 uno::Reference
< io::XInputStream
> xInput
;
643 mxStorage
= xStorage
;
644 sal_Bool bStorage
= mxStorage
.is();
647 // #110009: Scope to force the StorageRefs to be destructed and
648 // so the streams to be closed before the preload operation
652 uno::Reference
< embed::XStorage
> xLibrariesStor
;
656 if( !bStorage
&& meInitMode
== DEFAULT
)
658 for( int nPass
= 0 ; nPass
< nPassCount
; nPass
++ )
662 OSL_ENSURE( meInitMode
== DEFAULT
|| meInitMode
== OFFICE_DOCUMENT
,
663 "### Wrong InitMode for document\n" );
666 uno::Reference
< io::XStream
> xStream
;
667 xLibrariesStor
= xStorage
->openStorageElement( maLibrariesDir
, embed::ElementModes::READ
);
668 //if ( !xLibrariesStor.is() )
669 // TODO: the method must either return a storage or throw an exception
670 //throw uno::RuntimeException();
672 if ( xLibrariesStor
.is() )
674 aFileName
= maInfoFileName
;
675 aFileName
+= String( RTL_CONSTASCII_USTRINGPARAM("-lc.xml") );
679 xStream
= xLibrariesStor
->openStreamElement( aFileName
, embed::ElementModes::READ
);
681 catch( uno::Exception
& )
686 mbOldInfoFormat
= true;
689 aFileName
= maOldInfoFileName
;
690 aFileName
+= String( RTL_CONSTASCII_USTRINGPARAM(".xml") );
694 xStream
= xLibrariesStor
->openStreamElement( aFileName
, embed::ElementModes::READ
);
696 catch( uno::Exception
& )
701 // Check for EA2 document version with wrong extensions
702 aFileName
= maOldInfoFileName
;
703 aFileName
+= String( RTL_CONSTASCII_USTRINGPARAM(".xli") );
704 xStream
= xLibrariesStor
->openStreamElement( aFileName
, embed::ElementModes::READ
);
710 xInput
= xStream
->getInputStream();
712 catch( uno::Exception
& )
714 // TODO: error handling?
719 INetURLObject
* pLibInfoInetObj
= NULL
;
720 if( meInitMode
== CONTAINER_INIT_FILE
)
722 aFileName
= aInitFileName
;
727 pLibInfoInetObj
= new INetURLObject( String(maLibraryPath
).GetToken(0) );
729 pLibInfoInetObj
= new INetURLObject( String(maLibraryPath
).GetToken(1) );
730 pLibInfoInetObj
->insertName( maInfoFileName
, sal_True
, INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
731 pLibInfoInetObj
->setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xlc") ) );
732 aFileName
= pLibInfoInetObj
->GetMainURL( INetURLObject::NO_DECODE
);
737 xInput
= mxSFI
->openFileRead( aFileName
);
744 SfxErrorContext
aEc( ERRCTX_SFX_LOADBASIC
, aFileName
);
745 ULONG nErrorCode
= ERRCODE_IO_GENERAL
;
746 ErrorHandler::HandleError( nErrorCode
);
751 if( !xInput
.is() && nPass
== 0 )
753 INetURLObject
aLibInfoInetObj( String(maLibraryPath
).GetToken(1) );
754 aLibInfoInetObj
.insertName( maOldInfoFileName
, sal_True
, INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
755 aLibInfoInetObj
.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xli") ) );
756 aFileName
= aLibInfoInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
760 xInput
= mxSFI
->openFileRead( aFileName
);
761 mbOldInfoFormat
= true;
766 SfxErrorContext
aEc( ERRCTX_SFX_LOADBASIC
, aFileName
);
767 ULONG nErrorCode
= ERRCODE_IO_GENERAL
;
768 ErrorHandler::HandleError( nErrorCode
);
772 delete pLibInfoInetObj
;
778 source
.aInputStream
= xInput
;
779 source
.sSystemId
= aFileName
;
782 ::xmlscript::LibDescriptorArray
* pLibArray
= new ::xmlscript::LibDescriptorArray();
786 xParser
->setDocumentHandler( ::xmlscript::importLibraryContainer( pLibArray
) );
787 xParser
->parseStream( source
);
789 catch ( xml::sax::SAXException
& e
)
791 (void) e
; // avoid warning
792 OSL_ENSURE( 0, OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr() );
795 catch ( io::IOException
& e
)
797 (void) e
; // avoid warning
798 OSL_ENSURE( 0, OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr() );
802 sal_Int32 nLibCount
= pLibArray
->mnLibCount
;
803 for( sal_Int32 i
= 0 ; i
< nLibCount
; i
++ )
805 ::xmlscript::LibDescriptor
& rLib
= pLibArray
->mpLibs
[i
];
808 OUString aStorageURL
= rLib
.aStorageURL
;
809 if( !bStorage
&& !aStorageURL
.getLength() && nPass
== 0 )
812 if( meInitMode
== CONTAINER_INIT_FILE
)
813 aLibraryPath
= maLibraryPath
;
815 aLibraryPath
= String(maLibraryPath
).GetToken(1);
816 INetURLObject
aInetObj( aLibraryPath
);
818 aInetObj
.insertName( rLib
.aName
, sal_True
, INetURLObject::LAST_SEGMENT
,
819 sal_True
, INetURLObject::ENCODE_ALL
);
820 OUString aLibDirPath
= aInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
821 if( mxSFI
->isFolder( aLibDirPath
) )
823 createVariableURL( rLib
.aStorageURL
, rLib
.aName
, maInfoFileName
, true );
824 maModifiable
.setModified( sal_True
);
826 else if( rLib
.bLink
)
828 // Check "share" path
829 INetURLObject
aShareInetObj( String(maLibraryPath
).GetToken(0) );
830 aShareInetObj
.insertName( rLib
.aName
, sal_True
, INetURLObject::LAST_SEGMENT
,
831 sal_True
, INetURLObject::ENCODE_ALL
);
832 OUString aShareLibDirPath
= aShareInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
833 if( mxSFI
->isFolder( aShareLibDirPath
) )
835 createVariableURL( rLib
.aStorageURL
, rLib
.aName
, maInfoFileName
, false );
836 maModifiable
.setModified( sal_True
);
840 // #i25537: Ignore lib if library folder does not really exist
846 OUString aLibName
= rLib
.aName
;
848 // If the same library name is used by the shared and the
849 // user lib container index files the user file wins
850 if( nPass
== 1 && hasByName( aLibName
) )
853 SfxLibrary
* pImplLib
;
856 Reference
< XNameAccess
> xLib
=
857 createLibraryLink( aLibName
, rLib
.aStorageURL
, rLib
.bReadOnly
);
858 pImplLib
= static_cast< SfxLibrary
* >( xLib
.get() );
862 Reference
< XNameContainer
> xLib
= createLibrary( aLibName
);
863 pImplLib
= static_cast< SfxLibrary
* >( xLib
.get() );
864 pImplLib
->mbLoaded
= sal_False
;
865 pImplLib
->mbReadOnly
= rLib
.bReadOnly
;
867 checkStorageURL( rLib
.aStorageURL
, pImplLib
->maLibInfoFileURL
,
868 pImplLib
->maStorageURL
, pImplLib
->maUnexpandedStorageURL
);
870 maModifiable
.setModified( sal_False
);
872 // Read library info files
873 if( !mbOldInfoFormat
)
875 uno::Reference
< embed::XStorage
> xLibraryStor
;
876 if( !pImplLib
->mbInitialised
&& bStorage
)
879 xLibraryStor
= xLibrariesStor
->openStorageElement( rLib
.aName
,
880 embed::ElementModes::READ
);
882 catch( uno::Exception
& )
884 #if OSL_DEBUG_LEVEL > 0
885 Any
aError( ::cppu::getCaughtException() );
886 ::rtl::OStringBuffer aMessage
;
887 aMessage
.append( "couln't open sub storage for library '" );
888 aMessage
.append( ::rtl::OUStringToOString( rLib
.aName
, osl_getThreadTextEncoding() ) );
889 aMessage
.append( "'.\n\nException:" );
890 aMessage
.append( ::rtl::OUStringToOString( ::comphelper::anyToString( aError
), osl_getThreadTextEncoding() ) );
891 OSL_ENSURE( false, aMessage
.makeStringAndClear().getStr() );
896 // Link is already initialised in createLibraryLink()
897 if( !pImplLib
->mbInitialised
&& (!bStorage
|| xLibraryStor
.is()) )
899 OUString aIndexFileName
;
900 sal_Bool bLoaded
= implLoadLibraryIndexFile( pImplLib
, rLib
, xLibraryStor
, aIndexFileName
);
901 if( bLoaded
&& aLibName
!= rLib
.aName
)
903 OSL_ENSURE( 0, "Different library names in library"
904 " container and library info files!\n" );
906 if( GbMigrationSuppressErrors
&& !bLoaded
)
907 removeLibrary( aLibName
);
912 // Write new index file immediately because otherwise
913 // the library elements will be lost when storing into
914 // the new info format
915 uno::Reference
< embed::XStorage
> xTmpStorage
;
916 implStoreLibraryIndexFile( pImplLib
, rLib
, xTmpStorage
);
919 implImportLibDescriptor( pImplLib
, rLib
);
923 pImplLib
->mbSharedIndexFile
= sal_True
;
924 pImplLib
->mbReadOnly
= sal_True
;
928 // Keep flag for documents to force writing the new index files
930 mbOldInfoFormat
= sal_False
;
934 // Only in the first pass it's an error when no index file is found
935 else if( nPass
== 0 )
941 // #110009: END Scope to force the StorageRefs to be destructed
945 if( !bStorage
&& meInitMode
== DEFAULT
)
946 implScanExtensions();
950 Sequence
< OUString
> aNames
= maNameContainer
.getElementNames();
951 const OUString
* pNames
= aNames
.getConstArray();
952 sal_Int32 nNameCount
= aNames
.getLength();
953 for( sal_Int32 i
= 0 ; i
< nNameCount
; i
++ )
955 OUString aName
= pNames
[ i
];
956 SfxLibrary
* pImplLib
= getImplLib( aName
);
957 if( pImplLib
->mbPreload
)
958 loadLibrary( aName
);
962 // #118803# upgrade installation 7.0 -> 8.0
963 if( meInitMode
== DEFAULT
)
965 INetURLObject
aUserBasicInetObj( String(maLibraryPath
).GetToken(1) );
966 OUString
aStandardStr( RTL_CONSTASCII_USTRINGPARAM("Standard") );
968 static char strPrevFolderName_1
[] = "__basic_80";
969 static char strPrevFolderName_2
[] = "__basic_80_2";
970 INetURLObject
aPrevUserBasicInetObj_1( aUserBasicInetObj
);
971 aPrevUserBasicInetObj_1
.removeSegment();
972 INetURLObject aPrevUserBasicInetObj_2
= aPrevUserBasicInetObj_1
;
973 aPrevUserBasicInetObj_1
.Append( strPrevFolderName_1
);
974 aPrevUserBasicInetObj_2
.Append( strPrevFolderName_2
);
977 bool bCleanUp
= false;
980 INetURLObject aPrevUserBasicInetObj
= aPrevUserBasicInetObj_1
;
981 String aPrevFolder
= aPrevUserBasicInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
982 bool bSecondTime
= false;
983 if( mxSFI
->isFolder( aPrevFolder
) )
985 // #110101 Check if Standard folder exists and is complete
986 INetURLObject
aUserBasicStandardInetObj( aUserBasicInetObj
);
987 aUserBasicStandardInetObj
.insertName( aStandardStr
, sal_True
, INetURLObject::LAST_SEGMENT
,
988 sal_True
, INetURLObject::ENCODE_ALL
);
989 INetURLObject
aPrevUserBasicStandardInetObj( aPrevUserBasicInetObj
);
990 aPrevUserBasicStandardInetObj
.insertName( aStandardStr
, sal_True
, INetURLObject::LAST_SEGMENT
,
991 sal_True
, INetURLObject::ENCODE_ALL
);
992 OUString aPrevStandardFolder
= aPrevUserBasicStandardInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
993 if( mxSFI
->isFolder( aPrevStandardFolder
) )
995 OUString
aXlbExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xlb") ) );
996 OUString aCheckFileName
;
998 // Check if script.xlb exists
999 aCheckFileName
= OUString( RTL_CONSTASCII_USTRINGPARAM("script") );
1000 checkAndCopyFileImpl( aUserBasicStandardInetObj
,
1001 aPrevUserBasicStandardInetObj
,
1002 aCheckFileName
, aXlbExtension
, mxSFI
);
1004 // Check if dialog.xlb exists
1005 aCheckFileName
= OUString( RTL_CONSTASCII_USTRINGPARAM("dialog") );
1006 checkAndCopyFileImpl( aUserBasicStandardInetObj
,
1007 aPrevUserBasicStandardInetObj
,
1008 aCheckFileName
, aXlbExtension
, mxSFI
);
1010 // Check if module1.xba exists
1011 OUString
aXbaExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xba") ) );
1012 aCheckFileName
= OUString( RTL_CONSTASCII_USTRINGPARAM("Module1") );
1013 checkAndCopyFileImpl( aUserBasicStandardInetObj
,
1014 aPrevUserBasicStandardInetObj
,
1015 aCheckFileName
, aXbaExtension
, mxSFI
);
1019 String aStandardFolder
= aUserBasicStandardInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
1020 mxSFI
->copy( aStandardFolder
, aPrevStandardFolder
);
1023 String aPrevCopyToFolder
= aPrevUserBasicInetObj_2
.GetMainURL( INetURLObject::NO_DECODE
);
1024 mxSFI
->copy( aPrevFolder
, aPrevCopyToFolder
);
1029 aPrevUserBasicInetObj
= aPrevUserBasicInetObj_2
;
1030 aPrevFolder
= aPrevUserBasicInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
1032 if( mxSFI
->isFolder( aPrevFolder
) )
1034 SfxLibraryContainer
* pPrevCont
= createInstanceImpl();
1035 Reference
< XInterface
> xRef
= static_cast< XInterface
* >( static_cast< OWeakObject
* >(pPrevCont
) );
1037 // Rename previous basic folder to make storage URLs correct during initialisation
1038 String aFolderUserBasic
= aUserBasicInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
1039 INetURLObject
aUserBasicTmpInetObj( aUserBasicInetObj
);
1040 aUserBasicTmpInetObj
.removeSegment();
1041 aUserBasicTmpInetObj
.Append( "__basic_tmp" );
1042 String aFolderTmp
= aUserBasicTmpInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
1044 mxSFI
->move( aFolderUserBasic
, aFolderTmp
);
1047 mxSFI
->move( aPrevFolder
, aFolderUserBasic
);
1051 // Move back user/basic folder
1054 mxSFI
->kill( aFolderUserBasic
);
1058 mxSFI
->move( aFolderTmp
, aFolderUserBasic
);
1062 INetURLObject
aPrevUserBasicLibInfoInetObj( aUserBasicInetObj
);
1063 aPrevUserBasicLibInfoInetObj
.insertName( maInfoFileName
, sal_True
, INetURLObject::LAST_SEGMENT
,
1064 sal_True
, INetURLObject::ENCODE_ALL
);
1065 aPrevUserBasicLibInfoInetObj
.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xlc") ) );
1066 OUString aLibInfoFileName
= aPrevUserBasicLibInfoInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
1067 Sequence
<Any
> aInitSeq( 1 );
1068 aInitSeq
.getArray()[0] <<= aLibInfoFileName
;
1069 GbMigrationSuppressErrors
= true;
1070 pPrevCont
->initialize( aInitSeq
);
1071 GbMigrationSuppressErrors
= false;
1073 // Rename folders back
1074 mxSFI
->move( aFolderUserBasic
, aPrevFolder
);
1075 mxSFI
->move( aFolderTmp
, aFolderUserBasic
);
1077 OUString aUserSearchStr
= OUString::createFromAscii( "vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE" );
1078 OUString aSharedSearchStr
= OUString::createFromAscii( "vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE" );
1079 OUString aInstSearchStr
= OUString::createFromAscii( "$(INST)" );
1081 Sequence
< OUString
> aNames
= pPrevCont
->getElementNames();
1082 const OUString
* pNames
= aNames
.getConstArray();
1083 sal_Int32 nNameCount
= aNames
.getLength();
1085 for( sal_Int32 i
= 0 ; i
< nNameCount
; i
++ )
1087 OUString aLibName
= pNames
[ i
];
1088 if( hasByName( aLibName
) )
1090 if( aLibName
== aStandardStr
)
1092 SfxLibrary
* pImplLib
= getImplLib( aStandardStr
);
1093 INetURLObject
aStandardFolderInetObj( pImplLib
->maStorageURL
);
1094 String aStandardFolder
= pImplLib
->maStorageURL
;
1095 mxSFI
->kill( aStandardFolder
);
1103 SfxLibrary
* pImplLib
= pPrevCont
->getImplLib( aLibName
);
1104 if( pImplLib
->mbLink
)
1106 OUString aStorageURL
= pImplLib
->maUnexpandedStorageURL
;
1107 bool bCreateLink
= true;
1108 if( aStorageURL
.indexOf( aUserSearchStr
) != -1 ||
1109 aStorageURL
.indexOf( aSharedSearchStr
) != -1 ||
1110 aStorageURL
.indexOf( aInstSearchStr
) != -1 )
1112 bCreateLink
= false;
1115 createLibraryLink( aLibName
, pImplLib
->maStorageURL
, pImplLib
->mbReadOnly
);
1119 // Move folder if not already done
1120 INetURLObject
aUserBasicLibFolderInetObj( aUserBasicInetObj
);
1121 aUserBasicLibFolderInetObj
.Append( aLibName
);
1122 String aLibFolder
= aUserBasicLibFolderInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
1124 INetURLObject
aPrevUserBasicLibFolderInetObj( aPrevUserBasicInetObj
);
1125 aPrevUserBasicLibFolderInetObj
.Append( aLibName
);
1126 String aPrevLibFolder
= aPrevUserBasicLibFolderInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
1128 if( mxSFI
->isFolder( aPrevLibFolder
) && !mxSFI
->isFolder( aLibFolder
) )
1129 mxSFI
->move( aPrevLibFolder
, aLibFolder
);
1131 if( aLibName
== aStandardStr
)
1132 maNameContainer
.removeByName( aLibName
);
1135 Reference
< XNameContainer
> xLib
= createLibrary( aLibName
);
1136 SfxLibrary
* pNewLib
= static_cast< SfxLibrary
* >( xLib
.get() );
1137 pNewLib
->mbLoaded
= false;
1138 pNewLib
->implSetModified( sal_False
);
1139 checkStorageURL( aLibFolder
, pNewLib
->maLibInfoFileURL
,
1140 pNewLib
->maStorageURL
, pNewLib
->maUnexpandedStorageURL
);
1142 uno::Reference
< embed::XStorage
> xDummyStor
;
1143 ::xmlscript::LibDescriptor aLibDesc
;
1144 /*sal_Bool bReadIndexFile =*/ implLoadLibraryIndexFile
1145 ( pNewLib
, aLibDesc
, xDummyStor
, pNewLib
->maLibInfoFileURL
);
1146 implImportLibDescriptor( pNewLib
, aLibDesc
);
1149 mxSFI
->kill( aPrevFolder
);
1160 DBG_ERROR( "Upgrade of Basic installation failed somehow" );
1162 static char strErrorSavFolderName
[] = "__basic_80_err";
1163 INetURLObject
aPrevUserBasicInetObj_Err( aUserBasicInetObj
);
1164 aPrevUserBasicInetObj_Err
.removeSegment();
1165 aPrevUserBasicInetObj_Err
.Append( strErrorSavFolderName
);
1166 String aPrevFolder_Err
= aPrevUserBasicInetObj_Err
.GetMainURL( INetURLObject::NO_DECODE
);
1168 bool bSaved
= false;
1171 String aPrevFolder_1
= aPrevUserBasicInetObj_1
.GetMainURL( INetURLObject::NO_DECODE
);
1172 if( mxSFI
->isFolder( aPrevFolder_1
) )
1174 mxSFI
->move( aPrevFolder_1
, aPrevFolder_Err
);
1182 String aPrevFolder_2
= aPrevUserBasicInetObj_2
.GetMainURL( INetURLObject::NO_DECODE
);
1183 if( !bSaved
&& mxSFI
->isFolder( aPrevFolder_2
) )
1184 mxSFI
->move( aPrevFolder_2
, aPrevFolder_Err
);
1186 mxSFI
->kill( aPrevFolder_2
);
1196 void SfxLibraryContainer::implScanExtensions( void )
1198 ScriptExtensionIterator aScriptIt
;
1199 rtl::OUString aLibURL
;
1201 bool bPureDialogLib
= false;
1202 while( (aLibURL
= aScriptIt
.nextBasicOrDialogLibrary( bPureDialogLib
)).getLength() > 0 )
1204 if( bPureDialogLib
&& maInfoFileName
.equalsAscii( "script" ) )
1208 sal_Int32 nLen
= aLibURL
.getLength();
1209 sal_Int32 indexLastSlash
= aLibURL
.lastIndexOf( '/' );
1210 sal_Int32 nReduceCopy
= 0;
1211 if( indexLastSlash
== nLen
- 1 )
1214 indexLastSlash
= aLibURL
.lastIndexOf( '/', nLen
- 1 );
1217 OUString aLibName
= aLibURL
.copy( indexLastSlash
+ 1, nLen
- indexLastSlash
- nReduceCopy
- 1 );
1219 // If a library of the same exists the existing library wins
1220 if( hasByName( aLibName
) )
1223 // Add index file to URL
1224 OUString aIndexFileURL
= aLibURL
;
1225 if( nReduceCopy
== 0 )
1226 aIndexFileURL
+= OUString::createFromAscii( "/" );
1227 aIndexFileURL
+= maInfoFileName
;
1228 aIndexFileURL
+= OUString::createFromAscii( ".xlb" );
1231 const bool bReadOnly
= false;
1232 Reference
< XNameAccess
> xLib
=
1233 createLibraryLink( aLibName
, aIndexFileURL
, bReadOnly
);
1237 // Handle maLibInfoFileURL and maStorageURL correctly
1238 void SfxLibraryContainer::checkStorageURL( const OUString
& aSourceURL
,
1239 OUString
& aLibInfoFileURL
, OUString
& aStorageURL
, OUString
& aUnexpandedStorageURL
)
1241 OUString aExpandedSourceURL
= expand_url( aSourceURL
);
1242 if( aExpandedSourceURL
!= aSourceURL
)
1243 aUnexpandedStorageURL
= aSourceURL
;
1245 INetURLObject
aInetObj( aExpandedSourceURL
);
1246 OUString aExtension
= aInetObj
.getExtension();
1247 if( aExtension
.compareToAscii( "xlb" ) == COMPARE_EQUAL
)
1250 aLibInfoFileURL
= aExpandedSourceURL
;
1251 aInetObj
.removeSegment();
1252 aStorageURL
= aInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
1256 // URL to library folder
1257 aStorageURL
= aExpandedSourceURL
;
1258 aInetObj
.insertName( maInfoFileName
, sal_True
, INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
1259 aInetObj
.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xlb") ) );
1260 aLibInfoFileURL
= aInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
1264 SfxLibrary
* SfxLibraryContainer::getImplLib( const String
& rLibraryName
)
1266 Any aLibAny
= maNameContainer
.getByName( rLibraryName
) ;
1267 Reference
< XNameAccess
> xNameAccess
;
1268 aLibAny
>>= xNameAccess
;
1269 SfxLibrary
* pImplLib
= static_cast< SfxLibrary
* >( xNameAccess
.get() );
1274 // Storing with password encryption
1276 // Empty implementation, avoids unneccesary implementation in dlgcont.cxx
1277 sal_Bool
SfxLibraryContainer::implStorePasswordLibrary(
1280 const uno::Reference
< embed::XStorage
>&, const uno::Reference
< task::XInteractionHandler
>& )
1285 sal_Bool
SfxLibraryContainer::implStorePasswordLibrary(
1286 SfxLibrary
* /*pLib*/,
1287 const ::rtl::OUString
& /*aName*/,
1288 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& /*xStorage*/,
1289 const ::rtl::OUString
& /*aTargetURL*/,
1290 const Reference
< XSimpleFileAccess
> /*xToUseSFI*/,
1291 const uno::Reference
< task::XInteractionHandler
>& )
1296 sal_Bool
SfxLibraryContainer::implLoadPasswordLibrary(
1297 SfxLibrary
* /*pLib*/,
1298 const OUString
& /*Name*/,
1299 sal_Bool
/*bVerifyPasswordOnly*/ )
1300 throw(WrappedTargetException
, RuntimeException
)
1307 #define EXPAND_PROTOCOL "vnd.sun.star.expand"
1308 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
1310 OUString
SfxLibraryContainer::createAppLibraryFolder
1311 ( SfxLibrary
* pLib
, const OUString
& aName
)
1313 OUString aLibDirPath
= pLib
->maStorageURL
;
1314 if( !aLibDirPath
.getLength() )
1316 INetURLObject
aInetObj( String(maLibraryPath
).GetToken(1) );
1317 aInetObj
.insertName( aName
, sal_True
, INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
1318 checkStorageURL( aInetObj
.GetMainURL( INetURLObject::NO_DECODE
), pLib
->maLibInfoFileURL
,
1319 pLib
->maStorageURL
, pLib
->maUnexpandedStorageURL
);
1320 aLibDirPath
= pLib
->maStorageURL
;
1323 if( !mxSFI
->isFolder( aLibDirPath
) )
1327 mxSFI
->createFolder( aLibDirPath
);
1337 void SfxLibraryContainer::implStoreLibrary( SfxLibrary
* pLib
,
1338 const OUString
& aName
, const uno::Reference
< embed::XStorage
>& xStorage
)
1340 OUString aDummyLocation
;
1341 Reference
< XSimpleFileAccess
> xDummySFA
;
1342 Reference
< XInteractionHandler
> xDummyHandler
;
1343 implStoreLibrary( pLib
, aName
, xStorage
, aDummyLocation
, xDummySFA
, xDummyHandler
);
1346 // New variant for library export
1347 void SfxLibraryContainer::implStoreLibrary( SfxLibrary
* pLib
,
1348 const OUString
& aName
, const uno::Reference
< embed::XStorage
>& xStorage
,
1349 const ::rtl::OUString
& aTargetURL
, Reference
< XSimpleFileAccess
> xToUseSFI
,
1350 const Reference
< XInteractionHandler
>& xHandler
)
1352 sal_Bool bLink
= pLib
->mbLink
;
1353 sal_Bool bStorage
= xStorage
.is() && !bLink
;
1355 Sequence
< OUString
> aElementNames
= pLib
->getElementNames();
1356 sal_Int32 nNameCount
= aElementNames
.getLength();
1357 const OUString
* pNames
= aElementNames
.getConstArray();
1361 for( sal_Int32 i
= 0 ; i
< nNameCount
; i
++ )
1363 OUString aElementName
= pNames
[ i
];
1365 OUString aStreamName
= aElementName
;
1366 aStreamName
+= String( RTL_CONSTASCII_USTRINGPARAM(".xml") );
1368 Any aElement
= pLib
->getByName( aElementName
);
1369 if( !isLibraryElementValid( aElement
) )
1371 #if OSL_DEBUG_LEVEL > 0
1372 ::rtl::OStringBuffer aMessage
;
1373 aMessage
.append( "invalid library element '" );
1374 aMessage
.append( ::rtl::OUStringToOString( aElementName
, osl_getThreadTextEncoding() ) );
1375 aMessage
.append( "'." );
1376 OSL_ENSURE( false, aMessage
.makeStringAndClear().getStr() );
1381 uno::Reference
< io::XStream
> xElementStream
= xStorage
->openStreamElement(
1383 embed::ElementModes::READWRITE
);
1384 //if ( !xElementStream.is() )
1385 // throw uno::RuntimeException(); // TODO: method must either return the stream or throw an exception
1387 String
aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) );
1388 OUString
aMime( RTL_CONSTASCII_USTRINGPARAM("text/xml") );
1390 uno::Reference
< beans::XPropertySet
> xProps( xElementStream
, uno::UNO_QUERY
);
1391 OSL_ENSURE( xProps
.is(), "The StorageStream must implement XPropertySet interface!\n" );
1392 //if ( !xProps.is() ) //TODO
1393 // throw uno::RuntimeException();
1397 xProps
->setPropertyValue( aPropName
, uno::makeAny( aMime
) );
1399 // #87671 Allow encryption
1400 //REMOVE aPropName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("Encrypted") );
1401 aPropName
= String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) );
1402 xProps
->setPropertyValue( aPropName
, uno::makeAny( sal_True
) );
1404 Reference
< XOutputStream
> xOutput
= xElementStream
->getOutputStream();
1405 writeLibraryElement( aElement
, aElementName
, xOutput
);
1406 // writeLibraryElement closes the stream
1407 // xOutput->closeOutput();
1410 catch( uno::Exception
& )
1412 OSL_ENSURE( sal_False
, "Problem during storing of library!\n" );
1413 // TODO: error handling?
1417 pLib
->storeResourcesToStorage( xStorage
);
1422 bool bExport
= aTargetURL
.getLength();
1425 Reference
< XSimpleFileAccess
> xSFI
= mxSFI
;
1426 if( xToUseSFI
.is() )
1429 OUString aLibDirPath
;
1432 INetURLObject
aInetObj( aTargetURL
);
1433 aInetObj
.insertName( aName
, sal_True
, INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
1434 aLibDirPath
= aInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
1436 if( !xSFI
->isFolder( aLibDirPath
) )
1437 xSFI
->createFolder( aLibDirPath
);
1439 pLib
->storeResourcesToURL( aLibDirPath
, xHandler
);
1443 aLibDirPath
= createAppLibraryFolder( pLib
, aName
);
1444 pLib
->storeResources();
1447 for( sal_Int32 i
= 0 ; i
< nNameCount
; i
++ )
1449 OUString aElementName
= pNames
[ i
];
1451 INetURLObject
aElementInetObj( aLibDirPath
);
1452 aElementInetObj
.insertName( aElementName
, sal_False
,
1453 INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
1454 aElementInetObj
.setExtension( maLibElementFileExtension
);
1455 String
aElementPath( aElementInetObj
.GetMainURL( INetURLObject::NO_DECODE
) );
1457 Any aElement
= pLib
->getByName( aElementName
);
1458 if( !isLibraryElementValid( aElement
) )
1460 #if OSL_DEBUG_LEVEL > 0
1461 ::rtl::OStringBuffer aMessage
;
1462 aMessage
.append( "invalid library element '" );
1463 aMessage
.append( ::rtl::OUStringToOString( aElementName
, osl_getThreadTextEncoding() ) );
1464 aMessage
.append( "'." );
1465 OSL_ENSURE( false, aMessage
.makeStringAndClear().getStr() );
1470 // TODO: Check modified
1473 if( xSFI
->exists( aElementPath
) )
1474 xSFI
->kill( aElementPath
);
1475 Reference
< XOutputStream
> xOutput
= xSFI
->openFileWrite( aElementPath
);
1476 writeLibraryElement( aElement
, aElementName
, xOutput
);
1477 xOutput
->closeOutput();
1484 SfxErrorContext
aEc( ERRCTX_SFX_SAVEDOC
, aElementPath
);
1485 ULONG nErrorCode
= ERRCODE_IO_GENERAL
;
1486 ErrorHandler::HandleError( nErrorCode
);
1498 void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary
* pLib
,
1499 const ::xmlscript::LibDescriptor
& rLib
, const uno::Reference
< embed::XStorage
>& xStorage
)
1501 OUString aDummyLocation
;
1502 Reference
< XSimpleFileAccess
> xDummySFA
;
1503 implStoreLibraryIndexFile( pLib
, rLib
, xStorage
, aDummyLocation
, xDummySFA
);
1506 // New variant for library export
1507 void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary
* pLib
,
1508 const ::xmlscript::LibDescriptor
& rLib
, const uno::Reference
< embed::XStorage
>& xStorage
,
1509 const ::rtl::OUString
& aTargetURL
, Reference
< XSimpleFileAccess
> xToUseSFI
)
1511 // Create sax writer
1512 Reference
< XExtendedDocumentHandler
> xHandler(
1513 mxMSF
->createInstance(
1514 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer") ) ), UNO_QUERY
);
1515 if( !xHandler
.is() )
1517 OSL_ENSURE( 0, "### couln't create sax-writer component\n" );
1521 sal_Bool bLink
= pLib
->mbLink
;
1522 sal_Bool bStorage
= xStorage
.is() && !bLink
;
1525 uno::Reference
< io::XOutputStream
> xOut
;
1526 uno::Reference
< io::XStream
> xInfoStream
;
1529 OUString
aStreamName( maInfoFileName
);
1530 aStreamName
+= String( RTL_CONSTASCII_USTRINGPARAM("-lb.xml") );
1533 xInfoStream
= xStorage
->openStreamElement( aStreamName
, embed::ElementModes::READWRITE
);
1534 OSL_ENSURE( xInfoStream
.is(), "No stream!\n" );
1535 uno::Reference
< beans::XPropertySet
> xProps( xInfoStream
, uno::UNO_QUERY
);
1536 //if ( !xProps.is() )
1537 // throw uno::RuntimeException(); // TODO
1541 String
aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) );
1542 OUString
aMime( RTL_CONSTASCII_USTRINGPARAM("text/xml") );
1543 xProps
->setPropertyValue( aPropName
, uno::makeAny( aMime
) );
1545 // #87671 Allow encryption
1546 //REMOVE aPropName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("Encrypted") );
1547 aPropName
= String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) );
1548 xProps
->setPropertyValue( aPropName
, uno::makeAny( sal_True
) );
1550 xOut
= xInfoStream
->getOutputStream();
1553 catch( uno::Exception
& )
1555 OSL_ENSURE( sal_False
, "Problem during storing of library index file!\n" );
1556 // TODO: error handling?
1562 bool bExport
= aTargetURL
.getLength();
1563 Reference
< XSimpleFileAccess
> xSFI
= mxSFI
;
1564 if( xToUseSFI
.is() )
1567 OUString aLibInfoPath
;
1570 INetURLObject
aInetObj( aTargetURL
);
1571 aInetObj
.insertName( rLib
.aName
, sal_True
, INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
1572 OUString aLibDirPath
= aInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
1573 if( !xSFI
->isFolder( aLibDirPath
) )
1574 xSFI
->createFolder( aLibDirPath
);
1576 aInetObj
.insertName( maInfoFileName
, sal_True
, INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
1577 aInetObj
.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xlb") ) );
1578 aLibInfoPath
= aInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
1582 createAppLibraryFolder( pLib
, rLib
.aName
);
1583 aLibInfoPath
= pLib
->maLibInfoFileURL
;
1588 if( xSFI
->exists( aLibInfoPath
) )
1589 xSFI
->kill( aLibInfoPath
);
1590 xOut
= xSFI
->openFileWrite( aLibInfoPath
);
1597 SfxErrorContext
aEc( ERRCTX_SFX_SAVEDOC
, aLibInfoPath
);
1598 ULONG nErrorCode
= ERRCODE_IO_GENERAL
;
1599 ErrorHandler::HandleError( nErrorCode
);
1604 OSL_ENSURE( 0, "### couln't open output stream\n" );
1608 Reference
< XActiveDataSource
> xSource( xHandler
, UNO_QUERY
);
1609 xSource
->setOutputStream( xOut
);
1611 xmlscript::exportLibrary( xHandler
, rLib
);
1615 sal_Bool
SfxLibraryContainer::implLoadLibraryIndexFile( SfxLibrary
* pLib
,
1616 ::xmlscript::LibDescriptor
& rLib
, const uno::Reference
< embed::XStorage
>& xStorage
, const OUString
& aIndexFileName
)
1618 Reference
< XParser
> xParser( mxMSF
->createInstance(
1619 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ) ), UNO_QUERY
);
1622 OSL_ENSURE( 0, "### couln't create sax parser component\n" );
1626 sal_Bool bLink
= sal_False
;
1627 sal_Bool bStorage
= sal_False
;
1630 bLink
= pLib
->mbLink
;
1631 bStorage
= xStorage
.is() && !bLink
;
1635 uno::Reference
< io::XInputStream
> xInput
;
1636 String aLibInfoPath
;
1639 aLibInfoPath
= maInfoFileName
;
1640 aLibInfoPath
+= String( RTL_CONSTASCII_USTRINGPARAM("-lb.xml") );
1643 uno::Reference
< io::XStream
> xInfoStream
=
1644 xStorage
->openStreamElement( aLibInfoPath
, embed::ElementModes::READ
);
1645 xInput
= xInfoStream
->getInputStream();
1647 catch( uno::Exception
& )
1652 // Create Input stream
1653 //String aLibInfoPath; // attention: THIS PROBLEM MUST BE REVIEWED BY SCRIPTING OWNER!!!
1657 createAppLibraryFolder( pLib
, rLib
.aName
);
1658 aLibInfoPath
= pLib
->maLibInfoFileURL
;
1661 aLibInfoPath
= aIndexFileName
;
1665 xInput
= mxSFI
->openFileRead( aLibInfoPath
);
1670 if( !GbMigrationSuppressErrors
)
1672 SfxErrorContext
aEc( ERRCTX_SFX_LOADBASIC
, aLibInfoPath
);
1673 ULONG nErrorCode
= ERRCODE_IO_GENERAL
;
1674 ErrorHandler::HandleError( nErrorCode
);
1680 // OSL_ENSURE( 0, "### couln't open input stream\n" );
1685 source
.aInputStream
= xInput
;
1686 source
.sSystemId
= aLibInfoPath
;
1690 xParser
->setDocumentHandler( ::xmlscript::importLibrary( rLib
) );
1691 xParser
->parseStream( source
);
1695 // throw WrappedTargetException( OUString::createFromAscii( "parsing error!\n" ),
1696 // Reference< XInterface >(),
1698 OSL_ENSURE( 0, "Parsing error\n" );
1699 SfxErrorContext
aEc( ERRCTX_SFX_LOADBASIC
, aLibInfoPath
);
1700 ULONG nErrorCode
= ERRCODE_IO_GENERAL
;
1701 ErrorHandler::HandleError( nErrorCode
);
1707 Reference
< XNameContainer
> xLib
= createLibrary( rLib
.aName
);
1708 pLib
= static_cast< SfxLibrary
* >( xLib
.get() );
1709 pLib
->mbLoaded
= sal_False
;
1710 rLib
.aStorageURL
= aIndexFileName
;
1711 checkStorageURL( rLib
.aStorageURL
, pLib
->maLibInfoFileURL
, pLib
->maStorageURL
,
1712 pLib
->maUnexpandedStorageURL
);
1714 implImportLibDescriptor( pLib
, rLib
);
1720 void SfxLibraryContainer::implImportLibDescriptor
1721 ( SfxLibrary
* pLib
, ::xmlscript::LibDescriptor
& rLib
)
1723 if( !pLib
->mbInitialised
)
1725 sal_Int32 nElementCount
= rLib
.aElementNames
.getLength();
1726 const OUString
* pElementNames
= rLib
.aElementNames
.getConstArray();
1727 Any aDummyElement
= createEmptyLibraryElement();
1728 for( sal_Int32 i
= 0 ; i
< nElementCount
; i
++ )
1730 pLib
->maNameContainer
.insertByName( pElementNames
[i
], aDummyElement
);
1732 pLib
->mbPasswordProtected
= rLib
.bPasswordProtected
;
1733 pLib
->mbReadOnly
= rLib
.bReadOnly
;
1734 pLib
->mbPreload
= rLib
.bPreload
;
1735 pLib
->implSetModified( sal_False
);
1737 pLib
->mbInitialised
= sal_True
;
1742 // Methods of new XLibraryStorage interface?
1743 void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference
< embed::XStorage
>& xStorage
, sal_Bool bComplete
)
1745 const Sequence
< OUString
> aNames
= maNameContainer
.getElementNames();
1746 sal_Int32 nNameCount
= aNames
.getLength();
1747 const OUString
* pName
= aNames
.getConstArray();
1748 const OUString
* pNamesEnd
= aNames
.getConstArray() + nNameCount
;
1750 // Don't count libs from shared index file
1751 sal_Int32 nLibsToSave
= nNameCount
;
1752 for( ; pName
!= pNamesEnd
; ++pName
)
1754 SfxLibrary
* pImplLib
= getImplLib( *pName
);
1755 if( pImplLib
->mbSharedIndexFile
|| pImplLib
->mbExtension
)
1761 ::xmlscript::LibDescriptorArray
* pLibArray
= new ::xmlscript::LibDescriptorArray( nLibsToSave
);
1763 // Write to storage?
1764 sal_Bool bStorage
= xStorage
.is();
1765 uno::Reference
< embed::XStorage
> xLibrariesStor
;
1766 uno::Reference
< embed::XStorage
> xSourceLibrariesStor
;
1769 // when we save to our root storage, ensure the libs are all loaded. Else the below cleaning
1770 // of the target storage will loose them.
1771 if ( xStorage
== mxStorage
)
1773 pName
= aNames
.getConstArray();
1774 for ( ; pName
!= pNamesEnd
; ++pName
)
1776 if ( !isLibraryLoaded( *pName
) )
1777 loadLibrary( *pName
);
1781 // first of all, clean the target library storage, since the storing procedure must do overwrite
1784 if ( xStorage
->hasByName( maLibrariesDir
) )
1785 xStorage
->removeElement( maLibrariesDir
);
1787 catch( const uno::Exception
& )
1789 DBG_UNHANDLED_EXCEPTION();
1793 // Don't write if only empty standard lib exists
1794 if ( ( nNameCount
== 1 ) && ( aNames
[0].equalsAscii( "Standard" ) ) )
1796 Any aLibAny
= maNameContainer
.getByName( aNames
[0] );
1797 Reference
< XNameAccess
> xNameAccess
;
1798 aLibAny
>>= xNameAccess
;
1799 if ( !xNameAccess
->hasElements() )
1804 xLibrariesStor
.set( xStorage
->openStorageElement( maLibrariesDir
, embed::ElementModes::READWRITE
), UNO_QUERY_THROW
);
1806 catch( uno::Exception
& )
1808 #if OSL_DEBUG_LEVEL > 0
1809 Any
aError( ::cppu::getCaughtException() );
1810 ::rtl::OStringBuffer aMessage
;
1811 aMessage
.append( "couln't open source library storage.\n\nException:" );
1812 aMessage
.append( ::rtl::OUStringToOString( ::comphelper::anyToString( aError
), osl_getThreadTextEncoding() ) );
1813 OSL_ENSURE( false, aMessage
.makeStringAndClear().getStr() );
1820 if ( ( mxStorage
!= xStorage
) && ( mxStorage
->hasByName( maLibrariesDir
) ) )
1821 xSourceLibrariesStor
= mxStorage
->openStorageElement( maLibrariesDir
, embed::ElementModes::READ
);
1823 catch( const uno::Exception
& )
1825 DBG_UNHANDLED_EXCEPTION();
1830 pName
= aNames
.getConstArray();
1831 ::xmlscript::LibDescriptor aLibDescriptorForExtensionLibs
;
1832 for( ; pName
!= pNamesEnd
; ++pName
)
1834 SfxLibrary
* pImplLib
= getImplLib( *pName
);
1835 if( pImplLib
->mbSharedIndexFile
)
1837 bool bExtensionLib
= pImplLib
->mbExtension
;
1838 ::xmlscript::LibDescriptor
& rLib
= bExtensionLib
?
1839 aLibDescriptorForExtensionLibs
: pLibArray
->mpLibs
[iArray
];
1840 if( !bExtensionLib
)
1842 rLib
.aName
= *pName
;
1844 rLib
.bLink
= pImplLib
->mbLink
;
1845 if( !bStorage
|| pImplLib
->mbLink
)
1847 rLib
.aStorageURL
= ( pImplLib
->maUnexpandedStorageURL
.getLength() ) ?
1848 pImplLib
->maUnexpandedStorageURL
: pImplLib
->maLibInfoFileURL
;
1850 rLib
.bReadOnly
= pImplLib
->mbReadOnly
;
1851 rLib
.bPreload
= pImplLib
->mbPreload
;
1852 rLib
.bPasswordProtected
= pImplLib
->mbPasswordProtected
;
1853 rLib
.aElementNames
= pImplLib
->getElementNames();
1855 if( pImplLib
->implIsModified() || bComplete
)
1857 // Can we copy the storage?
1858 if( !mbOldInfoFormat
&& !pImplLib
->implIsModified() && !mbOasis2OOoFormat
&& xSourceLibrariesStor
.is() )
1861 xSourceLibrariesStor
->copyElementTo( rLib
.aName
, xLibrariesStor
, rLib
.aName
);
1862 } catch( uno::Exception
& )
1864 DBG_UNHANDLED_EXCEPTION();
1865 // TODO: error handling?
1870 uno::Reference
< embed::XStorage
> xLibraryStor
;
1875 xLibraryStor
= xLibrariesStor
->openStorageElement(
1877 embed::ElementModes::READWRITE
);
1879 catch( uno::Exception
& )
1881 #if OSL_DEBUG_LEVEL > 0
1882 Any
aError( ::cppu::getCaughtException() );
1883 ::rtl::OStringBuffer aMessage
;
1884 aMessage
.append( "couln't create sub storage for library '" );
1885 aMessage
.append( ::rtl::OUStringToOString( rLib
.aName
, osl_getThreadTextEncoding() ) );
1886 aMessage
.append( "'.\n\nException:" );
1887 aMessage
.append( ::rtl::OUStringToOString( ::comphelper::anyToString( aError
), osl_getThreadTextEncoding() ) );
1888 OSL_ENSURE( false, aMessage
.makeStringAndClear().getStr() );
1894 // Maybe lib is not loaded?!
1896 loadLibrary( rLib
.aName
);
1898 if( pImplLib
->mbPasswordProtected
)
1899 implStorePasswordLibrary( pImplLib
, rLib
.aName
, xLibraryStor
, uno::Reference
< task::XInteractionHandler
>() );
1900 // TODO: Check return value
1902 implStoreLibrary( pImplLib
, rLib
.aName
, xLibraryStor
);
1904 implStoreLibraryIndexFile( pImplLib
, rLib
, xLibraryStor
);
1908 uno::Reference
< embed::XTransactedObject
> xTransact( xLibraryStor
, uno::UNO_QUERY_THROW
);
1909 xTransact
->commit();
1911 catch( uno::Exception
& )
1913 DBG_UNHANDLED_EXCEPTION();
1914 // TODO: error handling
1919 maModifiable
.setModified( sal_True
);
1920 pImplLib
->implSetModified( sal_False
);
1923 // For container info ReadOnly refers to mbReadOnlyLink
1924 rLib
.bReadOnly
= pImplLib
->mbReadOnlyLink
;
1927 if( !mbOldInfoFormat
&& !maModifiable
.isModified() )
1929 maModifiable
.setModified( sal_False
);
1930 mbOldInfoFormat
= sal_False
;
1932 // Write library container info
1933 // Create sax writer
1934 Reference
< XExtendedDocumentHandler
> xHandler(
1935 mxMSF
->createInstance(
1936 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer") ) ), UNO_QUERY
);
1937 if( !xHandler
.is() )
1939 OSL_ENSURE( 0, "### couln't create sax-writer component\n" );
1944 uno::Reference
< io::XOutputStream
> xOut
;
1945 uno::Reference
< io::XStream
> xInfoStream
;
1948 OUString
aStreamName( maInfoFileName
);
1949 aStreamName
+= String( RTL_CONSTASCII_USTRINGPARAM("-lc.xml") );
1952 xInfoStream
= xLibrariesStor
->openStreamElement( aStreamName
, embed::ElementModes::READWRITE
);
1953 uno::Reference
< beans::XPropertySet
> xProps( xInfoStream
, uno::UNO_QUERY
);
1954 OSL_ENSURE ( xProps
.is(), "The stream must implement XPropertySet!\n" );
1956 throw uno::RuntimeException();
1958 String
aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) );
1959 OUString
aMime( RTL_CONSTASCII_USTRINGPARAM("text/xml") );
1960 xProps
->setPropertyValue( aPropName
, uno::makeAny( aMime
) );
1962 // #87671 Allow encryption
1963 aPropName
= String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("UseCommonStoragePasswordEncryption") );
1964 xProps
->setPropertyValue( aPropName
, uno::makeAny( sal_True
) );
1966 xOut
= xInfoStream
->getOutputStream();
1968 catch( uno::Exception
& )
1970 ULONG nErrorCode
= ERRCODE_IO_GENERAL
;
1971 ErrorHandler::HandleError( nErrorCode
);
1976 // Create Output stream
1977 INetURLObject
aLibInfoInetObj( String(maLibraryPath
).GetToken(1) );
1978 aLibInfoInetObj
.insertName( maInfoFileName
, sal_True
, INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
1979 aLibInfoInetObj
.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM("xlc") ) );
1980 String
aLibInfoPath( aLibInfoInetObj
.GetMainURL( INetURLObject::NO_DECODE
) );
1984 if( mxSFI
->exists( aLibInfoPath
) )
1985 mxSFI
->kill( aLibInfoPath
);
1986 xOut
= mxSFI
->openFileWrite( aLibInfoPath
);
1991 SfxErrorContext
aEc( ERRCTX_SFX_SAVEDOC
, aLibInfoPath
);
1992 ULONG nErrorCode
= ERRCODE_IO_GENERAL
;
1993 ErrorHandler::HandleError( nErrorCode
);
1999 OSL_ENSURE( 0, "### couln't open output stream\n" );
2003 Reference
< XActiveDataSource
> xSource( xHandler
, UNO_QUERY
);
2004 xSource
->setOutputStream( xOut
);
2008 xmlscript::exportLibraryContainer( xHandler
, pLibArray
);
2011 uno::Reference
< embed::XTransactedObject
> xTransact( xLibrariesStor
, uno::UNO_QUERY
);
2012 OSL_ENSURE( xTransact
.is(), "The storage must implement XTransactedObject!\n" );
2013 if ( !xTransact
.is() )
2014 throw uno::RuntimeException();
2016 xTransact
->commit();
2019 catch( uno::Exception
& )
2021 OSL_ENSURE( sal_False
, "Problem during storing of libraries!\n" );
2022 ULONG nErrorCode
= ERRCODE_IO_GENERAL
;
2023 ErrorHandler::HandleError( nErrorCode
);
2030 // Methods XElementAccess
2031 Type SAL_CALL
SfxLibraryContainer::getElementType()
2032 throw(RuntimeException
)
2034 LibraryContainerMethodGuard
aGuard( *this );
2035 return maNameContainer
.getElementType();
2038 sal_Bool
SfxLibraryContainer::hasElements()
2039 throw(RuntimeException
)
2041 LibraryContainerMethodGuard
aGuard( *this );
2042 sal_Bool bRet
= maNameContainer
.hasElements();
2046 // Methods XNameAccess
2047 Any
SfxLibraryContainer::getByName( const OUString
& aName
)
2048 throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
2050 LibraryContainerMethodGuard
aGuard( *this );
2051 Any aRetAny
= maNameContainer
.getByName( aName
) ;
2055 Sequence
< OUString
> SfxLibraryContainer::getElementNames()
2056 throw(RuntimeException
)
2058 LibraryContainerMethodGuard
aGuard( *this );
2059 return maNameContainer
.getElementNames();
2062 sal_Bool
SfxLibraryContainer::hasByName( const OUString
& aName
)
2063 throw(RuntimeException
)
2065 LibraryContainerMethodGuard
aGuard( *this );
2066 return maNameContainer
.hasByName( aName
) ;
2069 // Methods XLibraryContainer
2070 Reference
< XNameContainer
> SAL_CALL
SfxLibraryContainer::createLibrary( const OUString
& Name
)
2071 throw(IllegalArgumentException
, ElementExistException
, RuntimeException
)
2073 LibraryContainerMethodGuard
aGuard( *this );
2074 SfxLibrary
* pNewLib
= implCreateLibrary( Name
);
2075 pNewLib
->maLibElementFileExtension
= maLibElementFileExtension
;
2077 createVariableURL( pNewLib
->maUnexpandedStorageURL
, Name
, maInfoFileName
, true );
2079 Reference
< XNameAccess
> xNameAccess
= static_cast< XNameAccess
* >( pNewLib
);
2081 aElement
<<= xNameAccess
;
2082 maNameContainer
.insertByName( Name
, aElement
);
2083 maModifiable
.setModified( sal_True
);
2084 Reference
< XNameContainer
> xRet( xNameAccess
, UNO_QUERY
);
2088 Reference
< XNameAccess
> SAL_CALL
SfxLibraryContainer::createLibraryLink
2089 ( const OUString
& Name
, const OUString
& StorageURL
, sal_Bool ReadOnly
)
2090 throw(IllegalArgumentException
, ElementExistException
, RuntimeException
)
2092 LibraryContainerMethodGuard
aGuard( *this );
2093 // TODO: Check other reasons to force ReadOnly status
2098 OUString aLibInfoFileURL
;
2099 OUString aLibDirURL
;
2100 OUString aUnexpandedStorageURL
;
2101 checkStorageURL( StorageURL
, aLibInfoFileURL
, aLibDirURL
, aUnexpandedStorageURL
);
2104 SfxLibrary
* pNewLib
= implCreateLibraryLink( Name
, aLibInfoFileURL
, aLibDirURL
, ReadOnly
);
2105 pNewLib
->maLibElementFileExtension
= maLibElementFileExtension
;
2106 pNewLib
->maUnexpandedStorageURL
= aUnexpandedStorageURL
;
2108 OUString aInitFileName
;
2109 uno::Reference
< embed::XStorage
> xDummyStor
;
2110 ::xmlscript::LibDescriptor aLibDesc
;
2111 /*sal_Bool bReadIndexFile = */implLoadLibraryIndexFile( pNewLib
, aLibDesc
, xDummyStor
, aInitFileName
);
2112 implImportLibDescriptor( pNewLib
, aLibDesc
);
2114 Reference
< XNameAccess
> xRet
= static_cast< XNameAccess
* >( pNewLib
);
2117 maNameContainer
.insertByName( Name
, aElement
);
2118 maModifiable
.setModified( sal_True
);
2120 OUString aUserSearchStr
= OUString::createFromAscii( "vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE" );
2121 OUString aSharedSearchStr
= OUString::createFromAscii( "vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE" );
2122 if( StorageURL
.indexOf( aUserSearchStr
) != -1 )
2124 pNewLib
->mbExtension
= sal_True
;
2126 else if( StorageURL
.indexOf( aSharedSearchStr
) != -1 )
2128 pNewLib
->mbExtension
= sal_True
;
2129 pNewLib
->mbReadOnly
= sal_True
;
2135 void SAL_CALL
SfxLibraryContainer::removeLibrary( const OUString
& Name
)
2136 throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
2138 LibraryContainerMethodGuard
aGuard( *this );
2139 // Get and hold library before removing
2140 Any aLibAny
= maNameContainer
.getByName( Name
) ;
2141 Reference
< XNameAccess
> xNameAccess
;
2142 aLibAny
>>= xNameAccess
;
2143 SfxLibrary
* pImplLib
= static_cast< SfxLibrary
* >( xNameAccess
.get() );
2144 if( pImplLib
->mbReadOnly
&& !pImplLib
->mbLink
)
2145 throw IllegalArgumentException();
2147 // Remove from container
2148 maNameContainer
.removeByName( Name
);
2149 maModifiable
.setModified( sal_True
);
2151 // Delete library files, but not for linked libraries
2152 if( !pImplLib
->mbLink
)
2154 if( mxStorage
.is() )
2156 if( xNameAccess
->hasElements() )
2158 Sequence
< OUString
> aNames
= pImplLib
->getElementNames();
2159 sal_Int32 nNameCount
= aNames
.getLength();
2160 const OUString
* pNames
= aNames
.getConstArray();
2161 for( sal_Int32 i
= 0 ; i
< nNameCount
; ++i
, ++pNames
)
2163 pImplLib
->removeElementWithoutChecks( *pNames
, SfxLibrary::LibraryContainerAccess() );
2167 // Delete index file
2168 createAppLibraryFolder( pImplLib
, Name
);
2169 String aLibInfoPath
= pImplLib
->maLibInfoFileURL
;
2172 if( mxSFI
->exists( aLibInfoPath
) )
2173 mxSFI
->kill( aLibInfoPath
);
2175 catch( Exception
& ) {}
2177 // Delete folder if empty
2178 INetURLObject
aInetObj( String(maLibraryPath
).GetToken(1) );
2179 aInetObj
.insertName( Name
, sal_True
, INetURLObject::LAST_SEGMENT
,
2180 sal_True
, INetURLObject::ENCODE_ALL
);
2181 OUString aLibDirPath
= aInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
2185 if( mxSFI
->isFolder( aLibDirPath
) )
2187 Sequence
< OUString
> aContentSeq
= mxSFI
->getFolderContents( aLibDirPath
, true );
2188 sal_Int32 nCount
= aContentSeq
.getLength();
2190 mxSFI
->kill( aLibDirPath
);
2199 sal_Bool SAL_CALL
SfxLibraryContainer::isLibraryLoaded( const OUString
& Name
)
2200 throw(NoSuchElementException
, RuntimeException
)
2202 LibraryContainerMethodGuard
aGuard( *this );
2203 SfxLibrary
* pImplLib
= getImplLib( Name
);
2204 sal_Bool bRet
= pImplLib
->mbLoaded
;
2209 void SAL_CALL
SfxLibraryContainer::loadLibrary( const OUString
& Name
)
2210 throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
2212 LibraryContainerMethodGuard
aGuard( *this );
2213 Any aLibAny
= maNameContainer
.getByName( Name
) ;
2214 Reference
< XNameAccess
> xNameAccess
;
2215 aLibAny
>>= xNameAccess
;
2216 SfxLibrary
* pImplLib
= static_cast< SfxLibrary
* >( xNameAccess
.get() );
2218 sal_Bool bLoaded
= pImplLib
->mbLoaded
;
2219 pImplLib
->mbLoaded
= sal_True
;
2220 if( !bLoaded
&& xNameAccess
->hasElements() )
2222 if( pImplLib
->mbPasswordProtected
)
2224 implLoadPasswordLibrary( pImplLib
, Name
);
2228 sal_Bool bLink
= pImplLib
->mbLink
;
2229 sal_Bool bStorage
= mxStorage
.is() && !bLink
;
2231 uno::Reference
< embed::XStorage
> xLibrariesStor
;
2232 uno::Reference
< embed::XStorage
> xLibraryStor
;
2236 xLibrariesStor
= mxStorage
->openStorageElement( maLibrariesDir
, embed::ElementModes::READ
);
2237 OSL_ENSURE( xLibrariesStor
.is(), "The method must either throw exception or return a storage!\n" );
2238 if ( !xLibrariesStor
.is() )
2239 throw uno::RuntimeException();
2241 xLibraryStor
= xLibrariesStor
->openStorageElement( Name
, embed::ElementModes::READ
);
2242 OSL_ENSURE( xLibraryStor
.is(), "The method must either throw exception or return a storage!\n" );
2243 if ( !xLibrariesStor
.is() )
2244 throw uno::RuntimeException();
2246 catch( uno::Exception
& )
2248 #if OSL_DEBUG_LEVEL > 0
2249 Any
aError( ::cppu::getCaughtException() );
2250 ::rtl::OStringBuffer aMessage
;
2251 aMessage
.append( "couln't open sub storage for library '" );
2252 aMessage
.append( ::rtl::OUStringToOString( Name
, osl_getThreadTextEncoding() ) );
2253 aMessage
.append( "'.\n\nException:" );
2254 aMessage
.append( ::rtl::OUStringToOString( ::comphelper::anyToString( aError
), osl_getThreadTextEncoding() ) );
2255 OSL_ENSURE( false, aMessage
.makeStringAndClear().getStr() );
2261 Sequence
< OUString
> aNames
= pImplLib
->getElementNames();
2262 sal_Int32 nNameCount
= aNames
.getLength();
2263 const OUString
* pNames
= aNames
.getConstArray();
2264 for( sal_Int32 i
= 0 ; i
< nNameCount
; i
++ )
2266 OUString aElementName
= pNames
[ i
];
2269 uno::Reference
< io::XInputStream
> xInStream
;
2273 uno::Reference
< io::XStream
> xElementStream
;
2275 aFile
= aElementName
;
2276 aFile
+= String( RTL_CONSTASCII_USTRINGPARAM(".xml") );
2279 xElementStream
= xLibraryStor
->openStreamElement( aFile
, embed::ElementModes::READ
);
2280 } catch( uno::Exception
& )
2283 if( !xElementStream
.is() )
2285 // Check for EA2 document version with wrong extensions
2286 aFile
= aElementName
;
2287 aFile
+= String( RTL_CONSTASCII_USTRINGPARAM(".") );
2288 aFile
+= maLibElementFileExtension
;
2290 xElementStream
= xLibraryStor
->openStreamElement( aFile
, embed::ElementModes::READ
);
2291 } catch( uno::Exception
& )
2295 if ( xElementStream
.is() )
2296 xInStream
= xElementStream
->getInputStream();
2298 if ( !xInStream
.is() )
2300 #if OSL_DEBUG_LEVEL > 0
2301 ::rtl::OStringBuffer aMessage
;
2302 aMessage
.append( "couln't open library element stream - attempted to open library '" );
2303 aMessage
.append( ::rtl::OUStringToOString( Name
, osl_getThreadTextEncoding() ) );
2304 aMessage
.append( "'." );
2305 OSL_ENSURE( false, aMessage
.makeStringAndClear().getStr() );
2312 String aLibDirPath
= pImplLib
->maStorageURL
;
2313 INetURLObject
aElementInetObj( aLibDirPath
);
2314 aElementInetObj
.insertName( aElementName
, sal_False
,
2315 INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
2316 aElementInetObj
.setExtension( maLibElementFileExtension
);
2317 aFile
= aElementInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
2320 Any aAny
= importLibraryElement( aFile
, xInStream
);
2321 if( pImplLib
->hasByName( aElementName
) )
2323 if( aAny
.hasValue() )
2324 pImplLib
->maNameContainer
.replaceByName( aElementName
, aAny
);
2328 pImplLib
->maNameContainer
.insertByName( aElementName
, aAny
);
2332 pImplLib
->implSetModified( sal_False
);
2336 // Methods XLibraryContainer2
2337 sal_Bool SAL_CALL
SfxLibraryContainer::isLibraryLink( const OUString
& Name
)
2338 throw (NoSuchElementException
, RuntimeException
)
2340 LibraryContainerMethodGuard
aGuard( *this );
2341 SfxLibrary
* pImplLib
= getImplLib( Name
);
2342 sal_Bool bRet
= pImplLib
->mbLink
;
2346 OUString SAL_CALL
SfxLibraryContainer::getLibraryLinkURL( const OUString
& Name
)
2347 throw (IllegalArgumentException
, NoSuchElementException
, RuntimeException
)
2349 LibraryContainerMethodGuard
aGuard( *this );
2350 SfxLibrary
* pImplLib
= getImplLib( Name
);
2351 sal_Bool bLink
= pImplLib
->mbLink
;
2353 throw IllegalArgumentException();
2354 OUString aRetStr
= pImplLib
->maLibInfoFileURL
;
2358 sal_Bool SAL_CALL
SfxLibraryContainer::isLibraryReadOnly( const OUString
& Name
)
2359 throw (NoSuchElementException
, RuntimeException
)
2361 LibraryContainerMethodGuard
aGuard( *this );
2362 SfxLibrary
* pImplLib
= getImplLib( Name
);
2363 sal_Bool bRet
= pImplLib
->mbReadOnly
|| (pImplLib
->mbLink
&& pImplLib
->mbReadOnlyLink
);
2367 void SAL_CALL
SfxLibraryContainer::setLibraryReadOnly( const OUString
& Name
, sal_Bool bReadOnly
)
2368 throw (NoSuchElementException
, RuntimeException
)
2370 LibraryContainerMethodGuard
aGuard( *this );
2371 SfxLibrary
* pImplLib
= getImplLib( Name
);
2372 if( pImplLib
->mbLink
)
2374 if( pImplLib
->mbReadOnlyLink
!= bReadOnly
)
2376 pImplLib
->mbReadOnlyLink
= bReadOnly
;
2377 pImplLib
->implSetModified( sal_True
);
2378 maModifiable
.setModified( sal_True
);
2383 if( pImplLib
->mbReadOnly
!= bReadOnly
)
2385 pImplLib
->mbReadOnly
= bReadOnly
;
2386 pImplLib
->implSetModified( sal_True
);
2391 void SAL_CALL
SfxLibraryContainer::renameLibrary( const OUString
& Name
, const OUString
& NewName
)
2392 throw (NoSuchElementException
, ElementExistException
, RuntimeException
)
2394 LibraryContainerMethodGuard
aGuard( *this );
2395 if( maNameContainer
.hasByName( NewName
) )
2396 throw ElementExistException();
2398 // Get and hold library before removing
2399 Any aLibAny
= maNameContainer
.getByName( Name
) ;
2401 // #i24094 Maybe lib is not loaded!
2402 Reference
< XNameAccess
> xNameAccess
;
2403 aLibAny
>>= xNameAccess
;
2404 SfxLibrary
* pImplLib
= static_cast< SfxLibrary
* >( xNameAccess
.get() );
2405 if( pImplLib
->mbPasswordProtected
&& !pImplLib
->mbPasswordVerified
)
2406 return; // Lib with unverified password cannot be renamed
2407 loadLibrary( Name
);
2409 // Remove from container
2410 maNameContainer
.removeByName( Name
);
2411 maModifiable
.setModified( sal_True
);
2413 // Rename library folder, but not for linked libraries
2414 bool bMovedSuccessful
= true;
2417 sal_Bool bStorage
= mxStorage
.is();
2418 if( !bStorage
&& !pImplLib
->mbLink
)
2420 bMovedSuccessful
= false;
2422 OUString aLibDirPath
= pImplLib
->maStorageURL
;
2424 INetURLObject
aDestInetObj( String(maLibraryPath
).GetToken(1) );
2425 aDestInetObj
.insertName( NewName
, sal_True
, INetURLObject::LAST_SEGMENT
,
2426 sal_True
, INetURLObject::ENCODE_ALL
);
2427 OUString aDestDirPath
= aDestInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
2430 OUString aLibInfoFileURL
= pImplLib
->maLibInfoFileURL
;
2431 checkStorageURL( aDestDirPath
, pImplLib
->maLibInfoFileURL
, pImplLib
->maStorageURL
,
2432 pImplLib
->maUnexpandedStorageURL
);
2436 if( mxSFI
->isFolder( aLibDirPath
) )
2438 if( !mxSFI
->isFolder( aDestDirPath
) )
2439 mxSFI
->createFolder( aDestDirPath
);
2444 if( mxSFI
->exists( pImplLib
->maLibInfoFileURL
) )
2445 mxSFI
->kill( pImplLib
->maLibInfoFileURL
);
2446 mxSFI
->move( aLibInfoFileURL
, pImplLib
->maLibInfoFileURL
);
2452 Sequence
< OUString
> aElementNames
= xNameAccess
->getElementNames();
2453 sal_Int32 nNameCount
= aElementNames
.getLength();
2454 const OUString
* pNames
= aElementNames
.getConstArray();
2455 for( sal_Int32 i
= 0 ; i
< nNameCount
; i
++ )
2457 OUString aElementName
= pNames
[ i
];
2459 INetURLObject
aElementInetObj( aLibDirPath
);
2460 aElementInetObj
.insertName( aElementName
, sal_False
,
2461 INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
2462 aElementInetObj
.setExtension( maLibElementFileExtension
);
2463 String
aElementPath( aElementInetObj
.GetMainURL( INetURLObject::NO_DECODE
) );
2465 INetURLObject
aElementDestInetObj( aDestDirPath
);
2466 aElementDestInetObj
.insertName( aElementName
, sal_False
,
2467 INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
2468 aElementDestInetObj
.setExtension( maLibElementFileExtension
);
2469 String
aDestElementPath( aElementDestInetObj
.GetMainURL( INetURLObject::NO_DECODE
) );
2473 if( mxSFI
->exists( aDestElementPath
) )
2474 mxSFI
->kill( aDestElementPath
);
2475 mxSFI
->move( aElementPath
, aDestElementPath
);
2481 pImplLib
->storeResourcesAsURL( aDestDirPath
, NewName
);
2483 // Delete folder if empty
2484 Sequence
< OUString
> aContentSeq
= mxSFI
->getFolderContents( aLibDirPath
, true );
2485 sal_Int32 nCount
= aContentSeq
.getLength();
2488 mxSFI
->kill( aLibDirPath
);
2491 bMovedSuccessful
= true;
2492 pImplLib
->implSetModified( sal_True
);
2497 // Restore old library
2498 maNameContainer
.insertByName( Name
, aLibAny
) ;
2502 if( bStorage
&& !pImplLib
->mbLink
)
2503 pImplLib
->implSetModified( sal_True
);
2505 if( bMovedSuccessful
)
2506 maNameContainer
.insertByName( NewName
, aLibAny
) ;
2511 // Methods XInitialization
2512 void SAL_CALL
SfxLibraryContainer::initialize( const Sequence
< Any
>& _rArguments
)
2513 throw (Exception
, RuntimeException
)
2515 LibraryContainerMethodGuard
aGuard( *this );
2516 sal_Int32 nArgCount
= _rArguments
.getLength();
2517 if ( nArgCount
== 1 )
2519 OUString sInitialDocumentURL
;
2520 Reference
< XStorageBasedDocument
> xDocument
;
2521 if ( _rArguments
[0] >>= sInitialDocumentURL
)
2523 initializeFromDocumentURL( sInitialDocumentURL
);
2527 if ( _rArguments
[0] >>= xDocument
)
2529 initializeFromDocument( xDocument
);
2534 throw IllegalArgumentException();
2537 void SAL_CALL
SfxLibraryContainer::initializeFromDocumentURL( const ::rtl::OUString
& _rInitialDocumentURL
)
2539 init( _rInitialDocumentURL
, NULL
);
2542 void SAL_CALL
SfxLibraryContainer::initializeFromDocument( const Reference
< XStorageBasedDocument
>& _rxDocument
)
2544 // check whether this is a valid OfficeDocument, and obtain the document's root storage
2545 Reference
< XStorage
> xDocStorage
;
2548 Reference
< XServiceInfo
> xSI( _rxDocument
, UNO_QUERY_THROW
);
2549 if ( xSI
->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.OfficeDocument" ) ) ) )
2550 xDocStorage
.set( _rxDocument
->getDocumentStorage(), UNO_QUERY_THROW
);
2552 Reference
< XModel
> xDocument( _rxDocument
, UNO_QUERY_THROW
);
2553 Reference
< XComponent
> xDocComponent( _rxDocument
, UNO_QUERY_THROW
);
2555 mxOwnerDocument
= xDocument
;
2556 startComponentListening( xDocComponent
);
2558 catch( const Exception
& ) { }
2560 if ( !xDocStorage
.is() )
2561 throw IllegalArgumentException();
2563 init( OUString(), xDocStorage
);
2566 // OEventListenerAdapter
2567 void SfxLibraryContainer::_disposing( const EventObject
& _rSource
)
2569 #if OSL_DEBUG_LEVEL > 0
2570 Reference
< XModel
> xDocument( mxOwnerDocument
.get(), UNO_QUERY
);
2571 OSL_ENSURE( ( xDocument
== _rSource
.Source
) && xDocument
.is(), "SfxLibraryContainer::_disposing: where does this come from?" );
2579 void SAL_CALL
SfxLibraryContainer::disposing()
2581 stopAllComponentListening();
2582 mxOwnerDocument
= WeakReference
< XModel
>();
2585 // Methods XLibraryContainerPassword
2586 sal_Bool SAL_CALL
SfxLibraryContainer::isLibraryPasswordProtected( const OUString
& )
2587 throw (NoSuchElementException
, RuntimeException
)
2589 LibraryContainerMethodGuard
aGuard( *this );
2593 sal_Bool SAL_CALL
SfxLibraryContainer::isLibraryPasswordVerified( const OUString
& )
2594 throw (IllegalArgumentException
, NoSuchElementException
, RuntimeException
)
2596 LibraryContainerMethodGuard
aGuard( *this );
2597 throw IllegalArgumentException();
2600 sal_Bool SAL_CALL
SfxLibraryContainer::verifyLibraryPassword
2601 ( const OUString
&, const OUString
& )
2602 throw (IllegalArgumentException
, NoSuchElementException
, RuntimeException
)
2604 LibraryContainerMethodGuard
aGuard( *this );
2605 throw IllegalArgumentException();
2608 void SAL_CALL
SfxLibraryContainer::changeLibraryPassword(
2609 const OUString
&, const OUString
&, const OUString
& )
2610 throw (IllegalArgumentException
, NoSuchElementException
, RuntimeException
)
2612 LibraryContainerMethodGuard
aGuard( *this );
2613 throw IllegalArgumentException();
2616 // Methods XContainer
2617 void SAL_CALL
SfxLibraryContainer::addContainerListener( const Reference
< XContainerListener
>& xListener
)
2618 throw (RuntimeException
)
2620 LibraryContainerMethodGuard
aGuard( *this );
2621 maNameContainer
.setEventSource( static_cast< XInterface
* >( (OWeakObject
*)this ) );
2622 maNameContainer
.addContainerListener( xListener
);
2625 void SAL_CALL
SfxLibraryContainer::removeContainerListener( const Reference
< XContainerListener
>& xListener
)
2626 throw (RuntimeException
)
2628 LibraryContainerMethodGuard
aGuard( *this );
2629 maNameContainer
.removeContainerListener( xListener
);
2632 // Methods XLibraryContainerExport
2633 void SAL_CALL
SfxLibraryContainer::exportLibrary( const OUString
& Name
, const OUString
& URL
,
2634 const Reference
< XInteractionHandler
>& Handler
)
2635 throw ( uno::Exception
, NoSuchElementException
, RuntimeException
)
2637 LibraryContainerMethodGuard
aGuard( *this );
2638 SfxLibrary
* pImplLib
= getImplLib( Name
);
2640 Reference
< XSimpleFileAccess
> xToUseSFI
;
2643 xToUseSFI
= Reference
< XSimpleFileAccess
>( mxMSF
->createInstance
2644 ( OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY
);
2645 if( xToUseSFI
.is() )
2646 xToUseSFI
->setInteractionHandler( Handler
);
2649 // Maybe lib is not loaded?!
2650 loadLibrary( Name
);
2652 uno::Reference
< ::com::sun::star::embed::XStorage
> xDummyStor
;
2653 if( pImplLib
->mbPasswordProtected
)
2654 implStorePasswordLibrary( pImplLib
, Name
, xDummyStor
, URL
, xToUseSFI
, Handler
);
2656 implStoreLibrary( pImplLib
, Name
, xDummyStor
, URL
, xToUseSFI
, Handler
);
2658 ::xmlscript::LibDescriptor aLibDesc
;
2659 aLibDesc
.aName
= Name
;
2660 aLibDesc
.bLink
= false; // Link status gets lost?
2661 aLibDesc
.bReadOnly
= pImplLib
->mbReadOnly
;
2662 aLibDesc
.bPreload
= false; // Preload status gets lost?
2663 aLibDesc
.bPasswordProtected
= pImplLib
->mbPasswordProtected
;
2664 aLibDesc
.aElementNames
= pImplLib
->getElementNames();
2666 implStoreLibraryIndexFile( pImplLib
, aLibDesc
, xDummyStor
, URL
, xToUseSFI
);
2669 OUString
SfxLibraryContainer::expand_url( const OUString
& url
)
2670 throw(::com::sun::star::uno::RuntimeException
)
2672 if (0 == url
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(EXPAND_PROTOCOL
":") ))
2674 if( !mxMacroExpander
.is() )
2676 Reference
< XPropertySet
> xProps( mxMSF
, UNO_QUERY
);
2677 OSL_ASSERT( xProps
.is() );
2680 Reference
< XComponentContext
> xContext
;
2681 xProps
->getPropertyValue(
2682 OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xContext
;
2683 OSL_ASSERT( xContext
.is() );
2686 Reference
< util::XMacroExpander
> xExpander
;
2687 xContext
->getValueByName(
2688 OUSTR("/singletons/com.sun.star.util.theMacroExpander") ) >>= xExpander
;
2689 if(! xExpander
.is())
2691 throw uno::DeploymentException(
2692 OUSTR("no macro expander singleton available!"), Reference
< XInterface
>() );
2694 MutexGuard
guard( Mutex::getGlobalMutex() );
2695 if( !mxMacroExpander
.is() )
2697 mxMacroExpander
= xExpander
;
2703 if( !mxMacroExpander
.is() )
2707 OUString
macro( url
.copy( sizeof (EXPAND_PROTOCOL
":") -1 ) );
2708 // decode uric class chars
2709 macro
= Uri::decode( macro
, rtl_UriDecodeWithCharset
, RTL_TEXTENCODING_UTF8
);
2710 // expand macro string
2711 OUString
ret( mxMacroExpander
->expandMacros( macro
) );
2714 else if( mxStringSubstitution
.is() )
2716 OUString
ret( mxStringSubstitution
->substituteVariables( url
, false ) );
2725 ::sal_Bool SAL_CALL
SfxLibraryContainer::getVBACompatModeOn() throw (RuntimeException
)
2727 sal_Bool bVBACompat
= sal_False
;
2728 BasicManager
* pBasMgr
= getBasicManager();
2731 // get the standard library
2732 String
aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
2734 if ( pBasMgr
->GetName().Len() )
2735 aLibName
= pBasMgr
->GetName();
2737 StarBASIC
* pBasic
= pBasMgr
->GetLib( aLibName
);
2739 bVBACompat
= pBasic
->isVBAEnabled();
2745 void SAL_CALL
SfxLibraryContainer::setVBACompatModeOn( ::sal_Bool _vbacompatmodeon
) throw (RuntimeException
)
2747 BasicManager
* pBasMgr
= getBasicManager();
2750 // get the standard library
2751 String
aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
2752 StarBASIC
* pBasic
= pBasMgr
->GetLib( aLibName
);
2754 pBasic
->SetVBAEnabled( _vbacompatmodeon
);
2758 // Methods XServiceInfo
2759 ::sal_Bool SAL_CALL
SfxLibraryContainer::supportsService( const ::rtl::OUString
& _rServiceName
)
2760 throw (RuntimeException
)
2762 LibraryContainerMethodGuard
aGuard( *this );
2763 Sequence
< OUString
> aSupportedServices( getSupportedServiceNames() );
2764 const OUString
* pSupportedServices
= aSupportedServices
.getConstArray();
2765 for ( sal_Int32 i
=0; i
<aSupportedServices
.getLength(); ++i
, ++pSupportedServices
)
2766 if ( *pSupportedServices
== _rServiceName
)
2771 //============================================================================
2773 // Implementation class SfxLibrary
2776 SfxLibrary::SfxLibrary( ModifiableHelper
& _rModifiable
, const Type
& aType
,
2777 const Reference
< XMultiServiceFactory
>& xMSF
, const Reference
< XSimpleFileAccess
>& xSFI
)
2778 : OComponentHelper( m_aMutex
)
2781 , mrModifiable( _rModifiable
)
2782 , maNameContainer( aType
)
2783 , mbLoaded( sal_True
)
2784 , mbIsModified( sal_True
)
2785 , mbInitialised( sal_False
)
2786 , mbLink( sal_False
)
2787 , mbReadOnly( sal_False
)
2788 , mbReadOnlyLink( sal_False
)
2789 , mbPreload( sal_False
)
2790 , mbPasswordProtected( sal_False
)
2791 , mbPasswordVerified( sal_False
)
2792 , mbDoc50Password( sal_False
)
2793 , mbSharedIndexFile( sal_False
)
2794 , mbExtension( sal_False
)
2798 SfxLibrary::SfxLibrary( ModifiableHelper
& _rModifiable
, const Type
& aType
,
2799 const Reference
< XMultiServiceFactory
>& xMSF
, const Reference
< XSimpleFileAccess
>& xSFI
,
2800 const OUString
& aLibInfoFileURL
, const OUString
& aStorageURL
, sal_Bool ReadOnly
)
2801 : OComponentHelper( m_aMutex
)
2804 , mrModifiable( _rModifiable
)
2805 , maNameContainer( aType
)
2806 , mbLoaded( sal_False
)
2807 , mbIsModified( sal_True
)
2808 , mbInitialised( sal_False
)
2809 , maLibInfoFileURL( aLibInfoFileURL
)
2810 , maStorageURL( aStorageURL
)
2811 , mbLink( sal_True
)
2812 , mbReadOnly( sal_False
)
2813 , mbReadOnlyLink( ReadOnly
)
2814 , mbPreload( sal_False
)
2815 , mbPasswordProtected( sal_False
)
2816 , mbPasswordVerified( sal_False
)
2817 , mbDoc50Password( sal_False
)
2818 , mbSharedIndexFile( sal_False
)
2819 , mbExtension( sal_False
)
2823 void SfxLibrary::implSetModified( sal_Bool _bIsModified
)
2825 if ( mbIsModified
== _bIsModified
)
2827 mbIsModified
= _bIsModified
;
2829 mrModifiable
.setModified( sal_True
);
2832 // Methods XInterface
2833 Any SAL_CALL
SfxLibrary::queryInterface( const Type
& rType
)
2834 throw( RuntimeException
)
2841 aRet = Any( ::cppu::queryInterface( rType,
2842 static_cast< XContainer * >( this ),
2843 static_cast< XNameAccess * >( this ) ) );
2848 aRet
= Any( ::cppu::queryInterface( rType
,
2849 static_cast< XContainer
* >( this ),
2850 static_cast< XNameContainer
* >( this ),
2851 static_cast< XNameAccess
* >( this ) ) );
2853 if( !aRet
.hasValue() )
2854 aRet
= OComponentHelper::queryInterface( rType
);
2858 // Methods XElementAccess
2859 Type
SfxLibrary::getElementType()
2860 throw(RuntimeException
)
2862 return maNameContainer
.getElementType();
2865 sal_Bool
SfxLibrary::hasElements()
2866 throw(RuntimeException
)
2868 sal_Bool bRet
= maNameContainer
.hasElements();
2872 // Methods XNameAccess
2873 Any
SfxLibrary::getByName( const OUString
& aName
)
2874 throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
2878 Any aRetAny
= maNameContainer
.getByName( aName
) ;
2882 Sequence
< OUString
> SfxLibrary::getElementNames()
2883 throw(RuntimeException
)
2885 return maNameContainer
.getElementNames();
2888 sal_Bool
SfxLibrary::hasByName( const OUString
& aName
)
2889 throw(RuntimeException
)
2891 sal_Bool bRet
= maNameContainer
.hasByName( aName
);
2895 void SfxLibrary::impl_checkReadOnly()
2897 if( mbReadOnly
|| (mbLink
&& mbReadOnlyLink
) )
2898 throw IllegalArgumentException(
2899 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Library is readonly." ) ),
2905 void SfxLibrary::impl_checkLoaded()
2908 throw WrappedTargetException(
2911 makeAny( LibraryNotLoadedException(
2918 // Methods XNameReplace
2919 void SfxLibrary::replaceByName( const OUString
& aName
, const Any
& aElement
)
2920 throw(IllegalArgumentException
, NoSuchElementException
, WrappedTargetException
, RuntimeException
)
2922 impl_checkReadOnly();
2925 OSL_ENSURE( isLibraryElementValid( aElement
), "SfxLibrary::replaceByName: replacing element is invalid!" );
2927 maNameContainer
.replaceByName( aName
, aElement
);
2928 implSetModified( sal_True
);
2932 // Methods XNameContainer
2933 void SfxLibrary::insertByName( const OUString
& aName
, const Any
& aElement
)
2934 throw(IllegalArgumentException
, ElementExistException
, WrappedTargetException
, RuntimeException
)
2936 impl_checkReadOnly();
2939 OSL_ENSURE( isLibraryElementValid( aElement
), "SfxLibrary::insertByName: to-be-inserted element is invalid!" );
2941 maNameContainer
.insertByName( aName
, aElement
);
2942 implSetModified( sal_True
);
2945 void SfxLibrary::impl_removeWithoutChecks( const ::rtl::OUString
& _rElementName
)
2947 maNameContainer
.removeByName( _rElementName
);
2948 implSetModified( sal_True
);
2950 // Remove element file
2951 if( maStorageURL
.getLength() )
2953 INetURLObject
aElementInetObj( maStorageURL
);
2954 aElementInetObj
.insertName( _rElementName
, sal_False
,
2955 INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::ENCODE_ALL
);
2956 aElementInetObj
.setExtension( maLibElementFileExtension
);
2957 OUString aFile
= aElementInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
2961 if( mxSFI
->exists( aFile
) )
2962 mxSFI
->kill( aFile
);
2966 DBG_UNHANDLED_EXCEPTION();
2971 void SfxLibrary::removeByName( const OUString
& Name
)
2972 throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
2974 impl_checkReadOnly();
2976 impl_removeWithoutChecks( Name
);
2980 Sequence
< Type
> SfxLibrary::getTypes()
2981 throw( RuntimeException
)
2983 static OTypeCollection
* s_pTypes_NameContainer
= 0;
2985 if( !s_pTypes_NameContainer
)
2987 MutexGuard
aGuard( Mutex::getGlobalMutex() );
2988 if( !s_pTypes_NameContainer
)
2990 static OTypeCollection
s_aTypes_NameContainer(
2991 ::getCppuType( (const Reference
< XNameContainer
> *)0 ),
2992 ::getCppuType( (const Reference
< XContainer
> *)0 ),
2993 OComponentHelper::getTypes() );
2994 s_pTypes_NameContainer
= &s_aTypes_NameContainer
;
2997 return s_pTypes_NameContainer
->getTypes();
3002 Sequence
< sal_Int8
> SfxLibrary::getImplementationId()
3003 throw( RuntimeException
)
3005 static OImplementationId
* s_pId_NameContainer
= 0;
3007 if( !s_pId_NameContainer
)
3009 MutexGuard
aGuard( Mutex::getGlobalMutex() );
3010 if( !s_pId_NameContainer
)
3012 static OImplementationId s_aId_NameContainer
;
3013 s_pId_NameContainer
= &s_aId_NameContainer
;
3016 return s_pId_NameContainer
->getImplementationId();
3021 //============================================================================
3023 // Methods XContainer
3024 void SAL_CALL
SfxLibrary::addContainerListener( const Reference
< XContainerListener
>& xListener
)
3025 throw (RuntimeException
)
3027 maNameContainer
.setEventSource( static_cast< XInterface
* >( (OWeakObject
*)this ) );
3028 maNameContainer
.addContainerListener( xListener
);
3031 void SAL_CALL
SfxLibrary::removeContainerListener( const Reference
< XContainerListener
>& xListener
)
3032 throw (RuntimeException
)
3034 maNameContainer
.removeContainerListener( xListener
);
3038 //============================================================================
3039 // Implementation class ScriptExtensionIterator
3041 static rtl::OUString
aBasicLibMediaType( rtl::OUString::createFromAscii( "application/vnd.sun.star.basic-library" ) );
3042 static rtl::OUString
aDialogLibMediaType( rtl::OUString::createFromAscii( "application/vnd.sun.star.dialog-library" ) );
3044 ScriptExtensionIterator::ScriptExtensionIterator( void )
3045 : m_eState( USER_EXTENSIONS
)
3046 , m_bUserPackagesLoaded( false )
3047 , m_bSharedPackagesLoaded( false )
3048 , m_iUserPackage( 0 )
3049 , m_iSharedPackage( 0 )
3050 , m_pScriptSubPackageIterator( NULL
)
3052 Reference
< XMultiServiceFactory
> xFactory
= comphelper::getProcessServiceFactory();
3053 Reference
< XPropertySet
> xProps( xFactory
, UNO_QUERY
);
3054 OSL_ASSERT( xProps
.is() );
3057 xProps
->getPropertyValue(
3058 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= m_xContext
;
3059 OSL_ASSERT( m_xContext
.is() );
3061 if( !m_xContext
.is() )
3063 throw RuntimeException(
3064 ::rtl::OUString::createFromAscii( "ScriptExtensionIterator::init(), no XComponentContext" ),
3065 Reference
< XInterface
>() );
3069 rtl::OUString
ScriptExtensionIterator::nextBasicOrDialogLibrary( bool& rbPureDialogLib
)
3071 rtl::OUString aRetLib
;
3073 while( !aRetLib
.getLength() && m_eState
!= END_REACHED
)
3077 case USER_EXTENSIONS
:
3079 Reference
< deployment::XPackage
> xScriptPackage
=
3080 implGetNextUserScriptPackage( rbPureDialogLib
);
3081 if( !xScriptPackage
.is() )
3084 aRetLib
= xScriptPackage
->getURL();
3088 case SHARED_EXTENSIONS
:
3090 Reference
< deployment::XPackage
> xScriptPackage
=
3091 implGetNextSharedScriptPackage( rbPureDialogLib
);
3092 if( !xScriptPackage
.is() )
3095 aRetLib
= xScriptPackage
->getURL();
3099 VOS_ENSURE( false, "ScriptExtensionIterator::nextBasicOrDialogLibrary(): Invalid case END_REACHED" );
3107 ScriptSubPackageIterator::ScriptSubPackageIterator( Reference
< deployment::XPackage
> xMainPackage
)
3108 : m_xMainPackage( xMainPackage
)
3109 , m_bIsValid( false )
3110 , m_bIsBundle( false )
3111 , m_nSubPkgCount( 0 )
3112 , m_iNextSubPkg( 0 )
3114 Reference
< deployment::XPackage
> xScriptPackage
;
3115 if( !m_xMainPackage
.is() )
3118 // Check if parent package is registered
3119 beans::Optional
< beans::Ambiguous
<sal_Bool
> > option( m_xMainPackage
->isRegistered
3120 ( Reference
<task::XAbortChannel
>(), Reference
<ucb::XCommandEnvironment
>() ) );
3121 bool bRegistered
= false;
3122 if( option
.IsPresent
)
3124 beans::Ambiguous
<sal_Bool
> const & reg
= option
.Value
;
3125 if( !reg
.IsAmbiguous
&& reg
.Value
)
3131 if( m_xMainPackage
->isBundle() )
3134 m_aSubPkgSeq
= m_xMainPackage
->getBundle
3135 ( Reference
<task::XAbortChannel
>(), Reference
<ucb::XCommandEnvironment
>() );
3136 m_nSubPkgCount
= m_aSubPkgSeq
.getLength();
3141 Reference
< deployment::XPackage
> ScriptSubPackageIterator::getNextScriptSubPackage
3142 ( bool& rbPureDialogLib
)
3144 rbPureDialogLib
= false;
3146 Reference
< deployment::XPackage
> xScriptPackage
;
3148 return xScriptPackage
;
3152 const Reference
< deployment::XPackage
>* pSeq
= m_aSubPkgSeq
.getConstArray();
3154 for( iPkg
= m_iNextSubPkg
; iPkg
< m_nSubPkgCount
; ++iPkg
)
3156 const Reference
< deployment::XPackage
> xSubPkg
= pSeq
[ iPkg
];
3157 xScriptPackage
= implDetectScriptPackage( xSubPkg
, rbPureDialogLib
);
3158 if( xScriptPackage
.is() )
3161 m_iNextSubPkg
= iPkg
+ 1;
3165 xScriptPackage
= implDetectScriptPackage( m_xMainPackage
, rbPureDialogLib
);
3166 m_bIsValid
= false; // No more script packages
3169 return xScriptPackage
;
3172 Reference
< deployment::XPackage
> ScriptSubPackageIterator::implDetectScriptPackage
3173 ( const Reference
< deployment::XPackage
> xPackage
, bool& rbPureDialogLib
)
3175 Reference
< deployment::XPackage
> xScriptPackage
;
3179 const Reference
< deployment::XPackageTypeInfo
> xPackageTypeInfo
= xPackage
->getPackageType();
3180 rtl::OUString aMediaType
= xPackageTypeInfo
->getMediaType();
3181 if( aMediaType
.equals( aBasicLibMediaType
) )
3183 xScriptPackage
= xPackage
;
3185 else if( aMediaType
.equals( aDialogLibMediaType
) )
3187 rbPureDialogLib
= true;
3188 xScriptPackage
= xPackage
;
3192 return xScriptPackage
;
3195 Reference
< deployment::XPackage
> ScriptExtensionIterator::implGetScriptPackageFromPackage
3196 ( const Reference
< deployment::XPackage
> xPackage
, bool& rbPureDialogLib
)
3198 rbPureDialogLib
= false;
3200 Reference
< deployment::XPackage
> xScriptPackage
;
3201 if( !xPackage
.is() )
3202 return xScriptPackage
;
3204 // Check if parent package is registered
3205 beans::Optional
< beans::Ambiguous
<sal_Bool
> > option( xPackage
->isRegistered
3206 ( Reference
<task::XAbortChannel
>(), Reference
<ucb::XCommandEnvironment
>() ) );
3207 bool bRegistered
= false;
3208 if( option
.IsPresent
)
3210 beans::Ambiguous
<sal_Bool
> const & reg
= option
.Value
;
3211 if( !reg
.IsAmbiguous
&& reg
.Value
)
3216 if( xPackage
->isBundle() )
3218 Sequence
< Reference
< deployment::XPackage
> > aPkgSeq
= xPackage
->getBundle
3219 ( Reference
<task::XAbortChannel
>(), Reference
<ucb::XCommandEnvironment
>() );
3220 sal_Int32 nPkgCount
= aPkgSeq
.getLength();
3221 const Reference
< deployment::XPackage
>* pSeq
= aPkgSeq
.getConstArray();
3222 for( sal_Int32 iPkg
= 0 ; iPkg
< nPkgCount
; ++iPkg
)
3224 const Reference
< deployment::XPackage
> xSubPkg
= pSeq
[ iPkg
];
3225 const Reference
< deployment::XPackageTypeInfo
> xPackageTypeInfo
= xSubPkg
->getPackageType();
3226 rtl::OUString aMediaType
= xPackageTypeInfo
->getMediaType();
3227 if( aMediaType
.equals( aBasicLibMediaType
) )
3229 xScriptPackage
= xSubPkg
;
3232 else if( aMediaType
.equals( aDialogLibMediaType
) )
3234 rbPureDialogLib
= true;
3235 xScriptPackage
= xSubPkg
;
3242 const Reference
< deployment::XPackageTypeInfo
> xPackageTypeInfo
= xPackage
->getPackageType();
3243 rtl::OUString aMediaType
= xPackageTypeInfo
->getMediaType();
3244 if( aMediaType
.equals( aBasicLibMediaType
) )
3246 xScriptPackage
= xPackage
;
3248 else if( aMediaType
.equals( aDialogLibMediaType
) )
3250 rbPureDialogLib
= true;
3251 xScriptPackage
= xPackage
;
3256 return xScriptPackage
;
3259 Reference
< deployment::XPackage
> ScriptExtensionIterator::implGetNextUserScriptPackage
3260 ( bool& rbPureDialogLib
)
3262 Reference
< deployment::XPackage
> xScriptPackage
;
3264 if( !m_bUserPackagesLoaded
)
3268 Reference
< XPackageManager
> xUserManager
=
3269 thePackageManagerFactory::get( m_xContext
)->getPackageManager( rtl::OUString::createFromAscii("user") );
3270 m_aUserPackagesSeq
= xUserManager
->getDeployedPackages
3271 ( Reference
< task::XAbortChannel
>(), Reference
< ucb::XCommandEnvironment
>() );
3273 catch( com::sun::star::uno::DeploymentException
& )
3275 // Special Office installations may not contain deployment code
3276 m_eState
= END_REACHED
;
3277 return xScriptPackage
;
3280 m_bUserPackagesLoaded
= true;
3283 if( m_iUserPackage
== m_aUserPackagesSeq
.getLength() )
3285 m_eState
= SHARED_EXTENSIONS
; // Later: SHARED_MODULE
3289 if( m_pScriptSubPackageIterator
== NULL
)
3291 const Reference
< deployment::XPackage
>* pUserPackages
= m_aUserPackagesSeq
.getConstArray();
3292 Reference
< deployment::XPackage
> xPackage
= pUserPackages
[ m_iUserPackage
];
3293 VOS_ENSURE( xPackage
.is(), "ScriptExtensionIterator::implGetNextUserScriptPackage(): Invalid package" );
3294 m_pScriptSubPackageIterator
= new ScriptSubPackageIterator( xPackage
);
3297 if( m_pScriptSubPackageIterator
!= NULL
)
3299 xScriptPackage
= m_pScriptSubPackageIterator
->getNextScriptSubPackage( rbPureDialogLib
);
3300 if( !xScriptPackage
.is() )
3302 delete m_pScriptSubPackageIterator
;
3303 m_pScriptSubPackageIterator
= NULL
;
3309 return xScriptPackage
;
3312 Reference
< deployment::XPackage
> ScriptExtensionIterator::implGetNextSharedScriptPackage
3313 ( bool& rbPureDialogLib
)
3315 Reference
< deployment::XPackage
> xScriptPackage
;
3317 if( !m_bSharedPackagesLoaded
)
3321 Reference
< XPackageManager
> xSharedManager
=
3322 thePackageManagerFactory::get( m_xContext
)->getPackageManager( rtl::OUString::createFromAscii("shared") );
3323 m_aSharedPackagesSeq
= xSharedManager
->getDeployedPackages
3324 ( Reference
< task::XAbortChannel
>(), Reference
< ucb::XCommandEnvironment
>() );
3326 catch( com::sun::star::uno::DeploymentException
& )
3328 // Special Office installations may not contain deployment code
3329 return xScriptPackage
;
3332 m_bSharedPackagesLoaded
= true;
3335 if( m_iSharedPackage
== m_aSharedPackagesSeq
.getLength() )
3337 m_eState
= END_REACHED
;
3341 if( m_pScriptSubPackageIterator
== NULL
)
3343 const Reference
< deployment::XPackage
>* pSharedPackages
= m_aSharedPackagesSeq
.getConstArray();
3344 Reference
< deployment::XPackage
> xPackage
= pSharedPackages
[ m_iSharedPackage
];
3345 VOS_ENSURE( xPackage
.is(), "ScriptExtensionIterator::implGetNextSharedScriptPackage(): Invalid package" );
3346 m_pScriptSubPackageIterator
= new ScriptSubPackageIterator( xPackage
);
3349 if( m_pScriptSubPackageIterator
!= NULL
)
3351 xScriptPackage
= m_pScriptSubPackageIterator
->getNextScriptSubPackage( rbPureDialogLib
);
3352 if( !xScriptPackage
.is() )
3354 delete m_pScriptSubPackageIterator
;
3355 m_pScriptSubPackageIterator
= NULL
;
3361 return xScriptPackage
;
3364 } // namespace basic