1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #if !defined INCLUDED_JVMFWK_ELEMENTS_HXX 24 #define INCLUDED_JVMFWK_ELEMENTS_HXX 25 26 #include <vector> 27 #include "jvmfwk/framework.h" 28 #include "fwkutil.hxx" 29 #include "rtl/ustring.hxx" 30 #include "rtl/byteseq.hxx" 31 #include "libxml/parser.h" 32 #include "boost/optional.hpp" 33 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" 36 37 namespace jfw 38 { 39 40 /** gets the value of the updated element from the javavendors.xml. 41 */ 42 rtl::OString getElementUpdated(); 43 44 /** create the child elements within the root structure for each platform. 45 46 @param bNeedsSave 47 [out]If true then the respective structure of elements was added and the 48 document needs to be saved. 49 */ 50 void createSettingsStructure( 51 xmlDoc * document, bool * bNeedsSave); 52 53 54 /** represents the settings saved in the /java/javaInfo element. 55 It is used within class NodeJava which determines the settings 56 file. 57 */ 58 class CNodeJavaInfo 59 { 60 public: 61 CNodeJavaInfo(); 62 ~CNodeJavaInfo(); 63 64 /** if true, then javaInfo is empty. When writeToNode is called 65 then all child elements are deleted. 66 */ 67 bool m_bEmptyNode; 68 /** Contains the value of the <updated> element of 69 the javavendors.xml after loadFromNode was called. 70 It is not used, when the javaInfo node is written. 71 see writeToNode 72 */ 73 ::rtl::OString sAttrVendorUpdate; 74 /** contains the nil value of the /java/javaInfo@xsi:nil attribute. 75 Default is true; 76 */ 77 bool bNil; 78 /** contains the value of the /java/javaInfo@autoSelect attribute. 79 Default is true. If it is false then the user has modified the JRE 80 selection by actively choosing a JRE from the options dialog. That is, 81 the function jfw_setSelectedJRE was called. Contrary, the function 82 jfw_findAndSelectJRE sets the attribute to true. 83 */ 84 bool bAutoSelect; 85 ::rtl::OUString sVendor; 86 ::rtl::OUString sLocation; 87 ::rtl::OUString sVersion; 88 sal_uInt64 nFeatures; 89 sal_uInt64 nRequirements; 90 ::rtl::ByteSequence arVendorData; 91 92 /** reads the node /java/javaInfo. 93 If javaInfo@xsi:nil = true then member bNil is set to true 94 an no further elements are read. 95 */ 96 void loadFromNode(xmlDoc * pDoc,xmlNode * pJavaInfo); 97 /** The attribut nil will be set to false. The function gets the value 98 javaSettings/updated from the javavendors.xml and writes it to 99 javaInfo@vendorUpdate in javasettings.xml 100 */ 101 void writeToNode(xmlDoc * pDoc, xmlNode * pJavaInfo) const; 102 103 /** returns NULL if javaInfo is nil. 104 */ 105 JavaInfo * makeJavaInfo() const; 106 }; 107 108 /** this class represents the java settings based on a particular 109 settings file. 110 111 Which settings file is used is determined by the value passed into the 112 constructo and the values of the bootstrap parameters UNO_JAVA_JFW_USER_DATA, 113 UNO_JAVA_JFW_SHARED_DATA,_JAVA_JFW_INSTALL_DATA. 114 115 If the value is USER_OR_INSTALL then it depends of the bootstrap parameter 116 UNO_JAVA_JFW_INSTALL_DATA. If it has as value then it is used. Otherwise the 117 value from UNO_JAVA_JFW_USER_DATA is used. 118 119 The method load reads the data from the settings file. 120 The method write stores the data into the settings file. 121 */ 122 class NodeJava 123 { 124 public: 125 enum Layer { USER_OR_INSTALL, USER, SHARED, INSTALL }; 126 private: 127 128 /** creates settings file and fills it with default values. 129 130 When this function is called then it creates the 131 settings file at the possition determined by the bootstrap parameters 132 (UNO_JAVA_JFW_USER_DATA, UNO_JAVA_JFW_SHARED_DATA, 133 UNO_JAVA_JFW_INSTALL_DATA) and m_layer, unless the file already exists 134 (see createSettingsDocument). 135 136 @return 137 JFW_E_CONFIG_READWRITE 138 */ 139 void prepareSettingsDocument() const; 140 141 /** helper function for prepareSettingsDocument. 142 */ 143 void createSettingsDocument() const; 144 145 /** returns the system path to the data file which is to be used. The value 146 depends on 147 the the member m_layer and the bootstrap paramters UNO_JAVA_JFW_USER_DATA, 148 UNO_JAVA_JFW_SHARED_DATA and UNO_JAVA_JFW_INSTALL_DATA which this may be. 149 */ 150 ::rtl::OString getSettingsPath() const; 151 152 /** returns the file URL to the data file which is to be used. See getSettingsPath. 153 */ 154 ::rtl::OUString getSettingsURL() const; 155 156 /** Verifies if the respective settings file exist. In case UNO_JAVA_JFW_INSTALL_DATA 157 is used, the age is checked. If the file is too old then we assume that it does not 158 exist and wipe its contents. Then still FILE_DOES_NOT_EXIST is returned. 159 */ 160 jfw::FileStatus checkSettingsFileStatus() const; 161 162 /** Determines the layer for which the instance the loads and writes the 163 data. 164 */ 165 Layer m_layer; 166 167 /** User configurable option. /java/enabled 168 If /java/enabled@xsi:nil == true then the value will be uninitialized 169 after a call to load(). 170 */ 171 boost::optional<sal_Bool> m_enabled; 172 173 /** User configurable option. /java/userClassPath 174 If /java/userClassPath@xsi:nil == true then the value is uninitialized 175 after a call to load(). 176 */ 177 boost::optional< ::rtl::OUString> m_userClassPath; 178 /** User configurable option. /java/javaInfo 179 If /java/javaInfo@xsi:nil == true then the value is uninitialized 180 after a call to load. 181 */ 182 boost::optional<CNodeJavaInfo> m_javaInfo; 183 /** User configurable option. /java/vmParameters 184 If /java/vmParameters@xsi:nil == true then the value is uninitialized 185 after a call to load. 186 */ 187 boost::optional< ::std::vector< ::rtl::OUString> > m_vmParameters; 188 /** User configurable option. /java/jreLocations 189 If /java/jreLocaltions@xsi:nil == true then the value is uninitialized 190 after a call to load. 191 */ 192 boost::optional< ::std::vector< ::rtl::OUString> > m_JRELocations; 193 194 /** Only in INSTALL mode. Then NodeJava.write writes a <modified> element 195 which contains the seconds value of the TimeValue (osl/time.h), obtained 196 with osl_getSystemTime. 197 It returns 0 if the value cannot be obtained. 198 This is used to fix the problem that the modified time of the settings 199 file is incorrect because it resides on an NFS volume where the NFS 200 server and NFS client do not have the same system time. For example if 201 the server time is ahead of the client time then checkSettingsFileStatus 202 deleted the settings. So even if javaldx determined a Java 203 (jfw_findAndSelectJRE) then jfw_startVM returned a JFW_E_NO_SELECT. Then 204 it looked again for a java by calling jfw_findAndSelectJRE, which 205 returned a JFW_E_NONE. But the following jfw_startVM returned again 206 JFW_E_NO_SELECT. So it looped. (see issue i114509) 207 208 NFS server and NFS client should have the same time. It is common 209 practise to enforce this in networks. We actually should not work 210 around a malconfigured network. We must however, make sure that we do 211 not loop. Maybe a better approach is, that: 212 - assume that mtime and system time are reliable 213 - checkSettingsFile uses system time and mtime of the settings file, 214 instset of using getModifiedTime. 215 - allow a small error margin 216 - jfw_startVM must return a JFW_E_EXPIRED_SETTINGS 217 - XJavaVM::startVM should prevent the loop by processing the new return+ value 218 219 */ 220 sal_uInt32 getModifiedTime() const; 221 222 public: 223 224 NodeJava(Layer theLayer = USER_OR_INSTALL); 225 226 /** sets m_enabled. 227 /java/enabled@xsi:nil will be set to false when write is called. 228 */ 229 void setEnabled(sal_Bool bEnabled); 230 231 /** sets m_sUserClassPath. See setEnabled. 232 */ 233 void setUserClassPath(const ::rtl::OUString & sClassPath); 234 235 /** sets m_aInfo. See setEnabled. 236 @param bAutoSelect 237 true- called by jfw_setSelectedJRE 238 false called by jfw_findAndSelectJRE 239 */ 240 void setJavaInfo(const JavaInfo * pInfo, bool bAutoSelect); 241 242 /** sets the /java/vmParameters/param elements. 243 When this method all previous values are removed and replaced 244 by those in arParameters. 245 /java/vmParameters@xsi:nil will be set to true when write() is 246 called. 247 */ 248 void setVmParameters(rtl_uString * * arParameters, sal_Int32 size); 249 250 /** sets the /java/jreLocations/location elements. 251 When this method is called then all previous values are removed 252 and replaced by those in arParamters. 253 /java/jreLocations@xsi:nil will be set to true write() is called. 254 */ 255 void setJRELocations(rtl_uString * * arParameters, sal_Int32 size); 256 257 /** adds a location to the already existing locations. 258 Note: call load() before, then add the location and then call write(). 259 */ 260 void addJRELocation(rtl_uString * sLocation); 261 262 /** writes the data to user settings. 263 */ 264 void write() const; 265 266 /** load the values of the settings file. 267 */ 268 void load(); 269 270 /** returns the value of the element /java/enabled 271 */ 272 const boost::optional<sal_Bool> & getEnabled() const; 273 /** returns the value of the element /java/userClassPath. 274 */ 275 const boost::optional< ::rtl::OUString> & getUserClassPath() const; 276 277 /** returns the value of the element /java/javaInfo. 278 */ 279 const boost::optional<CNodeJavaInfo> & getJavaInfo() const; 280 281 /** returns the parameters from the element /java/vmParameters/param. 282 */ 283 const boost::optional< ::std::vector< ::rtl::OUString> > & getVmParameters() const; 284 285 /** returns the parameters from the element /java/jreLocations/location. 286 */ 287 const boost::optional< ::std::vector< ::rtl::OUString> > & getJRELocations() const; 288 }; 289 290 /** merges the settings for shared, user and installation during construction. 291 The class uses a simple merge mechanism for the javasettings.xml files in share and 292 user. The following elements completly overwrite the corresponding elements 293 from share: 294 /java/enabled 295 /java/userClassPath 296 /java/vmParameters 297 /java/jreLocations 298 /java/javaInfo 299 300 In case of an installation, the shared and user settings are completely 301 disregarded. 302 303 The locations of the different settings files is obtained through the 304 bootstrap variables: 305 UNO_JAVA_JFW_USER_DATA 306 UNO_JAVA_JFW_SHARED_DATA 307 UNO_JAVA_JFW_INSTALL_DATA 308 309 The class also determines useful default values for settings which have not been made. 310 */ 311 class MergedSettings 312 { 313 private: 314 const MergedSettings& operator = (MergedSettings&); 315 MergedSettings(MergedSettings&); 316 317 void merge(const NodeJava & share, const NodeJava & user); 318 319 sal_Bool m_bEnabled; 320 321 ::rtl::OUString m_sClassPath; 322 323 ::std::vector< ::rtl::OUString> m_vmParams; 324 325 ::std::vector< ::rtl::OUString> m_JRELocations; 326 327 CNodeJavaInfo m_javaInfo; 328 329 public: 330 MergedSettings(); 331 virtual ~MergedSettings(); 332 333 /** the default is true. 334 */ 335 sal_Bool getEnabled() const; 336 337 const ::rtl::OUString & getUserClassPath() const; 338 339 ::std::vector< ::rtl::OString> getVmParametersUtf8() const; 340 /** returns a JavaInfo structure representing the node 341 /java/javaInfo. Every time a new JavaInfo structure is created 342 which needs to be freed by the caller. 343 If both, user and share settings are nil, then NULL is returned. 344 */ 345 JavaInfo * createJavaInfo() const; 346 347 /** returns the value of the attribute /java/javaInfo[@vendorUpdate]. 348 */ 349 ::rtl::OString const & getJavaInfoAttrVendorUpdate() const; 350 351 #ifdef WNT 352 /** returns the javaInfo@autoSelect attribute. 353 Before calling this function loadFromSettings must be called. 354 It uses the javaInfo@autoSelect attribute to determine 355 the return value; 356 */ 357 bool getJavaInfoAttrAutoSelect() const; 358 #endif 359 360 /** returns an array. 361 Caller must free the strings and the array. 362 */ 363 void getVmParametersArray(rtl_uString *** parParameters, sal_Int32 * size) const; 364 365 /** returns an array. 366 Caller must free the strings and the array. 367 */ 368 void getJRELocations(rtl_uString *** parLocations, sal_Int32 * size) const; 369 370 const ::std::vector< ::rtl::OUString> & getJRELocations() const; 371 }; 372 373 374 class VersionInfo 375 { 376 ::std::vector< ::rtl::OUString> vecExcludeVersions; 377 rtl_uString ** arVersions; 378 379 public: 380 VersionInfo(); 381 ~VersionInfo(); 382 383 void addExcludeVersion(const ::rtl::OUString& sVersion); 384 385 ::rtl::OUString sMinVersion; 386 ::rtl::OUString sMaxVersion; 387 388 /** The caller DOES NOT get ownership of the strings. That is he 389 does not need to release the strings. 390 The array exists as long as this object exists. 391 */ 392 393 rtl_uString** getExcludeVersions(); 394 sal_Int32 getExcludeVersionSize(); 395 }; 396 397 struct PluginLibrary 398 { PluginLibraryjfw::PluginLibrary399 PluginLibrary() 400 { 401 } PluginLibraryjfw::PluginLibrary402 PluginLibrary(rtl::OUString vendor,::rtl::OUString path) : 403 sVendor(vendor), sPath(path) 404 { 405 } 406 /** contains the vendor string which is later userd in the xml API 407 */ 408 ::rtl::OUString sVendor; 409 /** File URL the plug-in library 410 */ 411 ::rtl::OUString sPath; 412 }; 413 414 } //end namespace 415 #endif 416