xref: /trunk/main/basic/source/inc/namecont.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef BASIC_NAMECONTAINER_HXX
29 #define BASIC_NAMECONTAINER_HXX
30 
31 #include <hash_map>
32 
33 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp>
37 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
38 #include <com/sun/star/script/XLibraryContainerExport.hpp>
39 #include <com/sun/star/script/XLibraryContainer3.hpp>
40 #include <com/sun/star/container/XNameContainer.hpp>
41 #include <com/sun/star/container/XContainer.hpp>
42 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
43 #include <com/sun/star/io/XOutputStream.hpp>
44 #include <com/sun/star/io/XInputStream.hpp>
45 #include <com/sun/star/util/XMacroExpander.hpp>
46 #include <com/sun/star/util/XStringSubstitution.hpp>
47 #include <com/sun/star/document/XStorageBasedDocument.hpp>
48 #include <com/sun/star/lang/XServiceInfo.hpp>
49 #include <com/sun/star/frame/XModel.hpp>
50 #include <com/sun/star/deployment/XPackage.hpp>
51 #include <com/sun/star/script/vba/XVBACompatibility.hpp>
52 #include <com/sun/star/script/vba/XVBAScriptListener.hpp>
53 #include <com/sun/star/util/XChangesNotifier.hpp>
54 
55 #include <osl/mutex.hxx>
56 #include <unotools/eventlisteneradapter.hxx>
57 #include <cppuhelper/implbase3.hxx>
58 #include <cppuhelper/compbase8.hxx>
59 #include <cppuhelper/interfacecontainer.hxx>
60 #include <cppuhelper/weakref.hxx>
61 #include <cppuhelper/component.hxx>
62 #include <cppuhelper/typeprovider.hxx>
63 #include <cppuhelper/interfacecontainer.hxx>
64 #include <cppuhelper/basemutex.hxx>
65 #include <sot/storage.hxx>
66 #include <comphelper/listenernotification.hxx>
67 #include <xmlscript/xmllib_imexp.hxx>
68 
69 class BasicManager;
70 
71 namespace basic
72 {
73 
74 //============================================================================
75 
76 typedef ::cppu::WeakImplHelper3<
77     ::com::sun::star::container::XNameContainer,
78 	::com::sun::star::container::XContainer,
79 	::com::sun::star::util::XChangesNotifier > NameContainer_BASE;
80 
81 class NameContainer : public ::cppu::BaseMutex, public NameContainer_BASE
82 {
83     typedef std::hash_map< ::rtl::OUString, sal_Int32, ::rtl::OUStringHash > NameContainerNameMap;
84 
85 	NameContainerNameMap mHashMap;
86 	::com::sun::star::uno::Sequence< ::rtl::OUString > mNames;
87 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > mValues;
88 	sal_Int32 mnElementCount;
89 
90 	::com::sun::star::uno::Type mType;
91 	::com::sun::star::uno::XInterface* mpxEventSource;
92 
93 	::cppu::OInterfaceContainerHelper maContainerListeners;
94 	::cppu::OInterfaceContainerHelper maChangesListeners;
95 
96 public:
97 	NameContainer( const ::com::sun::star::uno::Type& rType )
98 		: mnElementCount( 0 )
99 		, mType( rType )
100         , mpxEventSource( NULL )
101 		, maContainerListeners( m_aMutex )
102 		, maChangesListeners( m_aMutex )
103 	{}
104 
105 	void setEventSource( ::com::sun::star::uno::XInterface* pxEventSource )
106 		{ mpxEventSource = pxEventSource; }
107 
108     // Methods XElementAccess
109     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  )
110 		throw(::com::sun::star::uno::RuntimeException);
111     virtual sal_Bool SAL_CALL hasElements(  )
112 		throw(::com::sun::star::uno::RuntimeException);
113 
114     // Methods XNameAccess
115     virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
116 		throw(::com::sun::star::container::NoSuchElementException,
117 			  ::com::sun::star::lang::WrappedTargetException,
118 			  ::com::sun::star::uno::RuntimeException);
119     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  )
120 		throw(::com::sun::star::uno::RuntimeException);
121     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
122 		throw(::com::sun::star::uno::RuntimeException);
123 
124     // Methods XNameReplace
125     virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
126 		throw(::com::sun::star::lang::IllegalArgumentException,
127 			  ::com::sun::star::container::NoSuchElementException,
128 			  ::com::sun::star::lang::WrappedTargetException,
129 			  ::com::sun::star::uno::RuntimeException);
130 
131     // Methods XNameContainer
132     virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
133 		throw(::com::sun::star::lang::IllegalArgumentException,
134 			  ::com::sun::star::container::ElementExistException,
135 			  ::com::sun::star::lang::WrappedTargetException,
136 			  ::com::sun::star::uno::RuntimeException);
137     virtual void SAL_CALL removeByName( const ::rtl::OUString& Name )
138 		throw(::com::sun::star::container::NoSuchElementException,
139 			  ::com::sun::star::lang::WrappedTargetException,
140 			  ::com::sun::star::uno::RuntimeException);
141 
142 	// Methods XContainer
143 	virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference<
144 		::com::sun::star::container::XContainerListener >& xListener )
145 			throw (::com::sun::star::uno::RuntimeException);
146 	virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference<
147 		::com::sun::star::container::XContainerListener >& xListener )
148 			throw (::com::sun::star::uno::RuntimeException);
149 
150     // Methods XChangesNotifier
151     virtual void SAL_CALL addChangesListener( const ::com::sun::star::uno::Reference<
152         ::com::sun::star::util::XChangesListener >& xListener )
153             throw (::com::sun::star::uno::RuntimeException);
154     virtual void SAL_CALL removeChangesListener( const ::com::sun::star::uno::Reference<
155 		::com::sun::star::util::XChangesListener >& xListener )
156             throw (::com::sun::star::uno::RuntimeException);
157 };
158 
159 //============================================================================
160 
161 class ModifiableHelper
162 {
163 private:
164     ::cppu::OInterfaceContainerHelper   m_aModifyListeners;
165     ::cppu::OWeakObject&                m_rEventSource;
166     sal_Bool                            mbModified;
167 
168 public:
169     ModifiableHelper( ::cppu::OWeakObject& _rEventSource, ::osl::Mutex& _rMutex )
170         :m_aModifyListeners( _rMutex )
171         ,m_rEventSource( _rEventSource )
172         ,mbModified( sal_False )
173     {
174     }
175 
176     inline  sal_Bool    isModified() const  { return mbModified; }
177             void        setModified( sal_Bool _bModified );
178 
179     inline  void    addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& _rxListener )
180     {
181         m_aModifyListeners.addInterface( _rxListener );
182     }
183 
184     inline  void    removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& _rxListener )
185     {
186         m_aModifyListeners.removeInterface( _rxListener );
187     }
188 };
189 
190 //============================================================================
191 
192 typedef ::comphelper::OListenerContainerBase<
193     ::com::sun::star::script::vba::XVBAScriptListener,
194     ::com::sun::star::script::vba::VBAScriptEvent > VBAScriptListenerContainer_BASE;
195 
196 class VBAScriptListenerContainer : public VBAScriptListenerContainer_BASE
197 {
198 public:
199     explicit VBAScriptListenerContainer( ::osl::Mutex& rMutex );
200 
201 private:
202     virtual bool implTypedNotify(
203         const ::com::sun::star::uno::Reference< ::com::sun::star::script::vba::XVBAScriptListener >& rxListener,
204         const ::com::sun::star::script::vba::VBAScriptEvent& rEvent )
205         throw (::com::sun::star::uno::Exception);
206 };
207 
208 //============================================================================
209 
210 class SfxLibrary;
211 
212 typedef ::cppu::WeakComponentImplHelper8<
213     ::com::sun::star::lang::XInitialization,
214     ::com::sun::star::script::XStorageBasedLibraryContainer,
215     ::com::sun::star::script::XLibraryContainerPassword,
216     ::com::sun::star::script::XLibraryContainerExport,
217     ::com::sun::star::script::XLibraryContainer3,
218     ::com::sun::star::container::XContainer,
219     ::com::sun::star::script::vba::XVBACompatibility,
220     ::com::sun::star::lang::XServiceInfo > SfxLibraryContainer_BASE;
221 
222 class SfxLibraryContainer : public SfxLibraryContainer_BASE, public ::utl::OEventListenerAdapter
223 {
224     VBAScriptListenerContainer maVBAScriptListeners;
225     sal_Int32 mnRunningVBAScripts;
226     sal_Bool mbVBACompat;
227 protected:
228     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >   mxMSF;
229 	::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >       mxSFI;
230     ::com::sun::star::uno::Reference< ::com::sun::star::util::XMacroExpander >         mxMacroExpander;
231     ::com::sun::star::uno::Reference< ::com::sun::star::util::XStringSubstitution >    mxStringSubstitution;
232     ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XModel >            mxOwnerDocument;
233 
234     ::osl::Mutex        maMutex;
235     ModifiableHelper    maModifiable;
236 
237 	NameContainer maNameContainer;
238 	sal_Bool    mbOldInfoFormat;
239 	sal_Bool    mbOasis2OOoFormat;
240 
241     ::rtl::OUString maInitialDocumentURL;
242 	::rtl::OUString maInfoFileName;
243 	::rtl::OUString maOldInfoFileName;
244 	::rtl::OUString maLibElementFileExtension;
245 	::rtl::OUString maLibraryPath;
246 	::rtl::OUString maLibrariesDir;
247 
248 	::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > mxStorage;
249     BasicManager*   mpBasMgr;
250 	sal_Bool        mbOwnBasMgr;
251 
252     enum InitMode
253     {
254         DEFAULT,
255         CONTAINER_INIT_FILE,
256         LIBRARY_INIT_FILE,
257         OFFICE_DOCUMENT,
258         OLD_BASIC_STORAGE
259     } meInitMode;
260 
261 	void implStoreLibrary( SfxLibrary* pLib,
262 							const ::rtl::OUString& aName,
263 							const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage );
264 
265 	// New variant for library export
266 	void implStoreLibrary( SfxLibrary* pLib,
267 							const ::rtl::OUString& aName,
268 							const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
269 							const ::rtl::OUString& aTargetURL,
270 							const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI,
271 							const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler );
272 
273     void implStoreLibraryIndexFile( SfxLibrary* pLib, const ::xmlscript::LibDescriptor& rLib,
274 									const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage );
275 
276 	// New variant for library export
277     void implStoreLibraryIndexFile( SfxLibrary* pLib, const ::xmlscript::LibDescriptor& rLib,
278 									const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
279 									const ::rtl::OUString& aTargetURL,
280 									const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI );
281 
282     sal_Bool implLoadLibraryIndexFile( SfxLibrary* pLib,
283 									::xmlscript::LibDescriptor& rLib,
284 									const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
285 									const ::rtl::OUString& aIndexFileName );
286 
287     void implImportLibDescriptor( SfxLibrary* pLib, ::xmlscript::LibDescriptor& rLib );
288 
289 	// Methods to distinguish between deffirent library types
290 	virtual SfxLibrary* SAL_CALL implCreateLibrary( const ::rtl::OUString& aName ) = 0;
291     virtual SfxLibrary* SAL_CALL implCreateLibraryLink
292 		( const ::rtl::OUString& aName, const ::rtl::OUString& aLibInfoFileURL,
293           const ::rtl::OUString& StorageURL, sal_Bool ReadOnly ) = 0;
294 	virtual ::com::sun::star::uno::Any SAL_CALL createEmptyLibraryElement( void ) = 0;
295 	virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const = 0;
296 	virtual void SAL_CALL writeLibraryElement
297 	(
298 		const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& xLibrary,
299 		const ::rtl::OUString& aElementName,
300 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutput
301 	)
302 		throw(::com::sun::star::uno::Exception) = 0;
303 
304 	virtual ::com::sun::star::uno::Any SAL_CALL importLibraryElement
305 	(
306 		const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& xLibrary,
307 		const ::rtl::OUString& aElementName,
308 		const ::rtl::OUString& aFile,
309 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xElementStream ) = 0;
310 	virtual void SAL_CALL importFromOldStorage( const ::rtl::OUString& aFile ) = 0;
311 
312     // Password encryption
313 	virtual sal_Bool implStorePasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName,
314         				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler );
315 
316 	// New variant for library export
317 	virtual sal_Bool implStorePasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName,
318         				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
319 						const ::rtl::OUString& aTargetURL,
320 						const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler );
321 
322     virtual sal_Bool implLoadPasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& Name,
323         sal_Bool bVerifyPasswordOnly=false )
324 		    throw(::com::sun::star::lang::WrappedTargetException,
325 			      ::com::sun::star::uno::RuntimeException);
326 
327 	virtual void onNewRootStorage() = 0;
328 
329 
330     // #56666, Creates another library container
331     //         instance of the same derived class
332     virtual SfxLibraryContainer* createInstanceImpl( void ) = 0;
333 
334 
335 	// Interface to get the BasicManager (Hack for password implementation)
336     BasicManager* getBasicManager( void );
337     ::rtl::OUString createAppLibraryFolder( SfxLibrary* pLib, const ::rtl::OUString& aName );
338 
339 	sal_Bool init( const ::rtl::OUString& rInitialDocumentURL,
340 	               const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxInitialStorage );
341 
342     virtual const sal_Char* SAL_CALL    getInfoFileName() const = 0;
343     virtual const sal_Char* SAL_CALL    getOldInfoFileName() const = 0;
344     virtual const sal_Char* SAL_CALL    getLibElementFileExtension() const = 0;
345     virtual const sal_Char* SAL_CALL    getLibrariesDir() const = 0;
346 
347     // Handle maLibInfoFileURL and maStorageURL correctly
348     void checkStorageURL
349     (
350         const ::rtl::OUString& aSourceURL,
351         ::rtl::OUString& aLibInfoFileURL,
352         ::rtl::OUString& aStorageURL,
353         ::rtl::OUString& aUnexpandedStorageURL
354     );
355     ::rtl::OUString expand_url( const ::rtl::OUString& url )
356 		throw(::com::sun::star::uno::RuntimeException);
357 
358     SfxLibrary* getImplLib( const String& rLibraryName );
359 
360 	void storeLibraries_Impl(
361 							const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
362 							sal_Bool bComplete );
363 
364     void SAL_CALL initializeFromDocumentURL( const ::rtl::OUString& _rInitialDocumentURL );
365     void SAL_CALL initializeFromDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XStorageBasedDocument >& _rxDocument );
366 
367     // OEventListenerAdapter
368 	virtual void _disposing( const ::com::sun::star::lang::EventObject& _rSource );
369 
370     // OComponentHelper
371     virtual void SAL_CALL disposing();
372 
373 private:
374 	sal_Bool init_Impl( const ::rtl::OUString& rInitialDocumentURL,
375 	               const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxInitialStorage );
376 	void implScanExtensions( void );
377 
378 public:
379 	SfxLibraryContainer( void );
380 	~SfxLibraryContainer();
381 
382 
383 	// Interface to set the BasicManager (Hack for password implementation)
384 	void setBasicManager( BasicManager* pBasMgr )
385 	{
386 		mpBasMgr = pBasMgr;
387 	}
388 
389     void    enterMethod();
390     void    leaveMethod();
391     bool    isDisposed() const { return rBHelper.bInDispose || rBHelper.bDisposed; }
392     void    checkDisposed() const;
393 
394     // Methods XElementAccess
395     virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
396 		throw(::com::sun::star::uno::RuntimeException);
397     virtual sal_Bool SAL_CALL hasElements()
398 		throw(::com::sun::star::uno::RuntimeException);
399 
400     // Methods XNameAccess
401     virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
402 		throw(::com::sun::star::container::NoSuchElementException,
403 			  ::com::sun::star::lang::WrappedTargetException,
404 			  ::com::sun::star::uno::RuntimeException);
405     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
406 		throw(::com::sun::star::uno::RuntimeException);
407     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
408 		throw(::com::sun::star::uno::RuntimeException);
409 
410     // Members XStorageBasedLibraryContainer
411     virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > SAL_CALL getRootStorage() throw (::com::sun::star::uno::RuntimeException);
412     virtual void SAL_CALL setRootStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rootstorage ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
413     virtual void SAL_CALL storeLibrariesToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& RootStorage ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
414 
415     // Methods XModifiable (base of XPersistentLibraryContainer)
416     virtual ::sal_Bool SAL_CALL isModified(  ) throw (::com::sun::star::uno::RuntimeException);
417     virtual void SAL_CALL setModified( ::sal_Bool bModified ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException);
418     virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
419     virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
420 
421     // Methods XPersistentLibraryContainer (base of XStorageBasedLibraryContainer)
422     virtual ::com::sun::star::uno::Any SAL_CALL getRootLocation() throw (::com::sun::star::uno::RuntimeException);
423     virtual ::rtl::OUString SAL_CALL getContainerLocationName() throw (::com::sun::star::uno::RuntimeException);
424     virtual void SAL_CALL storeLibraries(  ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
425 
426     //Methods XLibraryContainer3
427     virtual ::rtl::OUString SAL_CALL getOriginalLibraryLinkURL( const ::rtl::OUString& Name )
428         throw (::com::sun::star::lang::IllegalArgumentException,
429                ::com::sun::star::container::NoSuchElementException,
430                ::com::sun::star::uno::RuntimeException);
431 
432     // Methods XLibraryContainer2 (base of XPersistentLibraryContainer)
433     virtual sal_Bool SAL_CALL isLibraryLink( const ::rtl::OUString& Name )
434         throw (::com::sun::star::container::NoSuchElementException,
435                ::com::sun::star::uno::RuntimeException);
436     virtual ::rtl::OUString SAL_CALL getLibraryLinkURL( const ::rtl::OUString& Name )
437         throw (::com::sun::star::lang::IllegalArgumentException,
438                ::com::sun::star::container::NoSuchElementException,
439                ::com::sun::star::uno::RuntimeException);
440     virtual sal_Bool SAL_CALL isLibraryReadOnly( const ::rtl::OUString& Name )
441         throw (::com::sun::star::container::NoSuchElementException,
442                ::com::sun::star::uno::RuntimeException);
443     virtual void SAL_CALL setLibraryReadOnly( const ::rtl::OUString& Name, sal_Bool bReadOnly )
444         throw (::com::sun::star::container::NoSuchElementException,
445                ::com::sun::star::uno::RuntimeException);
446     virtual void SAL_CALL renameLibrary( const ::rtl::OUString& Name, const ::rtl::OUString& NewName )
447         throw (::com::sun::star::container::NoSuchElementException,
448                ::com::sun::star::container::ElementExistException,
449                ::com::sun::star::uno::RuntimeException);
450 
451     // Methods XLibraryContainer (base of XLibraryContainer2)
452     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > SAL_CALL
453 		createLibrary( const ::rtl::OUString& Name )
454 			throw(::com::sun::star::lang::IllegalArgumentException,
455 				  ::com::sun::star::container::ElementExistException,
456 				  ::com::sun::star::uno::RuntimeException);
457     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL createLibraryLink
458 		( const ::rtl::OUString& Name, const ::rtl::OUString& StorageURL, sal_Bool ReadOnly )
459 			throw(::com::sun::star::lang::IllegalArgumentException,
460 				  ::com::sun::star::container::ElementExistException,
461 				  ::com::sun::star::uno::RuntimeException);
462     virtual void SAL_CALL removeLibrary( const ::rtl::OUString& Name )
463 		throw(::com::sun::star::container::NoSuchElementException,
464 			  ::com::sun::star::lang::WrappedTargetException,
465 			  ::com::sun::star::uno::RuntimeException);
466     virtual sal_Bool SAL_CALL isLibraryLoaded( const ::rtl::OUString& Name )
467 		throw(::com::sun::star::container::NoSuchElementException,
468 			  ::com::sun::star::uno::RuntimeException);
469     virtual void SAL_CALL loadLibrary( const ::rtl::OUString& Name )
470 		throw(::com::sun::star::container::NoSuchElementException,
471 			  ::com::sun::star::lang::WrappedTargetException,
472 			  ::com::sun::star::uno::RuntimeException);
473 
474     // Methods XInitialization
475     virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence<
476         ::com::sun::star::uno::Any >& aArguments )
477             throw (::com::sun::star::uno::Exception,
478                    ::com::sun::star::uno::RuntimeException);
479 
480     // Methods XLibraryContainerPassword
481     virtual sal_Bool SAL_CALL isLibraryPasswordProtected( const ::rtl::OUString& Name )
482         throw (::com::sun::star::container::NoSuchElementException,
483                ::com::sun::star::uno::RuntimeException);
484     virtual sal_Bool SAL_CALL isLibraryPasswordVerified( const ::rtl::OUString& Name )
485         throw (::com::sun::star::lang::IllegalArgumentException,
486                ::com::sun::star::container::NoSuchElementException,
487                ::com::sun::star::uno::RuntimeException);
488     virtual sal_Bool SAL_CALL verifyLibraryPassword( const ::rtl::OUString& Name, const ::rtl::OUString& Password )
489         throw (::com::sun::star::lang::IllegalArgumentException,
490                ::com::sun::star::container::NoSuchElementException,
491                ::com::sun::star::uno::RuntimeException);
492     virtual void SAL_CALL changeLibraryPassword( const ::rtl::OUString& Name,
493         const ::rtl::OUString& OldPassword, const ::rtl::OUString& NewPassword )
494         throw (::com::sun::star::lang::IllegalArgumentException,
495                ::com::sun::star::container::NoSuchElementException,
496                ::com::sun::star::uno::RuntimeException);
497 
498 	// Methods XContainer
499 	virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference<
500 		::com::sun::star::container::XContainerListener >& xListener )
501 			throw (::com::sun::star::uno::RuntimeException);
502 	virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference<
503 		::com::sun::star::container::XContainerListener >& xListener )
504 			throw (::com::sun::star::uno::RuntimeException);
505 
506     // Methods XLibraryContainerExport
507     virtual void SAL_CALL exportLibrary( const ::rtl::OUString& Name, const ::rtl::OUString& URL,
508 		const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler )
509 			throw (::com::sun::star::uno::Exception,
510 				   ::com::sun::star::container::NoSuchElementException,
511 				   ::com::sun::star::uno::RuntimeException);
512 
513     // Methods XServiceInfo
514     virtual ::rtl::OUString SAL_CALL getImplementationName( )
515         throw (::com::sun::star::uno::RuntimeException) = 0;
516     virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
517         throw (::com::sun::star::uno::RuntimeException);
518     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
519         throw (::com::sun::star::uno::RuntimeException) = 0;
520 	// Methods XVBACompatibility
521 	virtual ::sal_Bool SAL_CALL getVBACompatibilityMode()
522             throw (::com::sun::star::uno::RuntimeException);
523 	virtual void SAL_CALL setVBACompatibilityMode( ::sal_Bool _vbacompatmodeon )
524             throw (::com::sun::star::uno::RuntimeException);
525     virtual sal_Int32 SAL_CALL getRunningVBAScripts()
526             throw (::com::sun::star::uno::RuntimeException);
527     virtual void SAL_CALL addVBAScriptListener(
528         const ::com::sun::star::uno::Reference< ::com::sun::star::script::vba::XVBAScriptListener >& Listener )
529             throw (::com::sun::star::uno::RuntimeException);
530     virtual void SAL_CALL removeVBAScriptListener(
531         const ::com::sun::star::uno::Reference< ::com::sun::star::script::vba::XVBAScriptListener >& Listener )
532             throw (::com::sun::star::uno::RuntimeException);
533     virtual void SAL_CALL broadcastVBAScriptEvent( sal_Int32 nIdentifier, const ::rtl::OUString& rModuleName )
534             throw (::com::sun::star::uno::RuntimeException);
535 };
536 
537 //============================================================================
538 
539 class LibraryContainerMethodGuard
540 {
541 private:
542     SfxLibraryContainer&    m_rContainer;
543 public:
544     LibraryContainerMethodGuard( SfxLibraryContainer& _rContainer )
545         :m_rContainer( _rContainer )
546     {
547         m_rContainer.enterMethod();
548     }
549 
550     ~LibraryContainerMethodGuard()
551     {
552         m_rContainer.leaveMethod();
553     }
554 };
555 
556 //============================================================================
557 
558 class SfxLibrary
559 	: public ::com::sun::star::container::XNameContainer
560 	, public ::com::sun::star::container::XContainer
561 	, public ::com::sun::star::util::XChangesNotifier
562 	, public ::cppu::BaseMutex
563 	, public ::cppu::OComponentHelper
564 {
565 	friend class SfxLibraryContainer;
566 	friend class SfxDialogLibraryContainer;
567 	friend class SfxScriptLibraryContainer;
568 
569     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >   mxMSF;
570 	::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >       mxSFI;
571 
572     ModifiableHelper&   mrModifiable;
573     NameContainer       maNameContainer;
574 
575 	sal_Bool mbLoaded;
576     sal_Bool mbIsModified;
577 	sal_Bool mbInitialised;
578 
579 private:
580 
581     ::rtl::OUString maLibElementFileExtension;
582 	::rtl::OUString maLibInfoFileURL;
583 	::rtl::OUString maStorageURL;
584     ::rtl::OUString maUnexpandedStorageURL;
585     ::rtl::OUString maOrignialStorageURL;
586 
587 	sal_Bool mbLink;
588 	sal_Bool mbReadOnly;
589 	sal_Bool mbReadOnlyLink;
590 	sal_Bool mbPreload;
591 
592 	sal_Bool mbPasswordProtected;
593 	sal_Bool mbPasswordVerified;
594 	sal_Bool mbDoc50Password;
595 	::rtl::OUString maPassword;
596 
597 	sal_Bool mbSharedIndexFile;
598 	sal_Bool mbExtension;
599 
600 	// Additional functionality for localisation
601 	// Provide modify state including resources
602 	virtual sal_Bool isModified( void ) = 0;
603 	virtual void storeResources( void ) = 0;
604 	virtual void storeResourcesAsURL( const ::rtl::OUString& URL, const ::rtl::OUString& NewName ) = 0;
605 	virtual void storeResourcesToURL( const ::rtl::OUString& URL,
606 		const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler ) = 0;
607 	virtual void storeResourcesToStorage( const ::com::sun::star::uno::Reference
608 		< ::com::sun::star::embed::XStorage >& xStorage ) = 0;
609 
610 protected:
611     inline  sal_Bool    implIsModified() const  { return mbIsModified; }
612             void        implSetModified( sal_Bool _bIsModified );
613 
614 private:
615     /** checks whether the lib is readonly, or a readonly link, throws an IllegalArgumentException if so
616     */
617     void    impl_checkReadOnly();
618     /** checks whether the library is loaded, throws a LibraryNotLoadedException (wrapped in a WrappedTargetException),
619         if not.
620     */
621     void    impl_checkLoaded();
622 
623 private:
624     void    impl_removeWithoutChecks( const ::rtl::OUString& _rElementName );
625 
626 public:
627 	SfxLibrary(
628         ModifiableHelper& _rModifiable,
629         const ::com::sun::star::uno::Type& aType,
630         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xMSF,
631 	    const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xSFI
632     );
633 	SfxLibrary(
634         ModifiableHelper& _rModifiable,
635         const ::com::sun::star::uno::Type& aType,
636         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xMSF,
637 	    const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xSFI,
638 		const ::rtl::OUString& aLibInfoFileURL,
639         const ::rtl::OUString&
640         aStorageURL,
641         sal_Bool ReadOnly
642     );
643 
644 	// Methods XInterface
645     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) throw( ::com::sun::star::uno::RuntimeException );
646 	virtual void SAL_CALL acquire() throw() { OComponentHelper::acquire(); }
647 	virtual void SAL_CALL release() throw() { OComponentHelper::release(); }
648 
649     // Methods XElementAccess
650     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  )
651 		throw(::com::sun::star::uno::RuntimeException);
652     virtual sal_Bool SAL_CALL hasElements(  )
653 		throw(::com::sun::star::uno::RuntimeException);
654 
655     // Methods XNameAccess
656     virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
657 		throw(::com::sun::star::container::NoSuchElementException,
658 			  ::com::sun::star::lang::WrappedTargetException,
659 			  ::com::sun::star::uno::RuntimeException);
660     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  )
661 		throw(::com::sun::star::uno::RuntimeException);
662     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
663 		throw(::com::sun::star::uno::RuntimeException);
664 
665     // Methods XNameReplace
666     virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
667 		throw(::com::sun::star::lang::IllegalArgumentException,
668 			  ::com::sun::star::container::NoSuchElementException,
669 			  ::com::sun::star::lang::WrappedTargetException,
670 			  ::com::sun::star::uno::RuntimeException);
671 
672     // Methods XNameContainer
673     virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
674 		throw(::com::sun::star::lang::IllegalArgumentException,
675 			  ::com::sun::star::container::ElementExistException,
676 			  ::com::sun::star::lang::WrappedTargetException,
677 			  ::com::sun::star::uno::RuntimeException);
678     virtual void SAL_CALL removeByName( const ::rtl::OUString& Name )
679 		throw(::com::sun::star::container::NoSuchElementException,
680 			  ::com::sun::star::lang::WrappedTargetException,
681 			  ::com::sun::star::uno::RuntimeException);
682 
683 	// XTypeProvider
684     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  )
685 		throw( ::com::sun::star::uno::RuntimeException );
686     ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId(  )
687 		throw( ::com::sun::star::uno::RuntimeException );
688 
689 	// Methods XContainer
690 	virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference<
691 		::com::sun::star::container::XContainerListener >& xListener )
692 			throw (::com::sun::star::uno::RuntimeException);
693 	virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference<
694 		::com::sun::star::container::XContainerListener >& xListener )
695 			throw (::com::sun::star::uno::RuntimeException);
696 
697     // Methods XChangesNotifier
698     virtual void SAL_CALL addChangesListener( const ::com::sun::star::uno::Reference<
699         ::com::sun::star::util::XChangesListener >& xListener )
700             throw (::com::sun::star::uno::RuntimeException);
701     virtual void SAL_CALL removeChangesListener( const ::com::sun::star::uno::Reference<
702 		::com::sun::star::util::XChangesListener >& xListener )
703             throw (::com::sun::star::uno::RuntimeException);
704 
705 public:
706     struct LibraryContainerAccess { friend class SfxLibraryContainer; private: LibraryContainerAccess() { } };
707     void    removeElementWithoutChecks( const ::rtl::OUString& _rElementName, LibraryContainerAccess )
708     {
709         impl_removeWithoutChecks( _rElementName );
710     }
711 
712 protected:
713 	virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const = 0;
714 };
715 
716 //============================================================================
717 
718 class ScriptSubPackageIterator
719 {
720 	com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > m_xMainPackage;
721 
722 	bool m_bIsValid;
723 	bool m_bIsBundle;
724 
725 	com::sun::star::uno::Sequence< com::sun::star::uno::Reference
726 		< com::sun::star::deployment::XPackage > > m_aSubPkgSeq;
727 	sal_Int32 m_nSubPkgCount;
728 	sal_Int32 m_iNextSubPkg;
729 
730 	com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >
731 		implDetectScriptPackage( const com::sun::star::uno::Reference
732 			< com::sun::star::deployment::XPackage > xPackage, bool& rbPureDialogLib );
733 
734 public:
735 	ScriptSubPackageIterator( com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xMainPackage );
736 
737 	com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > getNextScriptSubPackage( bool& rbPureDialogLib );
738 };
739 
740 //============================================================================
741 
742 class ScriptExtensionIterator
743 {
744 public:
745 	ScriptExtensionIterator( void );
746 	rtl::OUString nextBasicOrDialogLibrary( bool& rbPureDialogLib );
747 
748 private:
749 	com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > implGetScriptPackageFromPackage
750 		( const com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage,
751 		  bool& rbPureDialogLib );
752 
753 protected:
754 	com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >
755 		implGetNextUserScriptPackage( bool& rbPureDialogLib );
756 	com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >
757 		implGetNextSharedScriptPackage( bool& rbPureDialogLib );
758 	com::sun::star::uno::Reference< com::sun::star::deployment::XPackage >
759 		implGetNextBundledScriptPackage( bool& rbPureDialogLib );
760 
761 	com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
762 
763     enum IteratorState
764     {
765     	USER_EXTENSIONS,
766     	SHARED_EXTENSIONS,
767         BUNDLED_EXTENSIONS,
768     	END_REACHED
769     } m_eState;
770 
771 	com::sun::star::uno::Sequence< com::sun::star::uno::Reference
772 		< com::sun::star::deployment::XPackage > > m_aUserPackagesSeq;
773 	bool m_bUserPackagesLoaded;
774 
775 	com::sun::star::uno::Sequence< com::sun::star::uno::Reference
776 		< com::sun::star::deployment::XPackage > > m_aSharedPackagesSeq;
777 	bool m_bSharedPackagesLoaded;
778 
779   	com::sun::star::uno::Sequence< com::sun::star::uno::Reference
780 		< com::sun::star::deployment::XPackage > > m_aBundledPackagesSeq;
781 	bool m_bBundledPackagesLoaded;
782 
783 	int m_iUserPackage;
784 	int m_iSharedPackage;
785    	int m_iBundledPackage;
786 
787 	ScriptSubPackageIterator* m_pScriptSubPackageIterator;
788 
789 }; // end class ScriptExtensionIterator
790 
791 //============================================================================
792 
793 }	// namespace basic
794 
795 #endif
796 
797