LCOV - code coverage report
Current view: top level - libreoffice/jvmfwk/source - fwkbase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 276 0.0 %
Date: 2012-12-27 Functions: 0 24 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10