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