license: STLPort is not included in LibreOffice
[LibreOffice.git] / jvmfwk / inc / elements.hxx
blob88a785a381fb67364d697f44e1d414c8a79e1cf2
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 <jvmfwk/framework.hxx>
27 #include "fwkutil.hxx"
28 #include <rtl/ustring.hxx>
29 #include <rtl/byteseq.hxx>
30 #include <libxml/parser.h>
31 #include <boost/optional.hpp>
33 #define NS_JAVA_FRAMEWORK "http://openoffice.org/2004/java/framework/1.0"
34 #define NS_SCHEMA_INSTANCE "http://www.w3.org/2001/XMLSchema-instance"
36 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(
50 xmlDoc * document, bool * bNeedsSave);
53 /** represents the settings saved in the /java/javaInfo element.
54 It is used within class NodeJava which determines the settings
55 file.
57 class CNodeJavaInfo
59 public:
60 CNodeJavaInfo();
62 /** if true, then javaInfo is empty. When writeToNode is called
63 then all child elements are deleted.
65 bool m_bEmptyNode;
66 /** Contains the value of the <updated> element of
67 the javavendors.xml after loadFromNode was called.
68 It is not used, when the javaInfo node is written.
69 see writeToNode
71 OString sAttrVendorUpdate;
72 /** contains the nil value of the /java/javaInfo@xsi:nil attribute.
73 Default is true;
75 bool bNil;
76 /** contains the value of the /java/javaInfo@autoSelect attribute.
77 Default is true. If it is false then the user has modified the JRE
78 selection by actively choosing a JRE from the options dialog. That is,
79 the function jfw_setSelectedJRE was called. Contrary, the function
80 jfw_findAndSelectJRE sets the attribute to true.
82 bool bAutoSelect;
83 OUString sVendor;
84 OUString sLocation;
85 OUString sVersion;
86 sal_uInt64 nFeatures;
87 sal_uInt64 nRequirements;
88 ::rtl::ByteSequence arVendorData;
90 /** reads the node /java/javaInfo.
91 If javaInfo@xsi:nil = true then member bNil is set to true
92 an no further elements are read.
94 void loadFromNode(xmlDoc * pDoc,xmlNode * pJavaInfo);
95 /** The attribute nil will be set to false. The function gets the value
96 javaSettings/updated from the javavendors.xml and writes it to
97 javaInfo@vendorUpdate in javasettings.xml
99 void writeToNode(xmlDoc * pDoc, xmlNode * pJavaInfo) const;
101 /** returns NULL if javaInfo is nil.
103 std::unique_ptr<JavaInfo> makeJavaInfo() const;
106 /** this class represents the java settings based on a particular
107 settings file.
109 Which settings file is used is determined by the value passed into the
110 constructor and the values of the bootstrap parameters
111 UNO_JAVA_JFW_USER_DATA and UNO_JAVA_JFW_SHARED_DATA.
113 The method load reads the data from the settings file.
114 The method write stores the data into the settings file.
116 class NodeJava
118 public:
119 enum Layer { USER, SHARED };
120 private:
122 /** creates settings file and fills it with default values.
124 When this function is called then it creates the
125 settings file at the position determined by the bootstrap parameters
126 (UNO_JAVA_JFW_USER_DATA, UNO_JAVA_JFW_SHARED_DATA) and m_layer, unless
127 the file already exists (see createSettingsDocument).
129 @return
130 JFW_E_CONFIG_READWRITE
132 bool prepareSettingsDocument() const;
134 /** helper function for prepareSettingsDocument.
136 bool createSettingsDocument() const;
138 /** returns the system path to the data file which is to be used. The value
139 depends on the member m_layer and the bootstrap parameters
140 UNO_JAVA_JFW_USER_DATA and UNO_JAVA_JFW_SHARED_DATA.
142 OString getSettingsPath() const;
144 /** returns the file URL to the data file which is to be used. See getSettingsPath.
146 OUString getSettingsURL() const;
148 /** Verifies if the respective settings file exist.
150 static jfw::FileStatus checkSettingsFileStatus(OUString const & sURL);
152 /** Determines the layer for which the instance the loads and writes the
153 data.
155 Layer m_layer;
157 /** User configurable option. /java/enabled
158 If /java/enabled@xsi:nil == true then the value will be uninitialized
159 after a call to load().
161 boost::optional<sal_Bool> m_enabled;
163 /** User configurable option. /java/userClassPath
164 If /java/userClassPath@xsi:nil == true then the value is uninitialized
165 after a call to load().
167 boost::optional< OUString> m_userClassPath;
168 /** User configurable option. /java/javaInfo
169 If /java/javaInfo@xsi:nil == true then the value is uninitialized
170 after a call to load.
172 boost::optional<CNodeJavaInfo> m_javaInfo;
173 /** User configurable option. /java/vmParameters
174 If /java/vmParameters@xsi:nil == true then the value is uninitialized
175 after a call to load.
177 boost::optional< ::std::vector< OUString> > m_vmParameters;
178 /** User configurable option. /java/jreLocations
179 If /java/jreLocaltions@xsi:nil == true then the value is uninitialized
180 after a call to load.
182 boost::optional< ::std::vector< OUString> > m_JRELocations;
184 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 boost::optional<sal_Bool> & getEnabled() const { return m_enabled;}
228 /** returns the value of the element /java/userClassPath.
230 const boost::optional< OUString> & getUserClassPath() const { return m_userClassPath;}
232 /** returns the value of the element /java/javaInfo.
234 const boost::optional<CNodeJavaInfo> & getJavaInfo() const { return m_javaInfo;}
236 /** returns the parameters from the element /java/vmParameters/param.
238 const boost::optional< ::std::vector< OUString> > & getVmParameters() const { return m_vmParameters;}
240 /** returns the parameters from the element /java/jreLocations/location.
242 const boost::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;}
320 struct VersionInfo
322 ::std::vector< OUString> vecExcludeVersions;
323 OUString sMinVersion;
324 OUString sMaxVersion;
327 } //end namespace
328 #endif
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */