xref: /aoo42x/main/basic/source/inc/scriptcont.hxx (revision 234bd5c5)
1*234bd5c5SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*234bd5c5SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*234bd5c5SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*234bd5c5SAndrew Rist  * distributed with this work for additional information
6*234bd5c5SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*234bd5c5SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*234bd5c5SAndrew Rist  * "License"); you may not use this file except in compliance
9*234bd5c5SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*234bd5c5SAndrew Rist  *
11*234bd5c5SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*234bd5c5SAndrew Rist  *
13*234bd5c5SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*234bd5c5SAndrew Rist  * software distributed under the License is distributed on an
15*234bd5c5SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*234bd5c5SAndrew Rist  * KIND, either express or implied.  See the License for the
17*234bd5c5SAndrew Rist  * specific language governing permissions and limitations
18*234bd5c5SAndrew Rist  * under the License.
19*234bd5c5SAndrew Rist  *
20*234bd5c5SAndrew Rist  *************************************************************/
21*234bd5c5SAndrew Rist 
22*234bd5c5SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef BASIC_SCRIPTCONTAINER_HXX
25cdf0e10cSrcweir #define BASIC_SCRIPTCONTAINER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "namecont.hxx"
28cdf0e10cSrcweir #include <basic/basmgr.hxx>
29cdf0e10cSrcweir #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
30cdf0e10cSrcweir #include <comphelper/uno3.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir class BasicManager;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace basic
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //============================================================================
38cdf0e10cSrcweir 
39cdf0e10cSrcweir class SfxScriptLibraryContainer : public SfxLibraryContainer, public OldBasicPassword
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 	::rtl::OUString maScriptLanguage;
42cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > mxCodeNameAccess;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 	// Methods to distinguish between deffirent library types
45cdf0e10cSrcweir 	virtual SfxLibrary* SAL_CALL implCreateLibrary( const ::rtl::OUString& aName );
46cdf0e10cSrcweir     virtual SfxLibrary* SAL_CALL implCreateLibraryLink
47cdf0e10cSrcweir 		( const ::rtl::OUString& aName, const ::rtl::OUString& aLibInfoFileURL,
48cdf0e10cSrcweir           const ::rtl::OUString& StorageURL, sal_Bool ReadOnly );
49cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Any SAL_CALL createEmptyLibraryElement( void );
50cdf0e10cSrcweir 	virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const;
51cdf0e10cSrcweir 	virtual void SAL_CALL writeLibraryElement
52cdf0e10cSrcweir 	(
53cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& xLibrary,
54cdf0e10cSrcweir 		const ::rtl::OUString& aElementName,
55cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutput
56cdf0e10cSrcweir 	)
57cdf0e10cSrcweir 		throw(::com::sun::star::uno::Exception);
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Any SAL_CALL importLibraryElement
60cdf0e10cSrcweir 	(
61cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& xLibrary,
62cdf0e10cSrcweir 		const ::rtl::OUString& aElementName,
63cdf0e10cSrcweir 		const ::rtl::OUString& aFile,
64cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xElementStream );
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	virtual void SAL_CALL importFromOldStorage( const ::rtl::OUString& aFile );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     virtual SfxLibraryContainer* createInstanceImpl( void );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     // Password encryption
72cdf0e10cSrcweir 	virtual sal_Bool implStorePasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName,
73cdf0e10cSrcweir         				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage>& xStorage, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	// New variant for library export
76cdf0e10cSrcweir 	virtual sal_Bool implStorePasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName,
77cdf0e10cSrcweir         				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
78cdf0e10cSrcweir 						const ::rtl::OUString& aTargetURL,
79cdf0e10cSrcweir 						const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     virtual sal_Bool implLoadPasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& Name,
82cdf0e10cSrcweir         sal_Bool bVerifyPasswordOnly=false )
83cdf0e10cSrcweir 		    throw(::com::sun::star::lang::WrappedTargetException,
84cdf0e10cSrcweir 			      ::com::sun::star::uno::RuntimeException);
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	virtual void onNewRootStorage();
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     // OldBasicPassword interface
90cdf0e10cSrcweir     virtual void setLibraryPassword( const String& rLibraryName, const String& rPassword );
91cdf0e10cSrcweir     virtual String getLibraryPassword( const String& rLibraryName );
92cdf0e10cSrcweir     virtual void clearLibraryPassword( const String& rLibraryName );
93cdf0e10cSrcweir     virtual sal_Bool hasLibraryPassword( const String& rLibraryName );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     virtual const sal_Char* SAL_CALL    getInfoFileName() const;
96cdf0e10cSrcweir     virtual const sal_Char* SAL_CALL    getOldInfoFileName() const;
97cdf0e10cSrcweir     virtual const sal_Char* SAL_CALL    getLibElementFileExtension() const;
98cdf0e10cSrcweir     virtual const sal_Char* SAL_CALL    getLibrariesDir() const;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir public:
101cdf0e10cSrcweir 	SfxScriptLibraryContainer( void );
102cdf0e10cSrcweir 	SfxScriptLibraryContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     // Methods XLibraryContainerPassword
106cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isLibraryPasswordProtected( const ::rtl::OUString& Name )
107cdf0e10cSrcweir         throw (::com::sun::star::container::NoSuchElementException,
108cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
109cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isLibraryPasswordVerified( const ::rtl::OUString& Name )
110cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
111cdf0e10cSrcweir                ::com::sun::star::container::NoSuchElementException,
112cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
113cdf0e10cSrcweir     virtual sal_Bool SAL_CALL verifyLibraryPassword( const ::rtl::OUString& Name, const ::rtl::OUString& Password )
114cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
115cdf0e10cSrcweir                ::com::sun::star::container::NoSuchElementException,
116cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
117cdf0e10cSrcweir     virtual void SAL_CALL changeLibraryPassword( const ::rtl::OUString& Name,
118cdf0e10cSrcweir         const ::rtl::OUString& OldPassword, const ::rtl::OUString& NewPassword )
119cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
120cdf0e10cSrcweir                ::com::sun::star::container::NoSuchElementException,
121cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     // Methods XServiceInfo
124cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL getImplementationName( )
125cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
126cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
127cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	// Service
130cdf0e10cSrcweir 	static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static();
131cdf0e10cSrcweir 	static ::rtl::OUString getImplementationName_static();
132cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create
133cdf0e10cSrcweir         ( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xServiceManager )
134cdf0e10cSrcweir             throw( ::com::sun::star::uno::Exception );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir };
137cdf0e10cSrcweir 
138cdf0e10cSrcweir //============================================================================
139cdf0e10cSrcweir 
140cdf0e10cSrcweir typedef ::cppu::ImplHelper1< ::com::sun::star::script::vba::XVBAModuleInfo > SfxScriptLibrary_BASE;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir class SfxScriptLibrary : public SfxLibrary, public SfxScriptLibrary_BASE
143cdf0e10cSrcweir {
144cdf0e10cSrcweir     friend class SfxScriptLibraryContainer;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     typedef std::hash_map< ::rtl::OUString, ::com::sun::star::script::ModuleInfo, ::rtl::OUStringHash > ModuleInfoMap;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	sal_Bool mbLoadedSource;
149cdf0e10cSrcweir 	sal_Bool mbLoadedBinary;
150cdf0e10cSrcweir     ModuleInfoMap mModuleInfos;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	// Provide modify state including resources
153cdf0e10cSrcweir 	virtual sal_Bool isModified( void );
154cdf0e10cSrcweir 	virtual void storeResources( void );
155cdf0e10cSrcweir 	virtual void storeResourcesAsURL( const ::rtl::OUString& URL, const ::rtl::OUString& NewName );
156cdf0e10cSrcweir 	virtual void storeResourcesToURL( const ::rtl::OUString& URL,
157cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler );
158cdf0e10cSrcweir 	virtual void storeResourcesToStorage( const ::com::sun::star::uno::Reference
159cdf0e10cSrcweir 		< ::com::sun::star::embed::XStorage >& xStorage );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir public:
162cdf0e10cSrcweir 	SfxScriptLibrary
163cdf0e10cSrcweir     (
164cdf0e10cSrcweir         ModifiableHelper& _rModifiable,
165cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xMSF,
166cdf0e10cSrcweir 	    const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xSFI
167cdf0e10cSrcweir     );
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	SfxScriptLibrary
170cdf0e10cSrcweir     (
171cdf0e10cSrcweir         ModifiableHelper& _rModifiable,
172cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xMSF,
173cdf0e10cSrcweir 	    const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xSFI,
174cdf0e10cSrcweir         const ::rtl::OUString& aLibInfoFileURL, const ::rtl::OUString& aStorageURL, sal_Bool ReadOnly
175cdf0e10cSrcweir     );
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     DECLARE_XINTERFACE()
178cdf0e10cSrcweir     DECLARE_XTYPEPROVIDER()
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     // XVBAModuleInfo
181cdf0e10cSrcweir     virtual ::com::sun::star::script::ModuleInfo SAL_CALL getModuleInfo( const ::rtl::OUString& ModuleName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
182cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasModuleInfo( const ::rtl::OUString& ModuleName ) throw (::com::sun::star::uno::RuntimeException);
183cdf0e10cSrcweir     virtual void SAL_CALL insertModuleInfo( const ::rtl::OUString& ModuleName, const ::com::sun::star::script::ModuleInfo& ModuleInfo ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
184cdf0e10cSrcweir     virtual void SAL_CALL removeModuleInfo( const ::rtl::OUString& ModuleName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     static bool containsValidModule( const ::com::sun::star::uno::Any& _rElement );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir protected:
189cdf0e10cSrcweir 	virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const;
190cdf0e10cSrcweir };
191cdf0e10cSrcweir 
192cdf0e10cSrcweir //============================================================================
193cdf0e10cSrcweir 
194cdf0e10cSrcweir }   // namespace basic
195cdf0e10cSrcweir 
196cdf0e10cSrcweir #endif
197cdf0e10cSrcweir 
198