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 position 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 the member m_layer and the bootstrap parameters UNO_JAVA_JFW_USER_DATA, 147 UNO_JAVA_JFW_SHARED_DATA and UNO_JAVA_JFW_INSTALL_DATA which this may be. 148 */ 149 ::rtl::OString getSettingsPath() const; 150 151 /** returns the file URL to the data file which is to be used. See getSettingsPath. 152 */ 153 ::rtl::OUString getSettingsURL() const; 154 155 /** Verifies if the respective settings file exist. In case UNO_JAVA_JFW_INSTALL_DATA 156 is used, the age is checked. If the file is too old then we assume that it does not 157 exist and wipe its contents. Then still FILE_DOES_NOT_EXIST is returned. 158 */ 159 jfw::FileStatus checkSettingsFileStatus() const; 160 161 /** Determines the layer for which the instance the loads and writes the 162 data. 163 */ 164 Layer m_layer; 165 166 /** User configurable option. /java/enabled 167 If /java/enabled@xsi:nil == true then the value will be uninitialized 168 after a call to load(). 169 */ 170 boost::optional<sal_Bool> m_enabled; 171 172 /** User configurable option. /java/userClassPath 173 If /java/userClassPath@xsi:nil == true then the value is uninitialized 174 after a call to load(). 175 */ 176 boost::optional< ::rtl::OUString> m_userClassPath; 177 /** User configurable option. /java/javaInfo 178 If /java/javaInfo@xsi:nil == true then the value is uninitialized 179 after a call to load. 180 */ 181 boost::optional<CNodeJavaInfo> m_javaInfo; 182 /** User configurable option. /java/vmParameters 183 If /java/vmParameters@xsi:nil == true then the value is uninitialized 184 after a call to load. 185 */ 186 boost::optional< ::std::vector< ::rtl::OUString> > m_vmParameters; 187 /** User configurable option. /java/jreLocations 188 If /java/jreLocaltions@xsi:nil == true then the value is uninitialized 189 after a call to load. 190 */ 191 boost::optional< ::std::vector< ::rtl::OUString> > m_JRELocations; 192 193 /** Only in INSTALL mode. Then NodeJava.write writes a <modified> element 194 which contains the seconds value of the TimeValue (osl/time.h), obtained 195 with osl_getSystemTime. 196 It returns 0 if the value cannot be obtained. 197 This is used to fix the problem that the modified time of the settings 198 file is incorrect because it resides on an NFS volume where the NFS 199 server and NFS client do not have the same system time. For example if 200 the server time is ahead of the client time then checkSettingsFileStatus 201 deleted the settings. So even if javaldx determined a Java 202 (jfw_findAndSelectJRE) then jfw_startVM returned a JFW_E_NO_SELECT. Then 203 it looked again for a java by calling jfw_findAndSelectJRE, which 204 returned a JFW_E_NONE. But the following jfw_startVM returned again 205 JFW_E_NO_SELECT. So it looped. (see issue i114509) 206 207 NFS server and NFS client should have the same time. It is common 208 practise to enforce this in networks. We actually should not work 209 around a malconfigured network. We must however, make sure that we do 210 not loop. Maybe a better approach is, that: 211 - assume that mtime and system time are reliable 212 - checkSettingsFile uses system time and mtime of the settings file, 213 instset of using getModifiedTime. 214 - allow a small error margin 215 - jfw_startVM must return a JFW_E_EXPIRED_SETTINGS 216 - XJavaVM::startVM should prevent the loop by processing the new return+ value 217 218 */ 219 sal_uInt32 getModifiedTime() const; 220 221 public: 222 223 NodeJava(Layer theLayer = USER_OR_INSTALL); 224 225 /** sets m_enabled. 226 /java/enabled@xsi:nil will be set to false when write is called. 227 */ 228 void setEnabled(sal_Bool bEnabled); 229 230 /** sets m_sUserClassPath. See setEnabled. 231 */ 232 void setUserClassPath(const ::rtl::OUString & sClassPath); 233 234 /** sets m_aInfo. See setEnabled. 235 @param bAutoSelect 236 true- called by jfw_setSelectedJRE 237 false called by jfw_findAndSelectJRE 238 */ 239 void setJavaInfo(const JavaInfo * pInfo, bool bAutoSelect); 240 241 /** sets the /java/vmParameters/param elements. 242 When this method all previous values are removed and replaced 243 by those in arParameters. 244 /java/vmParameters@xsi:nil will be set to true when write() is 245 called. 246 */ 247 void setVmParameters(rtl_uString * * arParameters, sal_Int32 size); 248 249 /** sets the /java/jreLocations/location elements. 250 When this method is called then all previous values are removed 251 and replaced by those in arParamters. 252 /java/jreLocations@xsi:nil will be set to true write() is called. 253 */ 254 void setJRELocations(rtl_uString * * arParameters, sal_Int32 size); 255 256 /** adds a location to the already existing locations. 257 Note: call load() before, then add the location and then call write(). 258 */ 259 void addJRELocation(rtl_uString * sLocation); 260 261 /** writes the data to user settings. 262 */ 263 void write() const; 264 265 /** load the values of the settings file. 266 */ 267 void load(); 268 269 /** returns the value of the element /java/enabled 270 */ 271 const boost::optional<sal_Bool> & getEnabled() const; 272 /** returns the value of the element /java/userClassPath. 273 */ 274 const boost::optional< ::rtl::OUString> & getUserClassPath() const; 275 276 /** returns the value of the element /java/javaInfo. 277 */ 278 const boost::optional<CNodeJavaInfo> & getJavaInfo() const; 279 280 /** returns the parameters from the element /java/vmParameters/param. 281 */ 282 const boost::optional< ::std::vector< ::rtl::OUString> > & getVmParameters() const; 283 284 /** returns the parameters from the element /java/jreLocations/location. 285 */ 286 const boost::optional< ::std::vector< ::rtl::OUString> > & getJRELocations() const; 287 }; 288 289 /** merges the settings for shared, user and installation during construction. 290 The class uses a simple merge mechanism for the javasettings.xml files in share and 291 user. The following elements completly overwrite the corresponding elements 292 from share: 293 /java/enabled 294 /java/userClassPath 295 /java/vmParameters 296 /java/jreLocations 297 /java/javaInfo 298 299 In case of an installation, the shared and user settings are completely 300 disregarded. 301 302 The locations of the different settings files is obtained through the 303 bootstrap variables: 304 UNO_JAVA_JFW_USER_DATA 305 UNO_JAVA_JFW_SHARED_DATA 306 UNO_JAVA_JFW_INSTALL_DATA 307 308 The class also determines useful default values for settings which have not been made. 309 */ 310 class MergedSettings 311 { 312 private: 313 const MergedSettings& operator = (MergedSettings&); 314 MergedSettings(MergedSettings&); 315 316 void merge(const NodeJava & share, const NodeJava & user); 317 318 sal_Bool m_bEnabled; 319 320 ::rtl::OUString m_sClassPath; 321 322 ::std::vector< ::rtl::OUString> m_vmParams; 323 324 ::std::vector< ::rtl::OUString> m_JRELocations; 325 326 CNodeJavaInfo m_javaInfo; 327 328 public: 329 MergedSettings(); 330 virtual ~MergedSettings(); 331 332 /** the default is true. 333 */ 334 sal_Bool getEnabled() const; 335 336 const ::rtl::OUString & getUserClassPath() const; 337 338 ::std::vector< ::rtl::OString> getVmParametersUtf8() const; 339 /** returns a JavaInfo structure representing the node 340 /java/javaInfo. Every time a new JavaInfo structure is created 341 which needs to be freed by the caller. 342 If both, user and share settings are nil, then NULL is returned. 343 */ 344 JavaInfo * createJavaInfo() const; 345 346 /** returns the value of the attribute /java/javaInfo[@vendorUpdate]. 347 */ 348 ::rtl::OString const & getJavaInfoAttrVendorUpdate() const; 349 350 #ifdef WNT 351 /** returns the javaInfo@autoSelect attribute. 352 Before calling this function loadFromSettings must be called. 353 It uses the javaInfo@autoSelect attribute to determine 354 the return value; 355 */ 356 bool getJavaInfoAttrAutoSelect() const; 357 #endif 358 359 /** returns an array. 360 Caller must free the strings and the array. 361 */ 362 void getVmParametersArray(rtl_uString *** parParameters, sal_Int32 * size) const; 363 364 /** returns an array. 365 Caller must free the strings and the array. 366 */ 367 void getJRELocations(rtl_uString *** parLocations, sal_Int32 * size) const; 368 369 const ::std::vector< ::rtl::OUString> & getJRELocations() const; 370 }; 371 372 373 class VersionInfo 374 { 375 ::std::vector< ::rtl::OUString> vecExcludeVersions; 376 rtl_uString ** arVersions; 377 378 public: 379 VersionInfo(); 380 ~VersionInfo(); 381 382 void addExcludeVersion(const ::rtl::OUString& sVersion); 383 384 ::rtl::OUString sMinVersion; 385 ::rtl::OUString sMaxVersion; 386 387 /** The caller DOES NOT get ownership of the strings. That is he 388 does not need to release the strings. 389 The array exists as long as this object exists. 390 */ 391 392 rtl_uString** getExcludeVersions(); 393 sal_Int32 getExcludeVersionSize(); 394 }; 395 396 struct PluginLibrary 397 { 398 PluginLibrary() 399 { 400 } 401 PluginLibrary(rtl::OUString vendor,::rtl::OUString path) : 402 sVendor(vendor), sPath(path) 403 { 404 } 405 /** contains the vendor string which is later userd in the xml API 406 */ 407 ::rtl::OUString sVendor; 408 /** File URL the plug-in library 409 */ 410 ::rtl::OUString sPath; 411 }; 412 413 } //end namespace 414 #endif 415