1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include "namecont.hxx"
23 #include <basic/basmgr.hxx>
24 #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
25 #include <comphelper/uno3.hxx>
26 #include <cppuhelper/implbase1.hxx>
32 class SfxScriptLibraryContainer final
: public SfxLibraryContainer
, public OldBasicPassword
34 css::uno::Reference
< css::container::XNameAccess
> mxCodeNameAccess
;
36 // Methods to distinguish between different library types
37 virtual rtl::Reference
<SfxLibrary
> implCreateLibrary( const OUString
& aName
) override
;
38 virtual rtl::Reference
<SfxLibrary
> implCreateLibraryLink
39 ( const OUString
& aName
, const OUString
& aLibInfoFileURL
,
40 const OUString
& StorageURL
, bool ReadOnly
) override
;
41 virtual css::uno::Any
createEmptyLibraryElement() override
;
42 virtual bool isLibraryElementValid(const css::uno::Any
& rElement
) const override
;
43 virtual void writeLibraryElement
45 const css::uno::Reference
< css::container::XNameContainer
>& xLibrary
,
46 const OUString
& aElementName
,
47 const css::uno::Reference
< css::io::XOutputStream
>& xOutput
50 virtual css::uno::Any importLibraryElement
52 const css::uno::Reference
< css::container::XNameContainer
>& xLibrary
,
53 const OUString
& aElementName
,
54 const OUString
& aFile
,
55 const css::uno::Reference
< css::io::XInputStream
>& xElementStream
) override
;
57 virtual void importFromOldStorage( const OUString
& aFile
) override
;
59 virtual rtl::Reference
<SfxLibraryContainer
> createInstanceImpl() override
;
62 // Password encryption
63 virtual bool implStorePasswordLibrary( SfxLibrary
* pLib
, const OUString
& aName
,
64 const css::uno::Reference
< css::embed::XStorage
>& xStorage
, const css::uno::Reference
< css::task::XInteractionHandler
>& Handler
) override
;
66 // New variant for library export
67 virtual bool implStorePasswordLibrary( SfxLibrary
* pLib
, const OUString
& aName
,
68 const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
69 const OUString
& aTargetURL
,
70 const css::uno::Reference
< css::ucb::XSimpleFileAccess3
>& rToUseSFI
, const css::uno::Reference
< css::task::XInteractionHandler
>& Handler
) override
;
72 virtual bool implLoadPasswordLibrary( SfxLibrary
* pLib
, const OUString
& Name
,
73 bool bVerifyPasswordOnly
=false ) override
;
75 virtual void onNewRootStorage() override
;
78 // OldBasicPassword interface
79 virtual void setLibraryPassword( const OUString
& rLibraryName
, const OUString
& rPassword
) override
;
81 virtual const char* getInfoFileName() const override
;
82 virtual const char* getOldInfoFileName() const override
;
83 virtual const char* getLibElementFileExtension() const override
;
84 virtual const char* getLibrariesDir() const override
;
87 SfxScriptLibraryContainer();
88 SfxScriptLibraryContainer( const css::uno::Reference
< css::embed::XStorage
>& xStorage
);
91 // Methods XLibraryContainerPassword
92 virtual sal_Bool SAL_CALL
isLibraryPasswordProtected( const OUString
& Name
) override
;
93 virtual sal_Bool SAL_CALL
isLibraryPasswordVerified( const OUString
& Name
) override
;
94 virtual sal_Bool SAL_CALL
verifyLibraryPassword( const OUString
& Name
, const OUString
& Password
) override
;
95 virtual void SAL_CALL
changeLibraryPassword( const OUString
& Name
,
96 const OUString
& OldPassword
, const OUString
& NewPassword
) override
;
97 // XLibraryQueryExecutable
98 virtual sal_Bool SAL_CALL
HasExecutableCode(const OUString
&) override
;
99 // Methods XServiceInfo
100 virtual OUString SAL_CALL
getImplementationName( ) override
;
101 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
105 typedef std::unordered_map
< OUString
, css::script::ModuleInfo
> ModuleInfoMap
;
107 typedef ::cppu::ImplHelper1
< css::script::vba::XVBAModuleInfo
> SfxScriptLibrary_BASE
;
109 class SfxScriptLibrary final
: public SfxLibrary
, public SfxScriptLibrary_BASE
111 friend class SfxScriptLibraryContainer
;
113 typedef std::unordered_map
< OUString
, css::script::ModuleInfo
> ModuleInfoMap
;
117 ModuleInfoMap mModuleInfo
;
119 // Provide modify state including resources
120 virtual bool isModified() override
;
121 virtual void storeResources() override
;
122 virtual void storeResourcesAsURL( const OUString
& URL
, const OUString
& NewName
) override
;
123 virtual void storeResourcesToURL( const OUString
& URL
,
124 const css::uno::Reference
< css::task::XInteractionHandler
>& xHandler
) override
;
125 virtual void storeResourcesToStorage( const css::uno::Reference
< css::embed::XStorage
>& xStorage
) override
;
126 virtual bool isLoadedStorable() override
;
131 ModifiableHelper
& _rModifiable
,
132 const css::uno::Reference
< css::ucb::XSimpleFileAccess3
>& xSFI
137 ModifiableHelper
& _rModifiable
,
138 const css::uno::Reference
< css::ucb::XSimpleFileAccess3
>& xSFI
,
139 const OUString
& aLibInfoFileURL
, const OUString
& aStorageURL
, bool ReadOnly
143 DECLARE_XTYPEPROVIDER()
146 virtual css::script::ModuleInfo SAL_CALL
getModuleInfo( const OUString
& ModuleName
) override
;
147 virtual sal_Bool SAL_CALL
hasModuleInfo( const OUString
& ModuleName
) override
;
148 virtual void SAL_CALL
insertModuleInfo( const OUString
& ModuleName
, const css::script::ModuleInfo
& ModuleInfo
) override
;
149 virtual void SAL_CALL
removeModuleInfo( const OUString
& ModuleName
) override
;
151 static bool containsValidModule( const css::uno::Any
& _rElement
);
154 virtual bool isLibraryElementValid(const css::uno::Any
& rElement
) const override
;
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */