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