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