xref: /aoo42x/main/basic/source/inc/scriptcont.hxx (revision 234bd5c5)
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_SCRIPTCONTAINER_HXX
25 #define BASIC_SCRIPTCONTAINER_HXX
26 
27 #include "namecont.hxx"
28 #include <basic/basmgr.hxx>
29 #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
30 #include <comphelper/uno3.hxx>
31 
32 class BasicManager;
33 
34 namespace basic
35 {
36 
37 //============================================================================
38 
39 class SfxScriptLibraryContainer : public SfxLibraryContainer, public OldBasicPassword
40 {
41 	::rtl::OUString maScriptLanguage;
42     ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > mxCodeNameAccess;
43 
44 	// Methods to distinguish between deffirent library types
45 	virtual SfxLibrary* SAL_CALL implCreateLibrary( const ::rtl::OUString& aName );
46     virtual SfxLibrary* SAL_CALL implCreateLibraryLink
47 		( const ::rtl::OUString& aName, const ::rtl::OUString& aLibInfoFileURL,
48           const ::rtl::OUString& StorageURL, sal_Bool ReadOnly );
49 	virtual ::com::sun::star::uno::Any SAL_CALL createEmptyLibraryElement( void );
50 	virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const;
51 	virtual void SAL_CALL writeLibraryElement
52 	(
53 		const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& xLibrary,
54 		const ::rtl::OUString& aElementName,
55 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutput
56 	)
57 		throw(::com::sun::star::uno::Exception);
58 
59 	virtual ::com::sun::star::uno::Any SAL_CALL importLibraryElement
60 	(
61 		const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& xLibrary,
62 		const ::rtl::OUString& aElementName,
63 		const ::rtl::OUString& aFile,
64 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xElementStream );
65 
66 	virtual void SAL_CALL importFromOldStorage( const ::rtl::OUString& aFile );
67 
68     virtual SfxLibraryContainer* createInstanceImpl( void );
69 
70 
71     // Password encryption
72 	virtual sal_Bool implStorePasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName,
73         				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage>& xStorage, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler );
74 
75 	// New variant for library export
76 	virtual sal_Bool implStorePasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName,
77         				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
78 						const ::rtl::OUString& aTargetURL,
79 						const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler );
80 
81     virtual sal_Bool implLoadPasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& Name,
82         sal_Bool bVerifyPasswordOnly=false )
83 		    throw(::com::sun::star::lang::WrappedTargetException,
84 			      ::com::sun::star::uno::RuntimeException);
85 
86 	virtual void onNewRootStorage();
87 
88 
89     // OldBasicPassword interface
90     virtual void setLibraryPassword( const String& rLibraryName, const String& rPassword );
91     virtual String getLibraryPassword( const String& rLibraryName );
92     virtual void clearLibraryPassword( const String& rLibraryName );
93     virtual sal_Bool hasLibraryPassword( const String& rLibraryName );
94 
95     virtual const sal_Char* SAL_CALL    getInfoFileName() const;
96     virtual const sal_Char* SAL_CALL    getOldInfoFileName() const;
97     virtual const sal_Char* SAL_CALL    getLibElementFileExtension() const;
98     virtual const sal_Char* SAL_CALL    getLibrariesDir() const;
99 
100 public:
101 	SfxScriptLibraryContainer( void );
102 	SfxScriptLibraryContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage );
103 
104 
105     // Methods XLibraryContainerPassword
106     virtual sal_Bool SAL_CALL isLibraryPasswordProtected( const ::rtl::OUString& Name )
107         throw (::com::sun::star::container::NoSuchElementException,
108                ::com::sun::star::uno::RuntimeException);
109     virtual sal_Bool SAL_CALL isLibraryPasswordVerified( const ::rtl::OUString& Name )
110         throw (::com::sun::star::lang::IllegalArgumentException,
111                ::com::sun::star::container::NoSuchElementException,
112                ::com::sun::star::uno::RuntimeException);
113     virtual sal_Bool SAL_CALL verifyLibraryPassword( const ::rtl::OUString& Name, const ::rtl::OUString& Password )
114         throw (::com::sun::star::lang::IllegalArgumentException,
115                ::com::sun::star::container::NoSuchElementException,
116                ::com::sun::star::uno::RuntimeException);
117     virtual void SAL_CALL changeLibraryPassword( const ::rtl::OUString& Name,
118         const ::rtl::OUString& OldPassword, const ::rtl::OUString& NewPassword )
119         throw (::com::sun::star::lang::IllegalArgumentException,
120                ::com::sun::star::container::NoSuchElementException,
121                ::com::sun::star::uno::RuntimeException);
122 
123     // Methods XServiceInfo
124     virtual ::rtl::OUString SAL_CALL getImplementationName( )
125         throw (::com::sun::star::uno::RuntimeException);
126     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
127         throw (::com::sun::star::uno::RuntimeException);
128 
129 	// Service
130 	static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static();
131 	static ::rtl::OUString getImplementationName_static();
132 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create
133         ( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xServiceManager )
134             throw( ::com::sun::star::uno::Exception );
135 
136 };
137 
138 //============================================================================
139 
140 typedef ::cppu::ImplHelper1< ::com::sun::star::script::vba::XVBAModuleInfo > SfxScriptLibrary_BASE;
141 
142 class SfxScriptLibrary : public SfxLibrary, public SfxScriptLibrary_BASE
143 {
144     friend class SfxScriptLibraryContainer;
145 
146     typedef std::hash_map< ::rtl::OUString, ::com::sun::star::script::ModuleInfo, ::rtl::OUStringHash > ModuleInfoMap;
147 
148 	sal_Bool mbLoadedSource;
149 	sal_Bool mbLoadedBinary;
150     ModuleInfoMap mModuleInfos;
151 
152 	// Provide modify state including resources
153 	virtual sal_Bool isModified( void );
154 	virtual void storeResources( void );
155 	virtual void storeResourcesAsURL( const ::rtl::OUString& URL, const ::rtl::OUString& NewName );
156 	virtual void storeResourcesToURL( const ::rtl::OUString& URL,
157 		const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler );
158 	virtual void storeResourcesToStorage( const ::com::sun::star::uno::Reference
159 		< ::com::sun::star::embed::XStorage >& xStorage );
160 
161 public:
162 	SfxScriptLibrary
163     (
164         ModifiableHelper& _rModifiable,
165         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xMSF,
166 	    const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xSFI
167     );
168 
169 	SfxScriptLibrary
170     (
171         ModifiableHelper& _rModifiable,
172         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xMSF,
173 	    const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xSFI,
174         const ::rtl::OUString& aLibInfoFileURL, const ::rtl::OUString& aStorageURL, sal_Bool ReadOnly
175     );
176 
177     DECLARE_XINTERFACE()
178     DECLARE_XTYPEPROVIDER()
179 
180     // XVBAModuleInfo
181     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);
182     virtual sal_Bool SAL_CALL hasModuleInfo( const ::rtl::OUString& ModuleName ) throw (::com::sun::star::uno::RuntimeException);
183     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);
184     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);
185 
186     static bool containsValidModule( const ::com::sun::star::uno::Any& _rElement );
187 
188 protected:
189 	virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const;
190 };
191 
192 //============================================================================
193 
194 }   // namespace basic
195 
196 #endif
197 
198