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 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_jvmfwk.hxx" 26 #include "rtl/ustring.hxx" 27 #include "rtl/ustrbuf.hxx" 28 #include "rtl/uri.hxx" 29 #include "osl/thread.hxx" 30 #include "osl/process.h" 31 #include "libxml/xpathInternals.h" 32 #include "osl/file.hxx" 33 #include "osl/module.hxx" 34 #include "framework.hxx" 35 #include "fwkutil.hxx" 36 #include "elements.hxx" 37 #include "fwkbase.hxx" 38 39 using namespace osl; 40 using namespace rtl; 41 #define JAVASETTINGS "javasettings" 42 #define JAVASETTINGS_XML "javasettings.xml" 43 #define VENDORSETTINGS "javavendors.xml" 44 45 #define UNO_JAVA_JFW_PARAMETER "UNO_JAVA_JFW_PARAMETER_" 46 #define UNO_JAVA_JFW_JREHOME "UNO_JAVA_JFW_JREHOME" 47 #define UNO_JAVA_JFW_ENV_JREHOME "UNO_JAVA_JFW_ENV_JREHOME" 48 #define UNO_JAVA_JFW_CLASSPATH "UNO_JAVA_JFW_CLASSPATH" 49 #define UNO_JAVA_JFW_ENV_CLASSPATH "UNO_JAVA_JFW_ENV_CLASSPATH" 50 #define UNO_JAVA_JFW_CLASSPATH_URLS "UNO_JAVA_JFW_CLASSPATH_URLS" 51 #define UNO_JAVA_JFW_PARAMETERS "UNO_JAVA_JFW_PARAMETERS" 52 #define UNO_JAVA_JFW_VENDOR_SETTINGS "UNO_JAVA_JFW_VENDOR_SETTINGS" 53 #define UNO_JAVA_JFW_USER_DATA "UNO_JAVA_JFW_USER_DATA" 54 #define UNO_JAVA_JFW_SHARED_DATA "UNO_JAVA_JFW_SHARED_DATA" 55 #define UNO_JAVA_JFW_INSTALL_DATA "UNO_JAVA_JFW_INSTALL_DATA" 56 #define UNO_JAVA_JFW_INSTALL_EXPIRE "UNO_JAVA_JFW_INSTALL_EXPIRE" 57 #define DEFAULT_INSTALL_EXPIRATION 3600 58 59 namespace jfw 60 { 61 bool g_bJavaSet = false; 62 63 namespace { 64 65 rtl::OString getVendorSettingsPath(rtl::OUString const & sURL) 66 { 67 if (sURL.getLength() == 0) 68 return rtl::OString(); 69 rtl::OUString sSystemPathSettings; 70 if (osl_getSystemPathFromFileURL(sURL.pData, 71 & sSystemPathSettings.pData) != osl_File_E_None) 72 throw FrameworkException( 73 JFW_E_ERROR, 74 rtl::OString("[Java framework] Error in function " 75 "getVendorSettingsPath (fwkutil.cxx) ")); 76 rtl::OString osSystemPathSettings = 77 rtl::OUStringToOString(sSystemPathSettings,osl_getThreadTextEncoding()); 78 return osSystemPathSettings; 79 } 80 81 rtl::OUString getParam(const char * name) 82 { 83 rtl::OUString retVal; 84 if (Bootstrap::get()->getFrom(rtl::OUString::createFromAscii(name), retVal)) 85 { 86 #if OSL_DEBUG_LEVEL >=2 87 rtl::OString sValue = rtl::OUStringToOString(retVal, osl_getThreadTextEncoding()); 88 fprintf(stderr,"[Java framework] Using bootstrap parameter %s = %s.\n", 89 name, sValue.getStr()); 90 #endif 91 } 92 return retVal; 93 } 94 95 rtl::OUString getParamFirstUrl(const char * name) 96 { 97 // Some parameters can consist of multiple URLs (separated by space 98 // characters, although trim() harmlessly also removes other white-space), 99 // of which only the first is used: 100 sal_Int32 i = 0; 101 return getParam(name).trim().getToken(0, ' ', i); 102 } 103 104 }//blind namespace 105 106 107 VendorSettings::VendorSettings(): 108 m_xmlDocVendorSettingsFileUrl(BootParams::getVendorSettings()) 109 { 110 OString sMsgExc("[Java framework] Error in constructor " 111 "VendorSettings::VendorSettings() (fwkbase.cxx)"); 112 //Prepare the xml document and context 113 OString sSettingsPath = getVendorSettingsPath(m_xmlDocVendorSettingsFileUrl); 114 if (sSettingsPath.getLength() == 0) 115 { 116 OString sMsg("[Java framework] A vendor settings file was not specified." 117 "Check the bootstrap parameter " UNO_JAVA_JFW_VENDOR_SETTINGS "."); 118 OSL_ENSURE(0, sMsg.getStr()); 119 throw FrameworkException(JFW_E_CONFIGURATION, sMsg); 120 } 121 if (sSettingsPath.getLength() > 0) 122 { 123 m_xmlDocVendorSettings = xmlParseFile(sSettingsPath.getStr()); 124 if (m_xmlDocVendorSettings == NULL) 125 throw FrameworkException( 126 JFW_E_ERROR, 127 OString("[Java framework] Error while parsing file: ") 128 + sSettingsPath + OString(".")); 129 130 m_xmlPathContextVendorSettings = xmlXPathNewContext(m_xmlDocVendorSettings); 131 int res = xmlXPathRegisterNs( 132 m_xmlPathContextVendorSettings, (xmlChar*) "jf", 133 (xmlChar*) NS_JAVA_FRAMEWORK); 134 if (res == -1) 135 throw FrameworkException(JFW_E_ERROR, sMsgExc); 136 } 137 } 138 139 std::vector<PluginLibrary> VendorSettings::getPluginData() 140 { 141 OString sExcMsg("[Java framework] Error in function VendorSettings::getVendorPluginURLs " 142 "(fwkbase.cxx)."); 143 std::vector<PluginLibrary> vecPlugins; 144 CXPathObjectPtr result(xmlXPathEvalExpression( 145 (xmlChar*)"/jf:javaSelection/jf:plugins/jf:library", 146 m_xmlPathContextVendorSettings)); 147 if (xmlXPathNodeSetIsEmpty(result->nodesetval)) 148 throw FrameworkException(JFW_E_ERROR, sExcMsg); 149 150 //get the values of the library elements + vendor attribute 151 xmlNode* cur = result->nodesetval->nodeTab[0]; 152 153 while (cur != NULL) 154 { 155 //between library elements are also text elements 156 if (cur->type == XML_ELEMENT_NODE) 157 { 158 CXmlCharPtr sAttrVendor(xmlGetProp(cur, (xmlChar*) "vendor")); 159 CXmlCharPtr sTextLibrary( 160 xmlNodeListGetString(m_xmlDocVendorSettings, 161 cur->xmlChildrenNode, 1)); 162 PluginLibrary plugin; 163 OString osVendor((sal_Char*)(xmlChar*) sAttrVendor); 164 plugin.sVendor = OStringToOUString(osVendor, RTL_TEXTENCODING_UTF8); 165 166 //create the file URL to the library 167 OUString sUrl = findPlugin( 168 m_xmlDocVendorSettingsFileUrl, sTextLibrary); 169 if (sUrl.getLength() == 0) 170 { 171 OString sPlugin = OUStringToOString( 172 sTextLibrary, osl_getThreadTextEncoding()); 173 throw FrameworkException( 174 JFW_E_CONFIGURATION, 175 "[Java framework] The file: " + sPlugin + " does not exist."); 176 } 177 plugin.sPath = sUrl; 178 179 vecPlugins.push_back(plugin); 180 } 181 cur = cur->next; 182 } 183 return vecPlugins; 184 } 185 186 VersionInfo VendorSettings::getVersionInformation(const rtl::OUString & sVendor) 187 { 188 OSL_ASSERT(sVendor.getLength() > 0); 189 VersionInfo aVersionInfo; 190 OString osVendor = OUStringToOString(sVendor, RTL_TEXTENCODING_UTF8); 191 //Get minVersion 192 OString sExpresion = OString( 193 "/jf:javaSelection/jf:vendorInfos/jf:vendor[@name=\"") + 194 osVendor + OString("\"]/jf:minVersion"); 195 196 CXPathObjectPtr xPathObjectMin; 197 xPathObjectMin = 198 xmlXPathEvalExpression((xmlChar*) sExpresion.getStr(), 199 m_xmlPathContextVendorSettings); 200 if (xmlXPathNodeSetIsEmpty(xPathObjectMin->nodesetval)) 201 { 202 aVersionInfo.sMinVersion = OUString(); 203 } 204 else 205 { 206 CXmlCharPtr sVersion; 207 sVersion = xmlNodeListGetString( 208 m_xmlDocVendorSettings, 209 xPathObjectMin->nodesetval->nodeTab[0]->xmlChildrenNode, 1); 210 OString osVersion((sal_Char*)(xmlChar*) sVersion); 211 aVersionInfo.sMinVersion = OStringToOUString( 212 osVersion, RTL_TEXTENCODING_UTF8); 213 } 214 215 //Get maxVersion 216 sExpresion = OString("/jf:javaSelection/jf:vendorInfos/jf:vendor[@name=\"") + 217 osVendor + OString("\"]/jf:maxVersion"); 218 CXPathObjectPtr xPathObjectMax; 219 xPathObjectMax = xmlXPathEvalExpression( 220 (xmlChar*) sExpresion.getStr(), 221 m_xmlPathContextVendorSettings); 222 if (xmlXPathNodeSetIsEmpty(xPathObjectMax->nodesetval)) 223 { 224 aVersionInfo.sMaxVersion = OUString(); 225 } 226 else 227 { 228 CXmlCharPtr sVersion; 229 sVersion = xmlNodeListGetString( 230 m_xmlDocVendorSettings, 231 xPathObjectMax->nodesetval->nodeTab[0]->xmlChildrenNode, 1); 232 OString osVersion((sal_Char*) (xmlChar*) sVersion); 233 aVersionInfo.sMaxVersion = OStringToOUString( 234 osVersion, RTL_TEXTENCODING_UTF8); 235 } 236 237 //Get excludeVersions 238 sExpresion = OString("/jf:javaSelection/jf:vendorInfos/jf:vendor[@name=\"") + 239 osVendor + OString("\"]/jf:excludeVersions/jf:version"); 240 CXPathObjectPtr xPathObjectVersions; 241 xPathObjectVersions = 242 xmlXPathEvalExpression((xmlChar*) sExpresion.getStr(), 243 m_xmlPathContextVendorSettings); 244 if (!xmlXPathNodeSetIsEmpty(xPathObjectVersions->nodesetval)) 245 { 246 xmlNode* cur = xPathObjectVersions->nodesetval->nodeTab[0]; 247 while (cur != NULL) 248 { 249 if (cur->type == XML_ELEMENT_NODE ) 250 { 251 if (xmlStrcmp(cur->name, (xmlChar*) "version") == 0) 252 { 253 CXmlCharPtr sVersion; 254 sVersion = xmlNodeListGetString( 255 m_xmlDocVendorSettings, cur->xmlChildrenNode, 1); 256 OString osVersion((sal_Char*)(xmlChar*) sVersion); 257 OUString usVersion = OStringToOUString( 258 osVersion, RTL_TEXTENCODING_UTF8); 259 aVersionInfo.addExcludeVersion(usVersion); 260 } 261 } 262 cur = cur->next; 263 } 264 } 265 return aVersionInfo; 266 } 267 268 std::vector<OUString> VendorSettings::getSupportedVendors() 269 { 270 std::vector<rtl::OUString> vecVendors; 271 //get the nodeset for the library elements 272 jfw::CXPathObjectPtr result; 273 result = xmlXPathEvalExpression( 274 (xmlChar*)"/jf:javaSelection/jf:plugins/jf:library", 275 m_xmlPathContextVendorSettings); 276 if (xmlXPathNodeSetIsEmpty(result->nodesetval)) 277 throw FrameworkException( 278 JFW_E_ERROR, 279 rtl::OString("[Java framework] Error in function getSupportedVendors (fwkutil.cxx).")); 280 281 //get the values of the library elements + vendor attribute 282 xmlNode* cur = result->nodesetval->nodeTab[0]; 283 while (cur != NULL) 284 { 285 //between library elements are also text elements 286 if (cur->type == XML_ELEMENT_NODE) 287 { 288 jfw::CXmlCharPtr sAttrVendor(xmlGetProp(cur, (xmlChar*) "vendor")); 289 vecVendors.push_back(sAttrVendor); 290 } 291 cur = cur->next; 292 } 293 return vecVendors; 294 } 295 296 OUString VendorSettings::getPluginLibrary(const OUString& sVendor) 297 { 298 OSL_ASSERT(sVendor.getLength() > 0); 299 300 OString sExcMsg("[Java framework] Error in function getPluginLibrary (fwkutil.cxx)."); 301 OString sVendorsPath = getVendorSettingsPath(m_xmlDocVendorSettingsFileUrl); 302 OUStringBuffer usBuffer(256); 303 usBuffer.appendAscii("/jf:javaSelection/jf:plugins/jf:library[@vendor=\""); 304 usBuffer.append(sVendor); 305 usBuffer.appendAscii("\"]/text()"); 306 OUString ouExpr = usBuffer.makeStringAndClear(); 307 OString sExpression = 308 OUStringToOString(ouExpr, osl_getThreadTextEncoding()); 309 CXPathObjectPtr pathObjVendor; 310 pathObjVendor = xmlXPathEvalExpression( 311 (xmlChar*) sExpression.getStr(), m_xmlPathContextVendorSettings); 312 if (xmlXPathNodeSetIsEmpty(pathObjVendor->nodesetval)) 313 throw FrameworkException(JFW_E_ERROR, sExcMsg); 314 315 CXmlCharPtr xmlCharPlugin; 316 xmlCharPlugin = 317 xmlNodeListGetString( 318 m_xmlDocVendorSettings,pathObjVendor->nodesetval->nodeTab[0], 1); 319 320 //make an absolute file url from the relativ plugin URL 321 OUString sUrl = findPlugin(m_xmlDocVendorSettingsFileUrl, xmlCharPlugin); 322 if (sUrl.getLength() == 0) 323 { 324 OString sPlugin = OUStringToOString( 325 xmlCharPlugin, osl_getThreadTextEncoding()); 326 throw FrameworkException( 327 JFW_E_CONFIGURATION, 328 "[Java framework] The file: " + sPlugin + " does not exist."); 329 } 330 return sUrl; 331 } 332 333 ::std::vector<OString> BootParams::getVMParameters() 334 { 335 ::std::vector<OString> vecParams; 336 337 for (sal_Int32 i = 1; ; i++) 338 { 339 OUString sName = 340 OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_PARAMETER)) + 341 OUString::valueOf(i); 342 OUString sValue; 343 if (Bootstrap::get()->getFrom(sName, sValue) == sal_True) 344 { 345 OString sParam = 346 OUStringToOString(sValue, osl_getThreadTextEncoding()); 347 vecParams.push_back(sParam); 348 #if OSL_DEBUG_LEVEL >=2 349 rtl::OString sParamName = rtl::OUStringToOString(sName, osl_getThreadTextEncoding()); 350 fprintf(stderr,"[Java framework] Using bootstrap parameter %s" 351 " = %s.\n", sParamName.getStr(), sParam.getStr()); 352 #endif 353 } 354 else 355 break; 356 } 357 return vecParams; 358 } 359 360 rtl::OUString BootParams::getUserData() 361 { 362 return getParamFirstUrl(UNO_JAVA_JFW_USER_DATA); 363 } 364 365 rtl::OUString BootParams::getSharedData() 366 { 367 return getParamFirstUrl(UNO_JAVA_JFW_SHARED_DATA); 368 } 369 370 rtl::OUString BootParams::getInstallData() 371 { 372 return getParam(UNO_JAVA_JFW_INSTALL_DATA); 373 } 374 375 376 rtl::OString BootParams::getClasspath() 377 { 378 rtl::OString sClassPath; 379 rtl::OUString sCP; 380 char szSep[] = {SAL_PATHSEPARATOR,0}; 381 if (Bootstrap::get()->getFrom( 382 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_CLASSPATH)), 383 sCP) == sal_True) 384 { 385 sClassPath = rtl::OUStringToOString( 386 sCP, osl_getThreadTextEncoding()); 387 #if OSL_DEBUG_LEVEL >=2 388 fprintf(stderr,"[Java framework] Using bootstrap parameter " 389 UNO_JAVA_JFW_CLASSPATH " = %s.\n", sClassPath.getStr()); 390 #endif 391 } 392 393 rtl::OUString sEnvCP; 394 if (Bootstrap::get()->getFrom( 395 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_ENV_CLASSPATH)), 396 sEnvCP) == sal_True) 397 { 398 char * pCp = getenv("CLASSPATH"); 399 if (pCp) 400 { 401 sClassPath += rtl::OString(szSep) + rtl::OString(pCp); 402 } 403 #if OSL_DEBUG_LEVEL >=2 404 fprintf(stderr,"[Java framework] Using bootstrap parameter " 405 UNO_JAVA_JFW_ENV_CLASSPATH " and class path is:\n %s.\n", pCp ? pCp : ""); 406 #endif 407 } 408 409 return sClassPath; 410 } 411 412 rtl::OUString BootParams::getVendorSettings() 413 { 414 rtl::OUString sVendor; 415 rtl::OUString sName( 416 RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_VENDOR_SETTINGS)); 417 if (Bootstrap::get()->getFrom(sName ,sVendor) == sal_True) 418 { 419 //check the value of the bootstrap variable 420 jfw::FileStatus s = checkFileURL(sVendor); 421 if (s != FILE_OK) 422 { 423 //This bootstrap parameter can contain a relative URL 424 rtl::OUString sAbsoluteUrl; 425 rtl::OUString sBaseDir = getLibraryLocation(); 426 if (File::getAbsoluteFileURL(sBaseDir, sVendor, sAbsoluteUrl) 427 != File::E_None) 428 throw FrameworkException( 429 JFW_E_CONFIGURATION, 430 rtl::OString("[Java framework] Invalid value for bootstrap variable: " 431 UNO_JAVA_JFW_VENDOR_SETTINGS)); 432 sVendor = sAbsoluteUrl; 433 s = checkFileURL(sVendor); 434 if (s == jfw::FILE_INVALID || s == jfw::FILE_DOES_NOT_EXIST) 435 { 436 throw FrameworkException( 437 JFW_E_CONFIGURATION, 438 rtl::OString("[Java framework] Invalid value for bootstrap variable: " 439 UNO_JAVA_JFW_VENDOR_SETTINGS)); 440 } 441 } 442 #if OSL_DEBUG_LEVEL >=2 443 rtl::OString sValue = rtl::OUStringToOString(sVendor, osl_getThreadTextEncoding()); 444 fprintf(stderr,"[Java framework] Using bootstrap parameter " 445 UNO_JAVA_JFW_VENDOR_SETTINGS" = %s.\n", sValue.getStr()); 446 #endif 447 } 448 return sVendor; 449 } 450 451 rtl::OUString BootParams::getJREHome() 452 { 453 rtl::OUString sJRE; 454 rtl::OUString sEnvJRE; 455 sal_Bool bJRE = Bootstrap::get()->getFrom( 456 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_JREHOME)) ,sJRE); 457 sal_Bool bEnvJRE = Bootstrap::get()->getFrom( 458 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_ENV_JREHOME)) ,sEnvJRE); 459 460 if (bJRE == sal_True && bEnvJRE == sal_True) 461 { 462 throw FrameworkException( 463 JFW_E_CONFIGURATION, 464 rtl::OString("[Java framework] Both bootstrap parameter " 465 UNO_JAVA_JFW_JREHOME" and " 466 UNO_JAVA_JFW_ENV_JREHOME" are set. However only one of them can be set." 467 "Check bootstrap parameters: environment variables, command line " 468 "arguments, rc/ini files for executable and java framework library.")); 469 } 470 else if (bEnvJRE == sal_True) 471 { 472 const char * pJRE = getenv("JAVA_HOME"); 473 if (pJRE == NULL) 474 { 475 throw FrameworkException( 476 JFW_E_CONFIGURATION, 477 rtl::OString("[Java framework] Both bootstrap parameter " 478 UNO_JAVA_JFW_ENV_JREHOME" is set, but the environment variable " 479 "JAVA_HOME is not set.")); 480 } 481 rtl::OString osJRE(pJRE); 482 rtl::OUString usJRE = rtl::OStringToOUString(osJRE, osl_getThreadTextEncoding()); 483 if (File::getFileURLFromSystemPath(usJRE, sJRE) != File::E_None) 484 throw FrameworkException( 485 JFW_E_ERROR, 486 rtl::OString("[Java framework] Error in function BootParams::getJREHome() " 487 "(fwkbase.cxx).")); 488 #if OSL_DEBUG_LEVEL >=2 489 fprintf(stderr,"[Java framework] Using bootstrap parameter " 490 UNO_JAVA_JFW_ENV_JREHOME" with JAVA_HOME = %s.\n", pJRE); 491 #endif 492 } 493 else if (getMode() == JFW_MODE_DIRECT 494 && bEnvJRE == sal_False 495 && bJRE == sal_False) 496 { 497 throw FrameworkException( 498 JFW_E_CONFIGURATION, 499 rtl::OString("[Java framework] The bootstrap parameter " 500 UNO_JAVA_JFW_ENV_JREHOME" or " UNO_JAVA_JFW_JREHOME 501 " must be set in direct mode.")); 502 } 503 504 #if OSL_DEBUG_LEVEL >=2 505 if (bJRE == sal_True) 506 { 507 rtl::OString sValue = rtl::OUStringToOString(sJRE, osl_getThreadTextEncoding()); 508 fprintf(stderr,"[Java framework] Using bootstrap parameter " 509 UNO_JAVA_JFW_JREHOME" = %s.\n", sValue.getStr()); 510 } 511 #endif 512 return sJRE; 513 } 514 515 rtl::OUString BootParams::getClasspathUrls() 516 { 517 rtl::OUString sParams; 518 Bootstrap::get()->getFrom( 519 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_CLASSPATH_URLS)), 520 sParams); 521 #if OSL_DEBUG_LEVEL >=2 522 rtl::OString sValue = rtl::OUStringToOString(sParams, osl_getThreadTextEncoding()); 523 fprintf(stderr,"[Java framework] Using bootstrap parameter " 524 UNO_JAVA_JFW_CLASSPATH_URLS " = %s.\n", sValue.getStr()); 525 #endif 526 return sParams; 527 } 528 529 ::sal_uInt32 BootParams::getInstallDataExpiration() 530 { 531 rtl::OUString sValue; 532 Bootstrap::get()->getFrom( 533 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_INSTALL_EXPIRE)), 534 sValue); 535 536 #if OSL_DEBUG_LEVEL >=2 537 rtl::OString osValue = rtl::OUStringToOString(sValue, osl_getThreadTextEncoding()); 538 fprintf(stderr,"[Java framework] Using bootstrap parameter " 539 UNO_JAVA_JFW_INSTALL_EXPIRE " = %s.\n", osValue.getStr()); 540 #endif 541 542 sal_Int64 nVal = sValue.toInt64(); 543 if (0 == nVal) 544 { 545 #if OSL_DEBUG_LEVEL >=2 546 fprintf(stderr,"[Java framework] Using default value for " 547 "UNO_JAVA_JFW_INSTALL_EXPIRE: %d \n", DEFAULT_INSTALL_EXPIRATION); 548 #endif 549 return DEFAULT_INSTALL_EXPIRATION; 550 } 551 else 552 { 553 return static_cast<sal_uInt32>(nVal); 554 } 555 } 556 557 JFW_MODE getMode() 558 { 559 static bool g_bMode = false; 560 static JFW_MODE g_mode = JFW_MODE_APPLICATION; 561 562 if (g_bMode == false) 563 { 564 //check if either of the "direct mode" bootstrap variables is set 565 bool bDirectMode = true; 566 rtl::OUString sValue; 567 const rtl::Bootstrap * aBoot = Bootstrap::get(); 568 rtl::OUString sJREHome( 569 RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_JREHOME)); 570 if (aBoot->getFrom(sJREHome, sValue) == sal_False) 571 { 572 rtl::OUString sEnvJRE( 573 RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_ENV_JREHOME)); 574 if (aBoot->getFrom(sEnvJRE, sValue) == sal_False) 575 { 576 rtl::OUString sClasspath( 577 RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_CLASSPATH)); 578 if (aBoot->getFrom(sClasspath, sValue) == sal_False) 579 { 580 rtl::OUString sEnvClasspath( 581 RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_ENV_CLASSPATH)); 582 if (aBoot->getFrom(sEnvClasspath, sValue) == sal_False) 583 { 584 rtl::OUString sParams = rtl::OUString( 585 RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_PARAMETER)) + 586 rtl::OUString::valueOf((sal_Int32)1); 587 if (aBoot->getFrom(sParams, sValue) == sal_False) 588 { 589 bDirectMode = false; 590 } 591 } 592 } 593 } 594 } 595 596 if (bDirectMode) 597 g_mode = JFW_MODE_DIRECT; 598 else 599 g_mode = JFW_MODE_APPLICATION; 600 g_bMode = true; 601 } 602 603 return g_mode; 604 } 605 606 rtl::OUString getApplicationClassPath() 607 { 608 OSL_ASSERT(getMode() == JFW_MODE_APPLICATION); 609 rtl::OUString retVal; 610 rtl::OUString sParams = BootParams::getClasspathUrls(); 611 if (sParams.getLength() == 0) 612 return retVal; 613 614 rtl::OUStringBuffer buf; 615 sal_Int32 index = 0; 616 char szClassPathSep[] = {SAL_PATHSEPARATOR,0}; 617 do 618 { 619 ::rtl::OUString token( sParams.getToken( 0, ' ', index ).trim() ); 620 if (token.getLength()) 621 { 622 ::rtl::OUString systemPathElement; 623 oslFileError rc = osl_getSystemPathFromFileURL( 624 token.pData, &systemPathElement.pData ); 625 OSL_ASSERT( rc == osl_File_E_None ); 626 if (rc == osl_File_E_None && systemPathElement.getLength() > 0) 627 { 628 if (buf.getLength() > 0) 629 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( 630 szClassPathSep) ); 631 buf.append( systemPathElement ); 632 } 633 } 634 } 635 while (index >= 0); 636 return buf.makeStringAndClear(); 637 } 638 639 rtl::OString makeClassPathOption(OUString const & sUserClassPath) 640 { 641 //Compose the class path 642 rtl::OString sPaths; 643 rtl::OUStringBuffer sBufCP(4096); 644 char szSep[] = {SAL_PATHSEPARATOR,0}; 645 646 // append all user selected jars to the class path 647 if (sUserClassPath.getLength() > 0) 648 sBufCP.append(sUserClassPath); 649 650 //append all jar libraries and components to the class path 651 OUString sAppCP = getApplicationClassPath(); 652 if (sAppCP.getLength()) 653 { 654 if (sUserClassPath.getLength()) 655 sBufCP.appendAscii(szSep); 656 sBufCP.append(sAppCP); 657 } 658 659 sPaths = rtl::OUStringToOString( 660 sBufCP.makeStringAndClear(), osl_getThreadTextEncoding()); 661 662 rtl::OString sOptionClassPath("-Djava.class.path="); 663 sOptionClassPath += sPaths; 664 return sOptionClassPath; 665 } 666 667 rtl::OString getUserSettingsPath() 668 { 669 return getSettingsPath(BootParams::getUserData()); 670 } 671 672 rtl::OString getSharedSettingsPath() 673 { 674 return getSettingsPath(BootParams::getSharedData()); 675 } 676 677 rtl::OString getInstallSettingsPath() 678 { 679 return getSettingsPath(BootParams::getInstallData()); 680 } 681 682 rtl::OString getSettingsPath( const rtl::OUString & sURL) 683 { 684 if (sURL.getLength() == 0) 685 return rtl::OString(); 686 rtl::OUString sPath; 687 if (osl_getSystemPathFromFileURL(sURL.pData, 688 & sPath.pData) != osl_File_E_None) 689 throw FrameworkException( 690 JFW_E_ERROR, rtl::OString( 691 "[Java framework] Error in function ::getSettingsPath (fwkbase.cxx).")); 692 return rtl::OUStringToOString(sPath,osl_getThreadTextEncoding()); 693 } 694 695 rtl::OString getVendorSettingsPath() 696 { 697 return getVendorSettingsPath(BootParams::getVendorSettings()); 698 } 699 700 void setJavaSelected() 701 { 702 g_bJavaSet = true; 703 } 704 705 bool wasJavaSelectedInSameProcess() 706 { 707 //g_setJavaProcId not set means no Java selected 708 if (g_bJavaSet == true) 709 return true; 710 return false; 711 } 712 713 714 } 715