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