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