Debian Codegraph @

basic/source/inc/scriptcont.hxx

raw
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 #pragma once
21
22 #include "namecont.hxx"
23 #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
24
25 namespace basic
26 {
27
28
29 class SfxScriptLibraryContainer final : public SfxLibraryContainer
30 {
31 css::uno::Reference< css::container::XNameAccess > mxCodeNameAccess;
32
33 // Methods to distinguish between different library types
34 virtual rtl::Reference<SfxLibrary> implCreateLibrary( const OUString& aName ) override;
35 virtual rtl::Reference<SfxLibrary> implCreateLibraryLink
36 ( const OUString& aName, const OUString& aLibInfoFileURL,
37 const OUString& StorageURL, bool ReadOnly ) override;
38 virtual css::uno::Any createEmptyLibraryElement() override;
39 virtual bool isLibraryElementValid(const css::uno::Any& rElement) const override;
40 virtual void writeLibraryElement
41 (
42 const css::uno::Reference< css::container::XNameContainer>& xLibrary,
43 const OUString& aElementName,
44 const css::uno::Reference< css::io::XOutputStream >& xOutput
45 ) override;
46
47 virtual css::uno::Any importLibraryElement
48 (
49 const css::uno::Reference< css::container::XNameContainer>& xLibrary,
50 const OUString& aElementName,
51 const OUString& aFile,
52 const css::uno::Reference< css::io::XInputStream >& xElementStream ) override;
53
54 virtual void importFromOldStorage( const OUString& aFile ) override;
55
56 virtual rtl::Reference<SfxLibraryContainer> createInstanceImpl() override;
57
58
59 // Password encryption
60 virtual bool implStorePasswordLibrary( SfxLibrary* pLib, const OUString& aName,
61 const css::uno::Reference< css::embed::XStorage>& xStorage, const css::uno::Reference< css::task::XInteractionHandler >& Handler ) override;
62
63 // New variant for library export
64 virtual bool implStorePasswordLibrary( SfxLibrary* pLib, const OUString& aName,
65 const css::uno::Reference< css::embed::XStorage >& xStorage,
66 const OUString& aTargetURL,
67 const css::uno::Reference< css::ucb::XSimpleFileAccess3 >& rToUseSFI, const css::uno::Reference< css::task::XInteractionHandler >& Handler ) override;
68
69 virtual bool implLoadPasswordLibrary( SfxLibrary* pLib, const OUString& Name,
70 bool bVerifyPasswordOnly,
71 std::unique_lock<std::mutex>& guard ) override;
72
73 virtual void onNewRootStorage() override;
74
75
76 virtual OUString getInfoFileName() const override;
77 virtual OUString getOldInfoFileName() const override;
78 virtual OUString getLibElementFileExtension() const override;
79 virtual OUString getLibrariesDir() const override;
80
81 public:
82 SfxScriptLibraryContainer();
83 SfxScriptLibraryContainer( const css::uno::Reference< css::embed::XStorage >& xStorage );
84
85
86 // Methods XLibraryContainerPassword
87 virtual sal_Bool SAL_CALL isLibraryPasswordProtected( const OUString& Name ) override;
88 virtual sal_Bool SAL_CALL isLibraryPasswordVerified( const OUString& Name ) override;
89 virtual sal_Bool SAL_CALL verifyLibraryPassword( const OUString& Name, const OUString& Password ) override;
90 virtual void SAL_CALL changeLibraryPassword( const OUString& Name,
91 const OUString& OldPassword, const OUString& NewPassword ) override;
92 // XLibraryQueryExecutable
93 virtual sal_Bool SAL_CALL HasExecutableCode(const OUString&) override;
94 // Methods XServiceInfo
95 virtual OUString SAL_CALL getImplementationName( ) override;
96 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
97
98 // Library password handling for 5.0 documents
99 void setLibraryPassword( const OUString& rLibraryName, const OUString& rPassword );
100 };
101
102
103 typedef std::unordered_map< OUString, css::script::ModuleInfo > ModuleInfoMap;
104
105 typedef cppu::ImplInheritanceHelper< SfxLibrary, css::script::vba::XVBAModuleInfo > SfxScriptLibrary_BASE;
106
107 class SfxScriptLibrary final : public SfxScriptLibrary_BASE
108 {
109 friend class SfxScriptLibraryContainer;
110
111 typedef std::unordered_map< OUString, css::script::ModuleInfo > ModuleInfoMap;
112
113 bool mbLoadedSource;
114 bool mbLoadedBinary;
115 ModuleInfoMap mModuleInfo;
116
117 // Provide modify state including resources
118 virtual bool isModified() override;
119 virtual void storeResources() override;
120 virtual void storeResourcesAsURL( const OUString& URL, const OUString& NewName ) override;
121 virtual void storeResourcesToURL( const OUString& URL,
122 const css::uno::Reference< css::task::XInteractionHandler >& xHandler ) override;
123 virtual void storeResourcesToStorage( const css::uno::Reference< css::embed::XStorage >& xStorage ) override;
124 virtual bool isLoadedStorable() override;
125
126 public:
127 SfxScriptLibrary
128 (
129 ModifiableHelper& _rModifiable,
130 const css::uno::Reference< css::ucb::XSimpleFileAccess3 >& xSFI
131 );
132
133 SfxScriptLibrary
134 (
135 ModifiableHelper& _rModifiable,
136 const css::uno::Reference< css::ucb::XSimpleFileAccess3 >& xSFI,
137 const OUString& aLibInfoFileURL, const OUString& aStorageURL, bool ReadOnly
138 );
139
140 // XVBAModuleInfo
141 virtual css::script::ModuleInfo SAL_CALL getModuleInfo( const OUString& ModuleName ) override;
142 virtual sal_Bool SAL_CALL hasModuleInfo( const OUString& ModuleName ) override;
143 virtual void SAL_CALL insertModuleInfo( const OUString& ModuleName, const css::script::ModuleInfo& ModuleInfo ) override;
144 virtual void SAL_CALL removeModuleInfo( const OUString& ModuleName ) override;
145
146 static bool containsValidModule( const css::uno::Any& _rElement );
147
148 private:
149 virtual bool isLibraryElementValid(const css::uno::Any& rElement) const override;
150 };
151
152
153 } // namespace basic
154
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */