xref: /aoo42x/main/jvmfwk/source/fwkbase.cxx (revision a21130c6)
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 
getVendorSettingsPath(rtl::OUString const & sURL)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 
getParam(const char * name)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 
getParamFirstUrl(const char * name)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 
VendorSettings()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 
getPluginData()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 
getVersionInformation(const rtl::OUString & sVendor)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 
getSupportedVendors()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 
getPluginLibrary(const OUString & sVendor)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 
getVMParameters()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 
getUserData()360 rtl::OUString BootParams::getUserData()
361 {
362     return getParamFirstUrl(UNO_JAVA_JFW_USER_DATA);
363 }
364 
getSharedData()365 rtl::OUString BootParams::getSharedData()
366 {
367     return getParamFirstUrl(UNO_JAVA_JFW_SHARED_DATA);
368 }
369 
getInstallData()370 rtl::OUString BootParams::getInstallData()
371 {
372     return getParam(UNO_JAVA_JFW_INSTALL_DATA);
373 }
374 
375 
getClasspath()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             if (sClassPath.getLength()) {
402                 sClassPath += rtl::OString(szSep);
403             }
404             sClassPath += rtl::OString(pCp);
405         }
406 #if OSL_DEBUG_LEVEL >=2
407         fprintf(stderr,"[Java framework] Using bootstrap parameter "
408             UNO_JAVA_JFW_ENV_CLASSPATH " and class path is:\n %s.\n", pCp ? pCp : "");
409 #endif
410     }
411 
412     return sClassPath;
413 }
414 
getVendorSettings()415 rtl::OUString BootParams::getVendorSettings()
416 {
417     rtl::OUString sVendor;
418     rtl::OUString sName(
419         RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_VENDOR_SETTINGS));
420     if (Bootstrap::get()->getFrom(sName ,sVendor) == sal_True)
421     {
422         //check the value of the bootstrap variable
423         jfw::FileStatus s = checkFileURL(sVendor);
424         if (s != FILE_OK)
425         {
426             //This bootstrap parameter can contain a relative URL
427             rtl::OUString sAbsoluteUrl;
428             rtl::OUString sBaseDir = getLibraryLocation();
429             if (File::getAbsoluteFileURL(sBaseDir, sVendor, sAbsoluteUrl)
430                 != File::E_None)
431                 throw FrameworkException(
432                     JFW_E_CONFIGURATION,
433                     rtl::OString("[Java framework] Invalid value for bootstrap variable: "
434                              UNO_JAVA_JFW_VENDOR_SETTINGS));
435             sVendor = sAbsoluteUrl;
436             s = checkFileURL(sVendor);
437             if (s == jfw::FILE_INVALID || s == jfw::FILE_DOES_NOT_EXIST)
438             {
439                 throw FrameworkException(
440                     JFW_E_CONFIGURATION,
441                     rtl::OString("[Java framework] Invalid value for bootstrap variable: "
442                                  UNO_JAVA_JFW_VENDOR_SETTINGS));
443             }
444         }
445 #if OSL_DEBUG_LEVEL >=2
446     rtl::OString sValue = rtl::OUStringToOString(sVendor, osl_getThreadTextEncoding());
447     fprintf(stderr,"[Java framework] Using bootstrap parameter "
448             UNO_JAVA_JFW_VENDOR_SETTINGS" = %s.\n", sValue.getStr());
449 #endif
450     }
451     return sVendor;
452 }
453 
getJREHome()454 rtl::OUString BootParams::getJREHome()
455 {
456     rtl::OUString sJRE;
457     rtl::OUString sEnvJRE;
458     sal_Bool bJRE = Bootstrap::get()->getFrom(
459         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_JREHOME)) ,sJRE);
460     sal_Bool bEnvJRE = Bootstrap::get()->getFrom(
461         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_ENV_JREHOME)) ,sEnvJRE);
462 
463     if (bJRE == sal_True && bEnvJRE == sal_True)
464     {
465         throw FrameworkException(
466             JFW_E_CONFIGURATION,
467             rtl::OString("[Java framework] Both bootstrap parameter "
468                          UNO_JAVA_JFW_JREHOME" and "
469                          UNO_JAVA_JFW_ENV_JREHOME" are set. However only one of them can be set."
470                              "Check bootstrap parameters: environment variables, command line "
471                              "arguments, rc/ini files for executable and java framework library."));
472     }
473     else if (bEnvJRE == sal_True)
474     {
475         const char * pJRE = getenv("JAVA_HOME");
476         if (pJRE == NULL)
477         {
478             throw FrameworkException(
479             JFW_E_CONFIGURATION,
480             rtl::OString("[Java framework] Both bootstrap parameter "
481                          UNO_JAVA_JFW_ENV_JREHOME" is set, but the environment variable "
482                          "JAVA_HOME is not set."));
483         }
484         rtl::OString osJRE(pJRE);
485         rtl::OUString usJRE = rtl::OStringToOUString(osJRE, osl_getThreadTextEncoding());
486         if (File::getFileURLFromSystemPath(usJRE, sJRE) != File::E_None)
487             throw FrameworkException(
488                 JFW_E_ERROR,
489                 rtl::OString("[Java framework] Error in function BootParams::getJREHome() "
490                              "(fwkbase.cxx)."));
491 #if OSL_DEBUG_LEVEL >=2
492     fprintf(stderr,"[Java framework] Using bootstrap parameter "
493             UNO_JAVA_JFW_ENV_JREHOME" with JAVA_HOME = %s.\n", pJRE);
494 #endif
495     }
496     else if (getMode() == JFW_MODE_DIRECT
497         && bEnvJRE == sal_False
498         && bJRE == sal_False)
499     {
500         throw FrameworkException(
501             JFW_E_CONFIGURATION,
502             rtl::OString("[Java framework] The bootstrap parameter "
503                          UNO_JAVA_JFW_ENV_JREHOME" or " UNO_JAVA_JFW_JREHOME
504                          " must be set in direct mode."));
505     }
506 
507 #if OSL_DEBUG_LEVEL >=2
508     if (bJRE == sal_True)
509     {
510         rtl::OString sValue = rtl::OUStringToOString(sJRE, osl_getThreadTextEncoding());
511         fprintf(stderr,"[Java framework] Using bootstrap parameter "
512             UNO_JAVA_JFW_JREHOME" = %s.\n", sValue.getStr());
513     }
514 #endif
515     return sJRE;
516 }
517 
getClasspathUrls()518 rtl::OUString BootParams::getClasspathUrls()
519 {
520     rtl::OUString sParams;
521     Bootstrap::get()->getFrom(
522         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_CLASSPATH_URLS)),
523         sParams);
524 #if OSL_DEBUG_LEVEL >=2
525     rtl::OString sValue = rtl::OUStringToOString(sParams, osl_getThreadTextEncoding());
526     fprintf(stderr,"[Java framework] Using bootstrap parameter "
527             UNO_JAVA_JFW_CLASSPATH_URLS " = \"%s\".\n", sValue.getStr());
528 #endif
529     return sParams;
530 }
531 
getInstallDataExpiration()532 ::sal_uInt32 BootParams::getInstallDataExpiration()
533 {
534     rtl::OUString sValue;
535     Bootstrap::get()->getFrom(
536         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_INSTALL_EXPIRE)),
537         sValue);
538 
539 #if OSL_DEBUG_LEVEL >=2
540     rtl::OString osValue = rtl::OUStringToOString(sValue, osl_getThreadTextEncoding());
541     fprintf(stderr,"[Java framework] Using bootstrap parameter "
542             UNO_JAVA_JFW_INSTALL_EXPIRE " = %s.\n", osValue.getStr());
543 #endif
544 
545     sal_Int64 nVal = sValue.toInt64();
546     if (0 == nVal)
547     {
548 #if OSL_DEBUG_LEVEL >=2
549         fprintf(stderr,"[Java framework] Using default value for "
550                 "UNO_JAVA_JFW_INSTALL_EXPIRE: %d  \n", DEFAULT_INSTALL_EXPIRATION);
551 #endif
552         return DEFAULT_INSTALL_EXPIRATION;
553     }
554     else
555     {
556         return static_cast<sal_uInt32>(nVal);
557     }
558 }
559 
getMode()560 JFW_MODE getMode()
561 {
562     static bool g_bMode = false;
563     static JFW_MODE g_mode = JFW_MODE_APPLICATION;
564 
565     if (g_bMode == false)
566     {
567         //check if either of the "direct mode" bootstrap variables is set
568         bool bDirectMode = true;
569         rtl::OUString sValue;
570         const rtl::Bootstrap * aBoot = Bootstrap::get();
571         rtl::OUString sJREHome(
572             RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_JREHOME));
573         if (aBoot->getFrom(sJREHome, sValue) == sal_False)
574         {
575             rtl::OUString sEnvJRE(
576             RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_ENV_JREHOME));
577             if (aBoot->getFrom(sEnvJRE, sValue) == sal_False)
578             {
579                 rtl::OUString sClasspath(
580                     RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_CLASSPATH));
581                 if (aBoot->getFrom(sClasspath, sValue) == sal_False)
582                 {
583                     rtl::OUString sEnvClasspath(
584                         RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_ENV_CLASSPATH));
585                     if (aBoot->getFrom(sEnvClasspath, sValue) == sal_False)
586                     {
587                         rtl::OUString sParams = rtl::OUString(
588                             RTL_CONSTASCII_USTRINGPARAM(UNO_JAVA_JFW_PARAMETER)) +
589                             rtl::OUString::valueOf((sal_Int32)1);
590                         if (aBoot->getFrom(sParams, sValue) == sal_False)
591                         {
592                             bDirectMode = false;
593                         }
594                     }
595                 }
596             }
597         }
598 
599         if (bDirectMode)
600             g_mode = JFW_MODE_DIRECT;
601         else
602             g_mode = JFW_MODE_APPLICATION;
603         g_bMode = true;
604     }
605 
606     return g_mode;
607 }
608 
getApplicationClassPath()609 rtl::OUString getApplicationClassPath()
610 {
611     OSL_ASSERT(getMode() == JFW_MODE_APPLICATION);
612     rtl::OUString retVal;
613     rtl::OUString sParams = BootParams::getClasspathUrls();
614     if (sParams.getLength() == 0)
615         return retVal;
616 
617     rtl::OUStringBuffer buf;
618     sal_Int32 index = 0;
619     char szClassPathSep[] = {SAL_PATHSEPARATOR,0};
620     do
621     {
622         ::rtl::OUString token( sParams.getToken( 0, ' ', index ).trim() );
623         if (token.getLength())
624         {
625             ::rtl::OUString systemPathElement;
626             oslFileError rc = osl_getSystemPathFromFileURL(
627                 token.pData, &systemPathElement.pData );
628             OSL_ASSERT( rc == osl_File_E_None );
629             if (rc == osl_File_E_None && systemPathElement.getLength() > 0)
630             {
631                 if (buf.getLength() > 0)
632                     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(
633                                          szClassPathSep) );
634                 buf.append( systemPathElement );
635             }
636         }
637     }
638     while (index >= 0);
639     return buf.makeStringAndClear();
640 }
641 
makeClassPathOption(OUString const & sUserClassPath)642 rtl::OString makeClassPathOption(OUString const & sUserClassPath)
643 {
644     //Compose the class path
645     rtl::OString sPaths;
646     rtl::OUStringBuffer sBufCP(4096);
647     char szSep[] = {SAL_PATHSEPARATOR,0};
648 
649     // append all user selected jars to the class path
650     if (sUserClassPath.getLength() > 0)
651         sBufCP.append(sUserClassPath);
652 
653     //append all jar libraries and components to the class path
654     OUString sAppCP = getApplicationClassPath();
655     if (sAppCP.getLength())
656     {
657         if (sUserClassPath.getLength())
658             sBufCP.appendAscii(szSep);
659         sBufCP.append(sAppCP);
660     }
661 
662     sPaths = rtl::OUStringToOString(
663         sBufCP.makeStringAndClear(), osl_getThreadTextEncoding());
664 
665     rtl::OString sOptionClassPath("-Djava.class.path=");
666     sOptionClassPath += sPaths;
667     return sOptionClassPath;
668 }
669 
getUserSettingsPath()670 rtl::OString getUserSettingsPath()
671 {
672     return getSettingsPath(BootParams::getUserData());
673 }
674 
getSharedSettingsPath()675 rtl::OString getSharedSettingsPath()
676 {
677     return getSettingsPath(BootParams::getSharedData());
678 }
679 
getInstallSettingsPath()680 rtl::OString getInstallSettingsPath()
681 {
682     return getSettingsPath(BootParams::getInstallData());
683 }
684 
getSettingsPath(const rtl::OUString & sURL)685 rtl::OString getSettingsPath( const rtl::OUString & sURL)
686 {
687     if (sURL.getLength() == 0)
688 		return rtl::OString();
689     rtl::OUString sPath;
690     if (osl_getSystemPathFromFileURL(sURL.pData,
691         & sPath.pData) != osl_File_E_None)
692         throw FrameworkException(
693             JFW_E_ERROR, rtl::OString(
694                 "[Java framework] Error in function ::getSettingsPath (fwkbase.cxx)."));
695     return rtl::OUStringToOString(sPath,osl_getThreadTextEncoding());
696 }
697 
getVendorSettingsPath()698 rtl::OString getVendorSettingsPath()
699 {
700     return getVendorSettingsPath(BootParams::getVendorSettings());
701 }
702 
setJavaSelected()703 void setJavaSelected()
704 {
705     g_bJavaSet = true;
706 }
707 
wasJavaSelectedInSameProcess()708 bool wasJavaSelectedInSameProcess()
709 {
710     //g_setJavaProcId not set means no Java selected
711     if (g_bJavaSet == true)
712         return true;
713     return false;
714 }
715 
716 
717 }
718