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