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