tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / jvmfwk / inc / elements.hxx
blob3fde096c44a40589dd3c12197cf50c36fb88c7d5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef INCLUDED_JVMFWK_SOURCE_ELEMENTS_HXX
20 #define INCLUDED_JVMFWK_SOURCE_ELEMENTS_HXX
22 #include <sal/config.h>
24 #include <memory>
25 #include <vector>
26 #include "fwkutil.hxx"
27 #include <rtl/ustring.hxx>
28 #include <rtl/byteseq.hxx>
29 #include <libxml/parser.h>
30 #include <optional>
32 struct JavaInfo;
34 #define NS_JAVA_FRAMEWORK "http://openoffice.org/2004/java/framework/1.0"
35 #define NS_SCHEMA_INSTANCE "http://www.w3.org/2001/XMLSchema-instance"
37 namespace jfw
39 /** gets the value of the updated element from the javavendors.xml.
41 OString getElementUpdated();
43 /** create the child elements within the root structure for each platform.
45 @param bNeedsSave
46 [out]If true then the respective structure of elements was added and the
47 document needs to be saved.
49 void createSettingsStructure(xmlDoc* document, bool* bNeedsSave);
51 /** represents the settings saved in the /java/javaInfo element.
52 It is used within class NodeJava which determines the settings
53 file.
55 class CNodeJavaInfo
57 public:
58 CNodeJavaInfo();
60 /** if true, then javaInfo is empty. When writeToNode is called
61 then all child elements are deleted.
63 bool m_bEmptyNode;
64 /** Contains the value of the <updated> element of
65 the javavendors.xml after loadFromNode was called.
66 It is not used, when the javaInfo node is written.
67 see writeToNode
69 OString sAttrVendorUpdate;
70 /** contains the nil value of the /java/javaInfo@xsi:nil attribute.
71 Default is true;
73 bool bNil;
74 /** contains the value of the /java/javaInfo@autoSelect attribute.
75 Default is true. If it is false then the user has modified the JRE
76 selection by actively choosing a JRE from the options dialog. That is,
77 the function jfw_setSelectedJRE was called. Contrary, the function
78 jfw_findAndSelectJRE sets the attribute to true.
80 bool bAutoSelect;
81 OUString sVendor;
82 OUString sLocation;
83 OUString sVersion;
84 sal_uInt64 nRequirements;
85 ::rtl::ByteSequence arVendorData;
87 /** reads the node /java/javaInfo.
88 If javaInfo@xsi:nil = true then member bNil is set to true
89 and no further elements are read.
91 void loadFromNode(xmlDoc* pDoc, xmlNode* pJavaInfo);
92 /** The attribute nil will be set to false. The function gets the value
93 javaSettings/updated from the javavendors.xml and writes it to
94 javaInfo@vendorUpdate in javasettings.xml
96 void writeToNode(xmlDoc* pDoc, xmlNode* pJavaInfo) const;
98 /** returns NULL if javaInfo is nil.
100 std::unique_ptr<JavaInfo> makeJavaInfo() const;
103 /** this class represents the java settings based on a particular
104 settings file.
106 Which settings file is used is determined by the value passed into the
107 constructor and the values of the bootstrap parameters
108 UNO_JAVA_JFW_USER_DATA and UNO_JAVA_JFW_SHARED_DATA.
110 The method load reads the data from the settings file.
111 The method write stores the data into the settings file.
113 class NodeJava
115 public:
116 enum Layer
118 USER,
119 SHARED
122 private:
123 /** creates settings file and fills it with default values.
125 When this function is called then it creates the
126 settings file at the position determined by the bootstrap parameters
127 (UNO_JAVA_JFW_USER_DATA, UNO_JAVA_JFW_SHARED_DATA) and m_layer, unless
128 the file already exists (see createSettingsDocument).
130 @return
131 JFW_E_CONFIG_READWRITE
133 bool prepareSettingsDocument() const;
135 /** helper function for prepareSettingsDocument.
137 bool createSettingsDocument() const;
139 /** returns the system path to the data file which is to be used. The value
140 depends on the member m_layer and the bootstrap parameters
141 UNO_JAVA_JFW_USER_DATA and UNO_JAVA_JFW_SHARED_DATA.
143 OString getSettingsPath() const;
145 /** returns the file URL to the data file which is to be used. See getSettingsPath.
147 OUString getSettingsURL() const;
149 /** Verifies if the respective settings file exist.
151 static jfw::FileStatus checkSettingsFileStatus(OUString const& sURL);
153 /** Determines the layer for which the instance the loads and writes the
154 data.
156 Layer m_layer;
158 /** User configurable option. /java/enabled
159 If /java/enabled@xsi:nil == true then the value will be uninitialized
160 after a call to load().
162 std::optional<sal_Bool> m_enabled;
164 /** User configurable option. /java/userClassPath
165 If /java/userClassPath@xsi:nil == true then the value is uninitialized
166 after a call to load().
168 std::optional<OUString> m_userClassPath;
169 /** User configurable option. /java/javaInfo
170 If /java/javaInfo@xsi:nil == true then the value is uninitialized
171 after a call to load.
173 std::optional<CNodeJavaInfo> m_javaInfo;
174 /** User configurable option. /java/vmParameters
175 If /java/vmParameters@xsi:nil == true then the value is uninitialized
176 after a call to load.
178 std::optional<::std::vector<OUString>> m_vmParameters;
179 /** User configurable option. /java/jreLocations
180 If /java/jreLocations@xsi:nil == true then the value is uninitialized
181 after a call to load.
183 std::optional<::std::vector<OUString>> m_JRELocations;
185 public:
186 explicit NodeJava(Layer theLayer);
188 /** sets m_enabled.
189 /java/enabled@xsi:nil will be set to false when write is called.
191 void setEnabled(bool bEnabled);
193 /** sets m_sUserClassPath. See setEnabled.
195 void setUserClassPath(const OUString& sClassPath);
197 /** sets m_aInfo. See setEnabled.
198 @param bAutoSelect
199 true- called by jfw_setSelectedJRE
200 false called by jfw_findAndSelectJRE
202 void setJavaInfo(const JavaInfo* pInfo, bool bAutoSelect);
204 /** sets the /java/vmParameters/param elements.
205 When this method all previous values are removed and replaced
206 by those in arParameters.
207 /java/vmParameters@xsi:nil will be set to true when write() is
208 called.
210 void setVmParameters(std::vector<OUString> const& arParameters);
212 /** adds a location to the already existing locations.
213 Note: call load() before, then add the location and then call write().
215 void addJRELocation(OUString const& sLocation);
217 /** writes the data to user settings.
219 void write() const;
221 /** load the values of the settings file.
223 void load();
225 /** returns the value of the element /java/enabled
227 const std::optional<sal_Bool>& getEnabled() const { return m_enabled; }
228 /** returns the value of the element /java/userClassPath.
230 const std::optional<OUString>& getUserClassPath() const { return m_userClassPath; }
232 /** returns the value of the element /java/javaInfo.
234 const std::optional<CNodeJavaInfo>& getJavaInfo() const { return m_javaInfo; }
236 /** returns the parameters from the element /java/vmParameters/param.
238 const std::optional<::std::vector<OUString>>& getVmParameters() const { return m_vmParameters; }
240 /** returns the parameters from the element /java/jreLocations/location.
242 const std::optional<::std::vector<OUString>>& getJRELocations() const { return m_JRELocations; }
245 /** merges the settings for shared, user and installation during construction.
246 The class uses a simple merge mechanism for the javasettings.xml files in share and
247 user. The following elements completely overwrite the corresponding elements
248 from share:
249 /java/enabled
250 /java/userClassPath
251 /java/vmParameters
252 /java/jreLocations
253 /java/javaInfo
255 In case of an installation, the shared and user settings are completely
256 disregarded.
258 The locations of the different settings files is obtained through the
259 bootstrap variables:
260 UNO_JAVA_JFW_USER_DATA
261 UNO_JAVA_JFW_SHARED_DATA
263 The class also determines useful default values for settings which have not been made.
265 class MergedSettings final
267 private:
268 MergedSettings& operator=(MergedSettings const&) = delete;
269 MergedSettings(MergedSettings const&) = delete;
271 void merge(const NodeJava& share, const NodeJava& user);
273 bool m_bEnabled;
275 OUString m_sClassPath;
277 ::std::vector<OUString> m_vmParams;
279 ::std::vector<OUString> m_JRELocations;
281 CNodeJavaInfo m_javaInfo;
283 public:
284 MergedSettings();
285 ~MergedSettings();
287 /** the default is true.
289 bool getEnabled() const { return m_bEnabled; }
291 const OUString& getUserClassPath() const { return m_sClassPath; }
293 ::std::vector<OString> getVmParametersUtf8() const;
294 /** returns a JavaInfo structure representing the node
295 /java/javaInfo. Every time a new JavaInfo structure is created
296 which needs to be freed by the caller.
297 If both, user and share settings are nil, then NULL is returned.
299 std::unique_ptr<JavaInfo> createJavaInfo() const;
301 /** returns the value of the attribute /java/javaInfo[@vendorUpdate].
303 OString const& getJavaInfoAttrVendorUpdate() const { return m_javaInfo.sAttrVendorUpdate; }
305 #ifdef _WIN32
306 /** returns the javaInfo@autoSelect attribute.
307 Before calling this function loadFromSettings must be called.
308 It uses the javaInfo@autoSelect attribute to determine
309 the return value;
311 bool getJavaInfoAttrAutoSelect() const;
312 #endif
314 void getVmParametersArray(std::vector<OUString>* parParameters) const;
316 const ::std::vector<OUString>& getJRELocations() const { return m_JRELocations; }
319 struct VersionInfo
321 ::std::vector<OUString> vecExcludeVersions;
322 OUString sMinVersion;
323 OUString sMaxVersion;
326 } //end namespace
327 #endif
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */