xref: /aoo42x/main/basic/source/inc/scriptcont.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef BASIC_SCRIPTCONTAINER_HXX
29 #define BASIC_SCRIPTCONTAINER_HXX
30 
31 #include "namecont.hxx"
32 #include <basic/basmgr.hxx>
33 #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
34 #include <comphelper/uno3.hxx>
35 
36 class BasicManager;
37 
38 namespace basic
39 {
40 
41 //============================================================================
42 
43 class SfxScriptLibraryContainer : public SfxLibraryContainer, public OldBasicPassword
44 {
45 	::rtl::OUString maScriptLanguage;
46     ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > mxCodeNameAccess;
47 
48 	// Methods to distinguish between deffirent library types
49 	virtual SfxLibrary* SAL_CALL implCreateLibrary( const ::rtl::OUString& aName );
50     virtual SfxLibrary* SAL_CALL implCreateLibraryLink
51 		( const ::rtl::OUString& aName, const ::rtl::OUString& aLibInfoFileURL,
52           const ::rtl::OUString& StorageURL, sal_Bool ReadOnly );
53 	virtual ::com::sun::star::uno::Any SAL_CALL createEmptyLibraryElement( void );
54 	virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const;
55 	virtual void SAL_CALL writeLibraryElement
56 	(
57 		const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& xLibrary,
58 		const ::rtl::OUString& aElementName,
59 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutput
60 	)
61 		throw(::com::sun::star::uno::Exception);
62 
63 	virtual ::com::sun::star::uno::Any SAL_CALL importLibraryElement
64 	(
65 		const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& xLibrary,
66 		const ::rtl::OUString& aElementName,
67 		const ::rtl::OUString& aFile,
68 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xElementStream );
69 
70 	virtual void SAL_CALL importFromOldStorage( const ::rtl::OUString& aFile );
71 
72     virtual SfxLibraryContainer* createInstanceImpl( void );
73 
74 
75     // Password encryption
76 	virtual sal_Bool implStorePasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName,
77         				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage>& xStorage, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler );
78 
79 	// New variant for library export
80 	virtual sal_Bool implStorePasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName,
81         				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
82 						const ::rtl::OUString& aTargetURL,
83 						const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler );
84 
85     virtual sal_Bool implLoadPasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& Name,
86         sal_Bool bVerifyPasswordOnly=false )
87 		    throw(::com::sun::star::lang::WrappedTargetException,
88 			      ::com::sun::star::uno::RuntimeException);
89 
90 	virtual void onNewRootStorage();
91 
92 
93     // OldBasicPassword interface
94     virtual void setLibraryPassword( const String& rLibraryName, const String& rPassword );
95     virtual String getLibraryPassword( const String& rLibraryName );
96     virtual void clearLibraryPassword( const String& rLibraryName );
97     virtual sal_Bool hasLibraryPassword( const String& rLibraryName );
98 
99     virtual const sal_Char* SAL_CALL    getInfoFileName() const;
100     virtual const sal_Char* SAL_CALL    getOldInfoFileName() const;
101     virtual const sal_Char* SAL_CALL    getLibElementFileExtension() const;
102     virtual const sal_Char* SAL_CALL    getLibrariesDir() const;
103 
104 public:
105 	SfxScriptLibraryContainer( void );
106 	SfxScriptLibraryContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage );
107 
108 
109     // Methods XLibraryContainerPassword
110     virtual sal_Bool SAL_CALL isLibraryPasswordProtected( const ::rtl::OUString& Name )
111         throw (::com::sun::star::container::NoSuchElementException,
112                ::com::sun::star::uno::RuntimeException);
113     virtual sal_Bool SAL_CALL isLibraryPasswordVerified( const ::rtl::OUString& Name )
114         throw (::com::sun::star::lang::IllegalArgumentException,
115                ::com::sun::star::container::NoSuchElementException,
116                ::com::sun::star::uno::RuntimeException);
117     virtual sal_Bool SAL_CALL verifyLibraryPassword( const ::rtl::OUString& Name, const ::rtl::OUString& Password )
118         throw (::com::sun::star::lang::IllegalArgumentException,
119                ::com::sun::star::container::NoSuchElementException,
120                ::com::sun::star::uno::RuntimeException);
121     virtual void SAL_CALL changeLibraryPassword( const ::rtl::OUString& Name,
122         const ::rtl::OUString& OldPassword, const ::rtl::OUString& NewPassword )
123         throw (::com::sun::star::lang::IllegalArgumentException,
124                ::com::sun::star::container::NoSuchElementException,
125                ::com::sun::star::uno::RuntimeException);
126 
127     // Methods XServiceInfo
128     virtual ::rtl::OUString SAL_CALL getImplementationName( )
129         throw (::com::sun::star::uno::RuntimeException);
130     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
131         throw (::com::sun::star::uno::RuntimeException);
132 
133 	// Service
134 	static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static();
135 	static ::rtl::OUString getImplementationName_static();
136 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create
137         ( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xServiceManager )
138             throw( ::com::sun::star::uno::Exception );
139 
140 };
141 
142 //============================================================================
143 
144 typedef ::cppu::ImplHelper1< ::com::sun::star::script::vba::XVBAModuleInfo > SfxScriptLibrary_BASE;
145 
146 class SfxScriptLibrary : public SfxLibrary, public SfxScriptLibrary_BASE
147 {
148     friend class SfxScriptLibraryContainer;
149 
150     typedef std::hash_map< ::rtl::OUString, ::com::sun::star::script::ModuleInfo, ::rtl::OUStringHash > ModuleInfoMap;
151 
152 	sal_Bool mbLoadedSource;
153 	sal_Bool mbLoadedBinary;
154     ModuleInfoMap mModuleInfos;
155 
156 	// Provide modify state including resources
157 	virtual sal_Bool isModified( void );
158 	virtual void storeResources( void );
159 	virtual void storeResourcesAsURL( const ::rtl::OUString& URL, const ::rtl::OUString& NewName );
160 	virtual void storeResourcesToURL( const ::rtl::OUString& URL,
161 		const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler );
162 	virtual void storeResourcesToStorage( const ::com::sun::star::uno::Reference
163 		< ::com::sun::star::embed::XStorage >& xStorage );
164 
165 public:
166 	SfxScriptLibrary
167     (
168         ModifiableHelper& _rModifiable,
169         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xMSF,
170 	    const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xSFI
171     );
172 
173 	SfxScriptLibrary
174     (
175         ModifiableHelper& _rModifiable,
176         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xMSF,
177 	    const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xSFI,
178         const ::rtl::OUString& aLibInfoFileURL, const ::rtl::OUString& aStorageURL, sal_Bool ReadOnly
179     );
180 
181     DECLARE_XINTERFACE()
182     DECLARE_XTYPEPROVIDER()
183 
184     // XVBAModuleInfo
185     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);
186     virtual sal_Bool SAL_CALL hasModuleInfo( const ::rtl::OUString& ModuleName ) throw (::com::sun::star::uno::RuntimeException);
187     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);
188     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);
189 
190     static bool containsValidModule( const ::com::sun::star::uno::Any& _rElement );
191 
192 protected:
193 	virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const;
194 };
195 
196 //============================================================================
197 
198 }   // namespace basic
199 
200 #endif
201 
202