LCOV - code coverage report
Current view: top level - libreoffice/jvmfwk/source - elements.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 590 0.0 %
Date: 2012-12-27 Functions: 0 44 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 "elements.hxx"
      21             : #include "osl/mutex.hxx"
      22             : #include "osl/file.hxx"
      23             : #include "fwkutil.hxx"
      24             : #include "fwkbase.hxx"
      25             : #include "framework.hxx"
      26             : #include "libxmlutil.hxx"
      27             : #include "osl/thread.hxx"
      28             : #include <algorithm>
      29             : #include "libxml/parser.h"
      30             : #include "libxml/xpath.h"
      31             : #include "libxml/xpathInternals.h"
      32             : #include "rtl/bootstrap.hxx"
      33             : #include "boost/optional.hpp"
      34             : #include <string.h>
      35             : 
      36             : 
      37             : using namespace osl;
      38             : namespace jfw
      39             : {
      40             : 
      41           0 : rtl::OString getElement(::rtl::OString const & docPath,
      42             :                         xmlChar const * pathExpression, bool bThrowIfEmpty)
      43             : {
      44             :     //Prepare the xml document and context
      45             :     OSL_ASSERT(!docPath.isEmpty());
      46           0 :      jfw::CXmlDocPtr doc(xmlParseFile(docPath.getStr()));
      47           0 :     if (doc == NULL)
      48             :         throw FrameworkException(
      49             :             JFW_E_ERROR,
      50             :             rtl::OString("[Java framework] Error in function getElement "
      51           0 :                          "(elements.cxx)"));
      52             : 
      53           0 :     jfw::CXPathContextPtr context(xmlXPathNewContext(doc));
      54           0 :     if (xmlXPathRegisterNs(context, (xmlChar*) "jf",
      55           0 :         (xmlChar*) NS_JAVA_FRAMEWORK) == -1)
      56             :         throw FrameworkException(
      57             :             JFW_E_ERROR,
      58             :             rtl::OString("[Java framework] Error in function getElement "
      59           0 :                          "(elements.cxx)"));
      60             : 
      61           0 :     CXPathObjectPtr pathObj;
      62           0 :     pathObj = xmlXPathEvalExpression(pathExpression, context);
      63           0 :     rtl::OString sValue;
      64           0 :     if (xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
      65             :     {
      66           0 :         if (bThrowIfEmpty)
      67             :             throw FrameworkException(
      68             :                 JFW_E_ERROR,
      69             :                 rtl::OString("[Java framework] Error in function getElement "
      70           0 :                              "(elements.cxx)"));
      71             :     }
      72             :     else
      73             :     {
      74           0 :         sValue = (sal_Char*) pathObj->nodesetval->nodeTab[0]->content;
      75             :     }
      76           0 :     return sValue;
      77             : }
      78             : 
      79           0 : rtl::OString getElementUpdated()
      80             : {
      81             :     return getElement(jfw::getVendorSettingsPath(),
      82           0 :                       (xmlChar*)"/jf:javaSelection/jf:updated/text()", true);
      83             : }
      84             : 
      85           0 : void createSettingsStructure(xmlDoc * document, bool * bNeedsSave)
      86             : {
      87             :     rtl::OString sExcMsg("[Java framework] Error in function createSettingsStructure "
      88           0 :                          "(elements.cxx).");
      89           0 :     xmlNode * root = xmlDocGetRootElement(document);
      90           0 :     if (root == NULL)
      91           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
      92           0 :     bool bFound = false;
      93           0 :     xmlNode * cur = root->children;
      94           0 :     while (cur != NULL)
      95             :     {
      96           0 :         if (xmlStrcmp(cur->name, (xmlChar*) "enabled") == 0)
      97             :         {
      98           0 :             bFound = true;
      99           0 :             break;
     100             :         }
     101           0 :         cur = cur->next;
     102             :     }
     103           0 :     if (bFound)
     104             :     {
     105           0 :         *bNeedsSave = false;
     106           0 :         return;
     107             :     }
     108             :     //We will modify this document
     109           0 :     *bNeedsSave = true;
     110             :     // Now we create the child elements ------------------
     111             :     //Get xsi:nil namespace
     112             :     xmlNs* nsXsi = xmlSearchNsByHref(
     113           0 :         document, root,(xmlChar*)  NS_SCHEMA_INSTANCE);
     114             : 
     115             :     //<enabled xsi:nil="true"
     116             :     xmlNode  * nodeEn = xmlNewTextChild(
     117           0 :         root,NULL, (xmlChar*) "enabled", (xmlChar*) "");
     118           0 :     if (nodeEn == NULL)
     119           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     120           0 :     xmlSetNsProp(nodeEn,nsXsi,(xmlChar*) "nil",(xmlChar*) "true");
     121             :     //add a new line
     122           0 :     xmlNode * nodeCrLf = xmlNewText((xmlChar*) "\n");
     123           0 :     xmlAddChild(root, nodeCrLf);
     124             : 
     125             :     //<userClassPath xsi:nil="true">
     126             :     xmlNode  * nodeUs = xmlNewTextChild(
     127           0 :         root,NULL, (xmlChar*) "userClassPath", (xmlChar*) "");
     128           0 :     if (nodeUs == NULL)
     129           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     130           0 :     xmlSetNsProp(nodeUs,nsXsi,(xmlChar*) "nil",(xmlChar*) "true");
     131             :     //add a new line
     132           0 :     nodeCrLf = xmlNewText((xmlChar*) "\n");
     133           0 :     xmlAddChild(root, nodeCrLf);
     134             : 
     135             :     //<vmParameters xsi:nil="true">
     136             :     xmlNode  * nodeVm = xmlNewTextChild(
     137           0 :         root,NULL, (xmlChar*) "vmParameters", (xmlChar*) "");
     138           0 :     if (nodeVm == NULL)
     139           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     140           0 :     xmlSetNsProp(nodeVm,nsXsi,(xmlChar*) "nil",(xmlChar*) "true");
     141             :     //add a new line
     142           0 :     nodeCrLf = xmlNewText((xmlChar*) "\n");
     143           0 :     xmlAddChild(root, nodeCrLf);
     144             : 
     145             :     //<jreLocations xsi:nil="true">
     146             :     xmlNode  * nodeJre = xmlNewTextChild(
     147           0 :         root,NULL, (xmlChar*) "jreLocations", (xmlChar*) "");
     148           0 :     if (nodeJre == NULL)
     149           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     150           0 :     xmlSetNsProp(nodeJre,nsXsi,(xmlChar*) "nil",(xmlChar*) "true");
     151             :     //add a new line
     152           0 :     nodeCrLf = xmlNewText((xmlChar*) "\n");
     153           0 :     xmlAddChild(root, nodeCrLf);
     154             : 
     155             :     //<javaInfo xsi:nil="true">
     156             :     xmlNode  * nodeJava = xmlNewTextChild(
     157           0 :         root,NULL, (xmlChar*) "javaInfo", (xmlChar*) "");
     158           0 :     if (nodeJava == NULL)
     159           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     160           0 :     xmlSetNsProp(nodeJava,nsXsi,(xmlChar*) "nil",(xmlChar*) "true");
     161             :     //add a new line
     162           0 :     nodeCrLf = xmlNewText((xmlChar*) "\n");
     163           0 :     xmlAddChild(root, nodeCrLf);
     164             : }
     165             : 
     166             : 
     167             : //====================================================================
     168           0 : VersionInfo::VersionInfo(): arVersions(NULL)
     169             : {
     170           0 : }
     171             : 
     172           0 : VersionInfo::~VersionInfo()
     173             : {
     174           0 :     delete [] arVersions;
     175           0 : }
     176             : 
     177           0 : void VersionInfo::addExcludeVersion(const rtl::OUString& sVersion)
     178             : {
     179           0 :     vecExcludeVersions.push_back(sVersion);
     180           0 : }
     181             : 
     182           0 : rtl_uString** VersionInfo::getExcludeVersions()
     183             : {
     184           0 :     osl::MutexGuard guard(FwkMutex::get());
     185           0 :     if (arVersions != NULL)
     186           0 :         return arVersions;
     187             : 
     188           0 :     arVersions = new rtl_uString*[vecExcludeVersions.size()];
     189           0 :     int j=0;
     190             :     typedef std::vector<rtl::OUString>::const_iterator it;
     191           0 :     for (it i = vecExcludeVersions.begin(); i != vecExcludeVersions.end();
     192             :          ++i, ++j)
     193             :     {
     194           0 :         arVersions[j] = vecExcludeVersions[j].pData;
     195             :     }
     196           0 :     return arVersions;
     197             : }
     198             : 
     199           0 : sal_Int32 VersionInfo::getExcludeVersionSize()
     200             : {
     201           0 :     return vecExcludeVersions.size();
     202             : }
     203             : //==================================================================
     204             : 
     205           0 : NodeJava::NodeJava(Layer layer):
     206           0 :     m_layer(layer)
     207             : {
     208             :     //This class reads and write to files which should only be done in
     209             :     //application mode
     210           0 :     if (getMode() == JFW_MODE_DIRECT)
     211             :         throw FrameworkException(
     212             :             JFW_E_DIRECT_MODE,
     213           0 :             "[Java framework] Trying to access settings files in direct mode.");
     214           0 : }
     215             : 
     216             : 
     217           0 : void NodeJava::load()
     218             : {
     219             :     const rtl::OString sExcMsg("[Java framework] Error in function NodeJava::load"
     220           0 :                              "(elements.cxx).");
     221           0 :     if (SHARED == m_layer)
     222             :     {
     223             :         //we do not support yet to write into the shared installation
     224             : 
     225             :         //check if shared settings exist at all.
     226           0 :         OUString sURL(BootParams::getSharedData());
     227           0 :         jfw::FileStatus s = sURL.isEmpty()
     228           0 :             ? FILE_DOES_NOT_EXIST : checkFileURL(sURL);
     229           0 :         if (s == FILE_INVALID)
     230             :             throw FrameworkException(
     231             :                 JFW_E_ERROR,
     232           0 :                 "[Java framework] Invalid file for shared Java settings.");
     233           0 :         else if (s == FILE_DOES_NOT_EXIST)
     234             :             //Writing shared data is not supported yet.
     235           0 :             return;
     236             :     }
     237           0 :     else if (USER == m_layer)
     238             :     {
     239           0 :         if (!prepareSettingsDocument())
     240             :         {
     241             :             SAL_INFO("jvmfwk", "no path to load user settings document from");
     242             :             return;
     243             :         }
     244             :     }
     245             :     else
     246             :     {
     247             :         OSL_FAIL("[Java framework] Unknown enum used.");
     248             :     }
     249             : 
     250             : 
     251             :     //Read the user elements
     252           0 :     rtl::OString sSettingsPath = getSettingsPath();
     253             :     //There must not be a share settings file
     254           0 :     CXmlDocPtr docUser(xmlParseFile(sSettingsPath.getStr()));
     255           0 :     if (docUser == NULL)
     256           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     257             : 
     258           0 :     xmlNode * cur = xmlDocGetRootElement(docUser);
     259           0 :     if (cur == NULL || cur->children == NULL)
     260           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     261             : 
     262           0 :     CXmlCharPtr sNil;
     263           0 :     cur = cur->children;
     264           0 :     while (cur != NULL)
     265             :     {
     266           0 :         if (xmlStrcmp(cur->name, (xmlChar*) "enabled") == 0)
     267             :         {
     268             :             //only overwrite share settings if xsi:nil="false"
     269             :             sNil = xmlGetNsProp(
     270           0 :                 cur, (xmlChar*) "nil", (xmlChar*) NS_SCHEMA_INSTANCE);
     271           0 :             if (sNil == NULL)
     272           0 :                 throw FrameworkException(JFW_E_ERROR, sExcMsg);;
     273           0 :             if (xmlStrcmp(sNil, (xmlChar*) "false") == 0)
     274             :             {
     275             :                 CXmlCharPtr sEnabled( xmlNodeListGetString(
     276           0 :                     docUser, cur->children, 1));
     277           0 :                 if (xmlStrcmp(sEnabled, (xmlChar*) "true") == 0)
     278           0 :                     m_enabled = boost::optional<sal_Bool>(sal_True);
     279           0 :                 else if (xmlStrcmp(sEnabled, (xmlChar*) "false") == 0)
     280           0 :                     m_enabled = boost::optional<sal_Bool>(sal_False);
     281             :             }
     282             :         }
     283           0 :         else if (xmlStrcmp(cur->name, (xmlChar*) "userClassPath") == 0)
     284             :         {
     285             :             sNil = xmlGetNsProp(
     286           0 :                 cur, (xmlChar*) "nil", (xmlChar*) NS_SCHEMA_INSTANCE);
     287           0 :             if (sNil == NULL)
     288           0 :                 throw FrameworkException(JFW_E_ERROR, sExcMsg);
     289           0 :             if (xmlStrcmp(sNil, (xmlChar*) "false") == 0)
     290             :             {
     291             :                 CXmlCharPtr sUser(xmlNodeListGetString(
     292           0 :                     docUser, cur->children, 1));
     293           0 :                 m_userClassPath = boost::optional<rtl::OUString>(rtl::OUString(sUser));
     294             :             }
     295             :         }
     296           0 :         else if (xmlStrcmp(cur->name, (xmlChar*) "javaInfo") == 0)
     297             :         {
     298             :             sNil = xmlGetNsProp(
     299           0 :                 cur, (xmlChar*) "nil", (xmlChar*) NS_SCHEMA_INSTANCE);
     300           0 :             if (sNil == NULL)
     301           0 :                 throw FrameworkException(JFW_E_ERROR, sExcMsg);
     302             : 
     303           0 :             if (xmlStrcmp(sNil, (xmlChar*) "false") == 0)
     304             :             {
     305           0 :                 if (! m_javaInfo)
     306           0 :                     m_javaInfo = boost::optional<CNodeJavaInfo>(CNodeJavaInfo());
     307           0 :                 m_javaInfo->loadFromNode(docUser, cur);
     308             :             }
     309             :         }
     310           0 :         else if (xmlStrcmp(cur->name, (xmlChar*) "vmParameters") == 0)
     311             :         {
     312             :             sNil = xmlGetNsProp(
     313           0 :                 cur, (xmlChar*) "nil", (xmlChar*) NS_SCHEMA_INSTANCE);
     314           0 :             if (sNil == NULL)
     315           0 :                 throw FrameworkException(JFW_E_ERROR, sExcMsg);
     316           0 :             if (xmlStrcmp(sNil, (xmlChar*) "false") == 0)
     317             :             {
     318           0 :                 if ( ! m_vmParameters)
     319             :                     m_vmParameters = boost::optional<std::vector<rtl::OUString> >(
     320           0 :                         std::vector<rtl::OUString> ());
     321             : 
     322           0 :                 xmlNode * pOpt = cur->children;
     323           0 :                 while (pOpt != NULL)
     324             :                 {
     325           0 :                     if (xmlStrcmp(pOpt->name, (xmlChar*) "param") == 0)
     326             :                     {
     327           0 :                         CXmlCharPtr sOpt;
     328             :                         sOpt = xmlNodeListGetString(
     329           0 :                             docUser, pOpt->children, 1);
     330           0 :                         m_vmParameters->push_back(sOpt);
     331             :                     }
     332           0 :                     pOpt = pOpt->next;
     333             :                 }
     334             :             }
     335             :         }
     336           0 :         else if (xmlStrcmp(cur->name, (xmlChar*) "jreLocations") == 0)
     337             :         {
     338             :             sNil = xmlGetNsProp(
     339           0 :                 cur, (xmlChar*) "nil", (xmlChar*) NS_SCHEMA_INSTANCE);
     340           0 :             if (sNil == NULL)
     341           0 :                 throw FrameworkException(JFW_E_ERROR, sExcMsg);
     342           0 :             if (xmlStrcmp(sNil, (xmlChar*) "false") == 0)
     343             :             {
     344           0 :                 if (! m_JRELocations)
     345             :                     m_JRELocations = boost::optional<std::vector<rtl::OUString> >(
     346           0 :                         std::vector<rtl::OUString>());
     347             : 
     348           0 :                 xmlNode * pLoc = cur->children;
     349           0 :                 while (pLoc != NULL)
     350             :                 {
     351           0 :                     if (xmlStrcmp(pLoc->name, (xmlChar*) "location") == 0)
     352             :                     {
     353           0 :                         CXmlCharPtr sLoc;
     354             :                         sLoc = xmlNodeListGetString(
     355           0 :                             docUser, pLoc->children, 1);
     356           0 :                         m_JRELocations->push_back(sLoc);
     357             :                     }
     358           0 :                     pLoc = pLoc->next;
     359             :                 }
     360             :             }
     361             :         }
     362           0 :         cur = cur->next;
     363           0 :     }
     364             : }
     365             : 
     366           0 : ::rtl::OString NodeJava::getSettingsPath() const
     367             : {
     368           0 :     ::rtl::OString ret;
     369           0 :     switch (m_layer)
     370             :     {
     371           0 :     case USER: ret = getUserSettingsPath(); break;
     372           0 :     case SHARED: ret = getSharedSettingsPath(); break;
     373             :     default:
     374             :         OSL_FAIL("[Java framework] NodeJava::getSettingsPath()");
     375             :     }
     376           0 :     return ret;
     377             : }
     378             : 
     379           0 : ::rtl::OUString NodeJava::getSettingsURL() const
     380             : {
     381           0 :     ::rtl::OUString ret;
     382           0 :     switch (m_layer)
     383             :     {
     384           0 :     case USER: ret = BootParams::getUserData(); break;
     385           0 :     case SHARED: ret = BootParams::getSharedData(); break;
     386             :     default:
     387             :         OSL_FAIL("[Java framework] NodeJava::getSettingsURL()");
     388             :     }
     389           0 :     return ret;
     390             : }
     391             : 
     392           0 : bool NodeJava::prepareSettingsDocument() const
     393             : {
     394             :     rtl::OString sExcMsg(
     395             :         "[Java framework] Error in function prepareSettingsDocument"
     396           0 :         " (elements.cxx).");
     397           0 :     if (!createSettingsDocument())
     398             :     {
     399           0 :         return false;
     400             :     }
     401           0 :     rtl::OString sSettings = getSettingsPath();
     402           0 :     CXmlDocPtr doc(xmlParseFile(sSettings.getStr()));
     403           0 :     if (!doc)
     404           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     405             : 
     406           0 :     bool bNeedsSave = false;
     407           0 :     createSettingsStructure(doc, & bNeedsSave);
     408           0 :     if (bNeedsSave)
     409             :     {
     410           0 :         if (xmlSaveFormatFileEnc(
     411           0 :                 sSettings.getStr(), doc,"UTF-8", 1) == -1)
     412           0 :             throw FrameworkException(JFW_E_ERROR, sExcMsg);
     413             :     }
     414           0 :     return true;
     415             : }
     416             : 
     417           0 : void NodeJava::write() const
     418             : {
     419             :     rtl::OString sExcMsg("[Java framework] Error in function NodeJava::writeSettings "
     420           0 :                          "(elements.cxx).");
     421           0 :     CXmlDocPtr docUser;
     422           0 :     CXPathContextPtr contextUser;
     423           0 :     CXPathObjectPtr pathObj;
     424             : 
     425           0 :     if (!prepareSettingsDocument())
     426             :     {
     427             :         SAL_INFO("jvmfwk", "no path to write settings document to");
     428           0 :         return;
     429             :     }
     430             : 
     431             :     //Read the user elements
     432           0 :     rtl::OString sSettingsPath = getSettingsPath();
     433           0 :     docUser = xmlParseFile(sSettingsPath.getStr());
     434           0 :     if (docUser == NULL)
     435           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     436           0 :     contextUser = xmlXPathNewContext(docUser);
     437           0 :     if (xmlXPathRegisterNs(contextUser, (xmlChar*) "jf",
     438           0 :         (xmlChar*) NS_JAVA_FRAMEWORK) == -1)
     439           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     440             : 
     441           0 :     xmlNode * root = xmlDocGetRootElement(docUser);
     442             :     //Get xsi:nil namespace
     443             :     xmlNs* nsXsi = xmlSearchNsByHref(docUser,
     444             :                              root,
     445           0 :                              (xmlChar*)  NS_SCHEMA_INSTANCE);
     446             : 
     447             :     //set the <enabled> element
     448             :     //The element must exist
     449           0 :     if (m_enabled)
     450             :     {
     451             :         rtl::OString sExpression= rtl::OString(
     452           0 :             "/jf:java/jf:enabled");
     453           0 :         pathObj = xmlXPathEvalExpression((xmlChar*) sExpression.getStr(),
     454           0 :                                          contextUser);
     455           0 :         if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
     456           0 :             throw FrameworkException(JFW_E_ERROR, sExcMsg);
     457             : 
     458           0 :         xmlNode * nodeEnabled = pathObj->nodesetval->nodeTab[0];
     459             :         xmlSetNsProp(nodeEnabled,
     460             :                      nsXsi,
     461             :                      (xmlChar*) "nil",
     462           0 :                      (xmlChar*) "false");
     463             : 
     464           0 :         if (m_enabled == boost::optional<sal_Bool>(sal_True))
     465           0 :             xmlNodeSetContent(nodeEnabled,(xmlChar*) "true");
     466             :         else
     467           0 :             xmlNodeSetContent(nodeEnabled,(xmlChar*) "false");
     468             :     }
     469             : 
     470             :     //set the <userClassPath> element
     471             :     //The element must exist
     472           0 :     if (m_userClassPath)
     473             :     {
     474             :         rtl::OString sExpression= rtl::OString(
     475           0 :             "/jf:java/jf:userClassPath");
     476           0 :         pathObj = xmlXPathEvalExpression((xmlChar*) sExpression.getStr(),
     477           0 :                                          contextUser);
     478           0 :         if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
     479           0 :             throw FrameworkException(JFW_E_ERROR, sExcMsg);
     480             : 
     481           0 :         xmlNode * nodeEnabled = pathObj->nodesetval->nodeTab[0];
     482           0 :         xmlSetNsProp(nodeEnabled, nsXsi, (xmlChar*) "nil",(xmlChar*) "false");
     483           0 :         xmlNodeSetContent(nodeEnabled,(xmlChar*) CXmlCharPtr(*m_userClassPath));
     484             :     }
     485             : 
     486             :     //set <javaInfo> element
     487           0 :     if (m_javaInfo)
     488             :     {
     489             :         rtl::OString sExpression= rtl::OString(
     490           0 :             "/jf:java/jf:javaInfo");
     491           0 :         pathObj = xmlXPathEvalExpression((xmlChar*) sExpression.getStr(),
     492           0 :                                                 contextUser);
     493           0 :         if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
     494           0 :             throw FrameworkException(JFW_E_ERROR, sExcMsg);
     495             :         m_javaInfo->writeToNode(
     496           0 :             docUser, pathObj->nodesetval->nodeTab[0]);
     497             :     }
     498             : 
     499             :     //set <vmParameters> element
     500           0 :     if (m_vmParameters)
     501             :     {
     502             :         rtl::OString sExpression= rtl::OString(
     503           0 :             "/jf:java/jf:vmParameters");
     504           0 :         pathObj = xmlXPathEvalExpression((xmlChar*) sExpression.getStr(),
     505           0 :                                          contextUser);
     506           0 :         if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
     507           0 :             throw FrameworkException(JFW_E_ERROR, sExcMsg);
     508           0 :         xmlNode* vmParameters = pathObj->nodesetval->nodeTab[0];
     509             :         //set xsi:nil = false;
     510             :         xmlSetNsProp(vmParameters, nsXsi,(xmlChar*) "nil",
     511           0 :                      (xmlChar*) "false");
     512             : 
     513             :         //remove option elements
     514           0 :         xmlNode* cur = vmParameters->children;
     515           0 :         while (cur != NULL)
     516             :         {
     517           0 :             xmlNode* lastNode = cur;
     518           0 :             cur = cur->next;
     519           0 :             xmlUnlinkNode(lastNode);
     520           0 :             xmlFreeNode(lastNode);
     521             :         }
     522             :         //add a new line after <vmParameters>
     523           0 :         if (m_vmParameters->size() > 0)
     524             :         {
     525           0 :             xmlNode * nodeCrLf = xmlNewText((xmlChar*) "\n");
     526           0 :             xmlAddChild(vmParameters, nodeCrLf);
     527             :         }
     528             : 
     529             :         typedef std::vector<rtl::OUString>::const_iterator cit;
     530           0 :         for (cit i = m_vmParameters->begin(); i != m_vmParameters->end(); ++i)
     531             :         {
     532             :             xmlNewTextChild(vmParameters, NULL, (xmlChar*) "param",
     533           0 :                             CXmlCharPtr(*i));
     534             :             //add a new line
     535           0 :             xmlNode * nodeCrLf = xmlNewText((xmlChar*) "\n");
     536           0 :             xmlAddChild(vmParameters, nodeCrLf);
     537           0 :         }
     538             :     }
     539             : 
     540             :     //set <jreLocations> element
     541           0 :     if (m_JRELocations)
     542             :     {
     543             :         rtl::OString sExpression= rtl::OString(
     544           0 :             "/jf:java/jf:jreLocations");
     545           0 :         pathObj = xmlXPathEvalExpression((xmlChar*) sExpression.getStr(),
     546           0 :                                          contextUser);
     547           0 :         if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
     548           0 :             throw FrameworkException(JFW_E_ERROR, sExcMsg);
     549           0 :         xmlNode* jreLocationsNode = pathObj->nodesetval->nodeTab[0];
     550             :         //set xsi:nil = false;
     551             :         xmlSetNsProp(jreLocationsNode, nsXsi,(xmlChar*) "nil",
     552           0 :                      (xmlChar*) "false");
     553             : 
     554             :         //remove option elements
     555           0 :         xmlNode* cur = jreLocationsNode->children;
     556           0 :         while (cur != NULL)
     557             :         {
     558           0 :             xmlNode* lastNode = cur;
     559           0 :             cur = cur->next;
     560           0 :             xmlUnlinkNode(lastNode);
     561           0 :             xmlFreeNode(lastNode);
     562             :         }
     563             :         //add a new line after <vmParameters>
     564           0 :         if (m_JRELocations->size() > 0)
     565             :         {
     566           0 :             xmlNode * nodeCrLf = xmlNewText((xmlChar*) "\n");
     567           0 :             xmlAddChild(jreLocationsNode, nodeCrLf);
     568             :         }
     569             : 
     570             :         typedef std::vector<rtl::OUString>::const_iterator cit;
     571           0 :         for (cit i = m_JRELocations->begin(); i != m_JRELocations->end(); ++i)
     572             :         {
     573             :             xmlNewTextChild(jreLocationsNode, NULL, (xmlChar*) "location",
     574           0 :                             CXmlCharPtr(*i));
     575             :             //add a new line
     576           0 :             xmlNode * nodeCrLf = xmlNewText((xmlChar*) "\n");
     577           0 :             xmlAddChild(jreLocationsNode, nodeCrLf);
     578           0 :         }
     579             :     }
     580             : 
     581           0 :     if (xmlSaveFormatFile(sSettingsPath.getStr(), docUser, 1) == -1)
     582           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     583             : }
     584             : 
     585           0 : void NodeJava::setEnabled(sal_Bool bEnabled)
     586             : {
     587           0 :     m_enabled =  boost::optional<sal_Bool>(bEnabled);
     588           0 : }
     589             : 
     590             : 
     591           0 : void NodeJava::setUserClassPath(const rtl::OUString & sClassPath)
     592             : {
     593           0 :     m_userClassPath = boost::optional<rtl::OUString>(sClassPath);
     594           0 : }
     595             : 
     596           0 : void NodeJava::setJavaInfo(const JavaInfo * pInfo, bool bAutoSelect)
     597             : {
     598           0 :     if (!m_javaInfo)
     599           0 :         m_javaInfo = boost::optional<CNodeJavaInfo>(CNodeJavaInfo());
     600           0 :     m_javaInfo->bAutoSelect = bAutoSelect;
     601           0 :     m_javaInfo->bNil = false;
     602             : 
     603           0 :     if (pInfo != NULL)
     604             :     {
     605           0 :         m_javaInfo->m_bEmptyNode = false;
     606           0 :         m_javaInfo->sVendor = pInfo->sVendor;
     607           0 :         m_javaInfo->sLocation = pInfo->sLocation;
     608           0 :         m_javaInfo->sVersion = pInfo->sVersion;
     609           0 :         m_javaInfo->nFeatures = pInfo->nFeatures;
     610           0 :         m_javaInfo->nRequirements = pInfo->nRequirements;
     611           0 :         m_javaInfo->arVendorData = pInfo->arVendorData;
     612             :     }
     613             :     else
     614             :     {
     615           0 :         m_javaInfo->m_bEmptyNode = true;
     616           0 :         rtl::OUString sEmpty;
     617           0 :         m_javaInfo->sVendor = sEmpty;
     618           0 :         m_javaInfo->sLocation = sEmpty;
     619           0 :         m_javaInfo->sVersion = sEmpty;
     620           0 :         m_javaInfo->nFeatures = 0;
     621           0 :         m_javaInfo->nRequirements = 0;
     622           0 :         m_javaInfo->arVendorData = rtl::ByteSequence();
     623             :     }
     624           0 : }
     625             : 
     626           0 : void NodeJava::setVmParameters(rtl_uString * * arOptions, sal_Int32 size)
     627             : {
     628             :     OSL_ASSERT( !(arOptions == 0 && size != 0));
     629           0 :     if ( ! m_vmParameters)
     630             :         m_vmParameters = boost::optional<std::vector<rtl::OUString> >(
     631           0 :             std::vector<rtl::OUString>());
     632           0 :     m_vmParameters->clear();
     633           0 :     if (arOptions != NULL)
     634             :     {
     635           0 :         for (int i  = 0; i < size; i++)
     636             :         {
     637           0 :             const rtl::OUString sOption(static_cast<rtl_uString*>(arOptions[i]));
     638           0 :             m_vmParameters->push_back(sOption);
     639           0 :         }
     640             :     }
     641           0 : }
     642             : 
     643           0 : void NodeJava::setJRELocations(rtl_uString  * * arLocations, sal_Int32 size)
     644             : {
     645             :     OSL_ASSERT( !(arLocations == 0 && size != 0));
     646           0 :     if (! m_JRELocations)
     647             :         m_JRELocations = boost::optional<std::vector<rtl::OUString> > (
     648           0 :             std::vector<rtl::OUString>());
     649           0 :     m_JRELocations->clear();
     650           0 :     if (arLocations != NULL)
     651             :     {
     652           0 :         for (int i  = 0; i < size; i++)
     653             :         {
     654           0 :             const rtl::OUString & sLocation = static_cast<rtl_uString*>(arLocations[i]);
     655             : 
     656             :             //only add the path if not already present
     657             :             std::vector<rtl::OUString>::const_iterator it =
     658             :                 std::find(m_JRELocations->begin(), m_JRELocations->end(),
     659           0 :                           sLocation);
     660           0 :             if (it == m_JRELocations->end())
     661           0 :                 m_JRELocations->push_back(sLocation);
     662           0 :         }
     663             :     }
     664           0 : }
     665             : 
     666           0 : void NodeJava::addJRELocation(rtl_uString * sLocation)
     667             : {
     668             :     OSL_ASSERT( sLocation);
     669           0 :     if (!m_JRELocations)
     670             :         m_JRELocations = boost::optional<std::vector<rtl::OUString> >(
     671           0 :             std::vector<rtl::OUString> ());
     672             :      //only add the path if not already present
     673             :     std::vector<rtl::OUString>::const_iterator it =
     674             :         std::find(m_JRELocations->begin(), m_JRELocations->end(),
     675           0 :                   rtl::OUString(sLocation));
     676           0 :     if (it == m_JRELocations->end())
     677           0 :         m_JRELocations->push_back(rtl::OUString(sLocation));
     678           0 : }
     679             : 
     680           0 : const boost::optional<sal_Bool> & NodeJava::getEnabled() const
     681             : {
     682           0 :     return m_enabled;
     683             : }
     684             : 
     685             : const boost::optional<std::vector<rtl::OUString> >&
     686           0 : NodeJava::getJRELocations() const
     687             : {
     688           0 :     return m_JRELocations;
     689             : }
     690             : 
     691           0 : const boost::optional<rtl::OUString> & NodeJava::getUserClassPath() const
     692             : {
     693           0 :     return m_userClassPath;
     694             : }
     695             : 
     696           0 : const boost::optional<std::vector<rtl::OUString> > & NodeJava::getVmParameters() const
     697             : {
     698           0 :     return m_vmParameters;
     699             : }
     700             : 
     701           0 : const boost::optional<CNodeJavaInfo> & NodeJava::getJavaInfo() const
     702             : {
     703           0 :     return m_javaInfo;
     704             : }
     705             : 
     706           0 : jfw::FileStatus NodeJava::checkSettingsFileStatus(OUString const & sURL) const
     707             : {
     708           0 :     jfw::FileStatus ret = FILE_DOES_NOT_EXIST;
     709             : 
     710             :     //check the file time
     711           0 :     ::osl::DirectoryItem item;
     712           0 :     File::RC rc = ::osl::DirectoryItem::get(sURL, item);
     713           0 :     if (File::E_None == rc)
     714             :     {
     715           0 :         ::osl::FileStatus stat(osl_FileStatus_Mask_Validate);
     716           0 :         File::RC rc_stat = item.getFileStatus(stat);
     717           0 :         if (File::E_None == rc_stat)
     718             :         {
     719           0 :             ret = FILE_OK;
     720             :         }
     721           0 :         else if (File::E_NOENT == rc_stat)
     722             :         {
     723           0 :             ret = FILE_DOES_NOT_EXIST;
     724             :         }
     725             :         else
     726             :         {
     727           0 :             ret = FILE_INVALID;
     728           0 :         }
     729             :     }
     730           0 :     else if(File::E_NOENT == rc)
     731             :     {
     732           0 :         ret = FILE_DOES_NOT_EXIST;
     733             :     }
     734             :     else
     735             :     {
     736           0 :         ret = FILE_INVALID;
     737             :     }
     738           0 :     return ret;
     739             : }
     740             : 
     741           0 : bool NodeJava::createSettingsDocument() const
     742             : {
     743           0 :     const rtl::OUString sURL = getSettingsURL();
     744           0 :     if (sURL.isEmpty())
     745             :     {
     746           0 :         return false;
     747             :     }
     748             :     //make sure there is a user directory
     749             :     rtl::OString sExcMsg("[Java framework] Error in function createSettingsDocument "
     750           0 :                          "(elements.cxx).");
     751             :     // check if javasettings.xml already exist
     752           0 :     if (FILE_OK == checkSettingsFileStatus(sURL))
     753           0 :         return true;
     754             : 
     755             :     //make sure that the directories are created in case they do not exist
     756           0 :     FileBase::RC rcFile = Directory::createPath(getDirFromFile(sURL));
     757           0 :     if (rcFile != FileBase::E_EXIST && rcFile != FileBase::E_None)
     758           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     759             : 
     760             :     //javasettings.xml does not exist yet
     761           0 :     CXmlDocPtr doc(xmlNewDoc((xmlChar *)"1.0"));
     762           0 :     if (! doc)
     763           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     764             :     //Create a comment
     765             :     xmlNewDocComment(
     766           0 :         doc, (xmlChar *) "This is a generated file. Do not alter this file!");
     767             : 
     768             :     //Create the root element and name spaces
     769             :     xmlNodePtr root =   xmlNewDocNode(
     770           0 :         doc, NULL, (xmlChar *) "java", (xmlChar *) "\n");
     771             : 
     772           0 :     if (root == NULL)
     773           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     774             : 
     775           0 :     if (xmlNewNs(root, (xmlChar *) NS_JAVA_FRAMEWORK,NULL) == NULL)
     776           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     777           0 :     if (xmlNewNs(root,(xmlChar*) NS_SCHEMA_INSTANCE,(xmlChar*)"xsi") == NULL)
     778           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     779           0 :     xmlDocSetRootElement(doc,  root);
     780             : 
     781             :     //Create a comment
     782             :     xmlNodePtr com = xmlNewComment(
     783           0 :         (xmlChar *) "This is a generated file. Do not alter this file!");
     784           0 :     if (com == NULL)
     785           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     786             : 
     787           0 :     if (xmlAddPrevSibling(root, com) == NULL)
     788           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     789             : 
     790           0 :     const rtl::OString path = getSettingsPath();
     791           0 :     if (xmlSaveFormatFileEnc(path.getStr(), doc,"UTF-8", 1) == -1)
     792           0 :          throw FrameworkException(JFW_E_ERROR, sExcMsg);
     793           0 :     return true;
     794             : }
     795             : 
     796             : //=====================================================================
     797           0 : CNodeJavaInfo::CNodeJavaInfo() :
     798             :     m_bEmptyNode(false), bNil(true), bAutoSelect(true),
     799           0 :     nFeatures(0), nRequirements(0)
     800             : {
     801           0 : }
     802             : 
     803           0 : CNodeJavaInfo::~CNodeJavaInfo()
     804             : {
     805           0 : }
     806             : 
     807           0 : void CNodeJavaInfo::loadFromNode(xmlDoc * pDoc, xmlNode * pJavaInfo)
     808             : {
     809             :     rtl::OString sExcMsg("[Java framework] Error in function NodeJavaInfo::loadFromNode "
     810           0 :                          "(elements.cxx).");
     811             : 
     812             :     OSL_ASSERT(pJavaInfo && pDoc);
     813           0 :     if (pJavaInfo->children == NULL)
     814             :         return;
     815             :     //Get the xsi:nil attribute;
     816           0 :     CXmlCharPtr sNil;
     817             :     sNil = xmlGetNsProp(
     818           0 :         pJavaInfo, (xmlChar*) "nil", (xmlChar*) NS_SCHEMA_INSTANCE);
     819           0 :     if ( ! sNil)
     820           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     821             : 
     822           0 :     if (xmlStrcmp(sNil, (xmlChar*) "true") == 0)
     823           0 :         bNil = true;
     824           0 :     else if (xmlStrcmp(sNil, (xmlChar*) "false") == 0)
     825           0 :         bNil = false;
     826             :     else
     827           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     828           0 :     if (bNil == true)
     829             :         return;
     830             : 
     831             :     //Get javaInfo@manuallySelected attribute
     832           0 :     CXmlCharPtr sAutoSelect;
     833             :     sAutoSelect = xmlGetProp(
     834           0 :         pJavaInfo, (xmlChar*) "autoSelect");
     835           0 :     if ( ! sAutoSelect)
     836           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     837             : 
     838           0 :     if (xmlStrcmp(sAutoSelect, (xmlChar*) "true") == 0)
     839           0 :         bAutoSelect = true;
     840           0 :     else if (xmlStrcmp(sAutoSelect, (xmlChar*) "false") == 0)
     841           0 :         bAutoSelect = false;
     842             :     else
     843           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     844             : 
     845           0 :     xmlNode * cur = pJavaInfo->children;
     846             : 
     847           0 :     while (cur != NULL)
     848             :     {
     849           0 :         if (xmlStrcmp(cur->name, (xmlChar*) "vendor") == 0)
     850             :         {
     851           0 :             CXmlCharPtr xmlVendor;
     852             :             xmlVendor = xmlNodeListGetString(
     853           0 :                 pDoc, cur->children, 1);
     854           0 :             if (! xmlVendor)
     855             :                 return;
     856           0 :             sVendor = xmlVendor;
     857             :         }
     858           0 :         else if (xmlStrcmp(cur->name, (xmlChar*) "location") == 0)
     859             :         {
     860           0 :             CXmlCharPtr xmlLocation;
     861             :             xmlLocation = xmlNodeListGetString(
     862           0 :                 pDoc, cur->children, 1);
     863           0 :             sLocation = xmlLocation;
     864             :         }
     865           0 :         else if (xmlStrcmp(cur->name, (xmlChar*) "version") == 0)
     866             :         {
     867           0 :             CXmlCharPtr xmlVersion;
     868             :             xmlVersion = xmlNodeListGetString(
     869           0 :                 pDoc, cur->children, 1);
     870           0 :             sVersion = xmlVersion;
     871             :         }
     872           0 :         else if (xmlStrcmp(cur->name, (xmlChar*) "features")== 0)
     873             :         {
     874           0 :             CXmlCharPtr xmlFeatures;
     875             :             xmlFeatures = xmlNodeListGetString(
     876           0 :                     pDoc, cur->children, 1);
     877           0 :             rtl::OUString sFeatures = xmlFeatures;
     878           0 :             nFeatures = sFeatures.toInt64(16);
     879             :         }
     880           0 :         else if (xmlStrcmp(cur->name, (xmlChar*) "requirements") == 0)
     881             :         {
     882           0 :             CXmlCharPtr xmlRequire;
     883             :             xmlRequire = xmlNodeListGetString(
     884           0 :                 pDoc, cur->children, 1);
     885           0 :             rtl::OUString sRequire = xmlRequire;
     886           0 :             nRequirements = sRequire.toInt64(16);
     887             : #ifdef MACOSX
     888             :             //javaldx is not used anymore in the mac build. In case the Java
     889             :             //corresponding to the saved settings does not exist anymore the
     890             :             //javavm services will look for an existing Java after creation of
     891             :             //the JVM failed. See stoc/source/javavm/javavm.cxx. Only if
     892             :             //nRequirements does not have the flag JFW_REQUIRE_NEEDRESTART the
     893             :             //jvm of the new selected JRE will be started. Old settings (before
     894             :             //OOo 3.3) still contain the flag which can be safely ignored.
     895             :             nRequirements &= ~JFW_REQUIRE_NEEDRESTART;
     896             : #endif
     897             :         }
     898           0 :         else if (xmlStrcmp(cur->name, (xmlChar*) "vendorData") == 0)
     899             :         {
     900           0 :             CXmlCharPtr xmlData;
     901             :             xmlData = xmlNodeListGetString(
     902           0 :                 pDoc, cur->children, 1);
     903           0 :             xmlChar* _data = (xmlChar*) xmlData;
     904           0 :             if (_data)
     905             :             {
     906           0 :                 rtl::ByteSequence seq((sal_Int8*) _data, strlen((char*)_data));
     907           0 :                 arVendorData = decodeBase16(seq);
     908           0 :             }
     909             :         }
     910           0 :         cur = cur->next;
     911             :     }
     912             : 
     913           0 :     if (sVendor.isEmpty())
     914           0 :         m_bEmptyNode = true;
     915             :     //Get the javainfo attributes
     916           0 :     CXmlCharPtr sVendorUpdate;
     917             :     sVendorUpdate = xmlGetProp(pJavaInfo,
     918           0 :                                (xmlChar*) "vendorUpdate");
     919           0 :     if ( ! sVendorUpdate)
     920           0 :         throw FrameworkException(JFW_E_ERROR, sExcMsg);
     921           0 :     sAttrVendorUpdate = sVendorUpdate;
     922             : }
     923             : 
     924             : 
     925           0 : void CNodeJavaInfo::writeToNode(xmlDoc* pDoc,
     926             :                                 xmlNode* pJavaInfoNode) const
     927             : 
     928             : {
     929             :     OSL_ASSERT(pJavaInfoNode && pDoc);
     930             :     //write the attribute vendorSettings
     931             : 
     932             :     //javaInfo@vendorUpdate
     933             :     //creates the attribute if necessary
     934           0 :     rtl::OString sUpdated = getElementUpdated();
     935             : 
     936             :     xmlSetProp(pJavaInfoNode, (xmlChar*)"vendorUpdate",
     937           0 :                (xmlChar*) sUpdated.getStr());
     938             : 
     939             :     //javaInfo@autoSelect
     940             :     xmlSetProp(pJavaInfoNode, (xmlChar*)"autoSelect",
     941           0 :                (xmlChar*) (bAutoSelect == true ? "true" : "false"));
     942             : 
     943             :     //Set xsi:nil in javaInfo element to false
     944             :     //the xmlNs pointer must not be destroyed
     945             :     xmlNs* nsXsi = xmlSearchNsByHref((xmlDoc*) pDoc,
     946             :                              pJavaInfoNode,
     947           0 :                              (xmlChar*)  NS_SCHEMA_INSTANCE);
     948             : 
     949             :     xmlSetNsProp(pJavaInfoNode,
     950             :                  nsXsi,
     951             :                  (xmlChar*) "nil",
     952           0 :                  (xmlChar*) "false");
     953             : 
     954             :     //Delete the children of JavaInfo
     955           0 :     xmlNode* cur = pJavaInfoNode->children;
     956           0 :     while (cur != NULL)
     957             :     {
     958           0 :         xmlNode* lastNode = cur;
     959           0 :         cur = cur->next;
     960           0 :         xmlUnlinkNode(lastNode);
     961           0 :         xmlFreeNode(lastNode);
     962             :     }
     963             : 
     964             :     //If the JavaInfo was set with an empty value,
     965             :     //then we are done.
     966           0 :     if (m_bEmptyNode)
     967           0 :         return;
     968             : 
     969             :     //add a new line after <javaInfo>
     970           0 :     xmlNode * nodeCrLf = xmlNewText((xmlChar*) "\n");
     971           0 :     xmlAddChild(pJavaInfoNode, nodeCrLf);
     972             : 
     973             :     //Create the vendor element
     974             :     xmlNewTextChild(pJavaInfoNode, NULL, (xmlChar*) "vendor",
     975           0 :                     CXmlCharPtr(sVendor));
     976             :     //add a new line for better readability
     977           0 :     nodeCrLf = xmlNewText((xmlChar*) "\n");
     978           0 :     xmlAddChild(pJavaInfoNode, nodeCrLf);
     979             : 
     980             :     //Create the location element
     981             :     xmlNewTextChild(pJavaInfoNode, NULL, (xmlChar*) "location",
     982           0 :                     CXmlCharPtr(sLocation));
     983             :     //add a new line for better readability
     984           0 :     nodeCrLf = xmlNewText((xmlChar*) "\n");
     985           0 :     xmlAddChild(pJavaInfoNode, nodeCrLf);
     986             : 
     987             :     //Create the version element
     988             :     xmlNewTextChild(pJavaInfoNode, NULL, (xmlChar*) "version",
     989           0 :                     CXmlCharPtr(sVersion));
     990             :     //add a new line for better readability
     991           0 :     nodeCrLf = xmlNewText((xmlChar*) "\n");
     992           0 :     xmlAddChild(pJavaInfoNode, nodeCrLf);
     993             : 
     994             :     //Create the features element
     995             :     rtl::OUString sFeatures = rtl::OUString::valueOf(
     996           0 :         (sal_Int64)nFeatures, 16);
     997             :     xmlNewTextChild(pJavaInfoNode, NULL, (xmlChar*) "features",
     998           0 :                     CXmlCharPtr(sFeatures));
     999             :     //add a new line for better readability
    1000           0 :     nodeCrLf = xmlNewText((xmlChar*) "\n");
    1001           0 :     xmlAddChild(pJavaInfoNode, nodeCrLf);
    1002             : 
    1003             : 
    1004             :     //Create the requirements element
    1005             :     rtl::OUString sRequirements = rtl::OUString::valueOf(
    1006           0 :         (sal_Int64) nRequirements, 16);
    1007             :     xmlNewTextChild(pJavaInfoNode, NULL, (xmlChar*) "requirements",
    1008           0 :                     CXmlCharPtr(sRequirements));
    1009             :     //add a new line for better readability
    1010           0 :     nodeCrLf = xmlNewText((xmlChar*) "\n");
    1011           0 :     xmlAddChild(pJavaInfoNode, nodeCrLf);
    1012             : 
    1013             : 
    1014             :     //Create the features element
    1015           0 :     rtl::ByteSequence data = encodeBase16(arVendorData);
    1016             :     xmlNode* dataNode = xmlNewChild(pJavaInfoNode, NULL,
    1017             :                                     (xmlChar*) "vendorData",
    1018           0 :                                     (xmlChar*) "");
    1019             :     xmlNodeSetContentLen(dataNode,
    1020           0 :                          (xmlChar*) data.getArray(), data.getLength());
    1021             :     //add a new line for better readability
    1022           0 :     nodeCrLf = xmlNewText((xmlChar*) "\n");
    1023           0 :     xmlAddChild(pJavaInfoNode, nodeCrLf);
    1024             : }
    1025             : 
    1026           0 : JavaInfo * CNodeJavaInfo::makeJavaInfo() const
    1027             : {
    1028           0 :     if (bNil == true || m_bEmptyNode == true)
    1029           0 :         return NULL;
    1030           0 :     JavaInfo * pInfo = (JavaInfo*) rtl_allocateMemory(sizeof(JavaInfo));
    1031           0 :     if (pInfo == NULL)
    1032           0 :         return NULL;
    1033           0 :     memset(pInfo, 0, sizeof(JavaInfo));
    1034           0 :     pInfo->sVendor = sVendor.pData;
    1035           0 :     rtl_uString_acquire(pInfo->sVendor);
    1036           0 :     pInfo->sLocation = sLocation.pData;
    1037           0 :     rtl_uString_acquire(pInfo->sLocation);
    1038           0 :     pInfo->sVersion = sVersion.pData;
    1039           0 :     rtl_uString_acquire(pInfo->sVersion);
    1040           0 :     pInfo->nFeatures = nFeatures;
    1041           0 :     pInfo->nRequirements = nRequirements;
    1042           0 :     pInfo->arVendorData = arVendorData.getHandle();
    1043           0 :     rtl_byte_sequence_acquire(pInfo->arVendorData);
    1044           0 :     return pInfo;
    1045             : }
    1046             : 
    1047             : //================================================================================
    1048           0 : MergedSettings::MergedSettings():
    1049             :     m_bEnabled(false),
    1050             :     m_sClassPath(),
    1051             :     m_vmParams(),
    1052             :     m_JRELocations(),
    1053           0 :     m_javaInfo()
    1054             : {
    1055           0 :     NodeJava settings(NodeJava::USER);
    1056           0 :     settings.load();
    1057           0 :     NodeJava sharedSettings(NodeJava::SHARED);
    1058           0 :     sharedSettings.load();
    1059           0 :     merge(sharedSettings, settings);
    1060           0 : }
    1061             : 
    1062           0 : MergedSettings::~MergedSettings()
    1063             : {
    1064           0 : }
    1065             : 
    1066           0 : void MergedSettings::merge(const NodeJava & share, const NodeJava & user)
    1067             : {
    1068           0 :     if (user.getEnabled())
    1069           0 :         m_bEnabled = * user.getEnabled();
    1070           0 :     else if (share.getEnabled())
    1071           0 :         m_bEnabled = * share.getEnabled();
    1072             :     else
    1073           0 :         m_bEnabled = sal_True;
    1074             : 
    1075           0 :     if (user.getUserClassPath())
    1076           0 :         m_sClassPath = * user.getUserClassPath();
    1077           0 :     else if (share.getUserClassPath())
    1078           0 :         m_sClassPath = * share.getUserClassPath();
    1079             : 
    1080           0 :     if (user.getJavaInfo())
    1081           0 :         m_javaInfo = * user.getJavaInfo();
    1082           0 :     else if (share.getJavaInfo())
    1083           0 :         m_javaInfo = * share.getJavaInfo();
    1084             : 
    1085           0 :     if (user.getVmParameters())
    1086           0 :         m_vmParams = * user.getVmParameters();
    1087           0 :     else if (share.getVmParameters())
    1088           0 :          m_vmParams = * share.getVmParameters();
    1089             : 
    1090           0 :     if (user.getJRELocations())
    1091           0 :         m_JRELocations = * user.getJRELocations();
    1092           0 :     else if (share.getJRELocations())
    1093           0 :         m_JRELocations = * share.getJRELocations();
    1094           0 : }
    1095             : 
    1096           0 : bool MergedSettings::getEnabled() const
    1097             : {
    1098           0 :     return m_bEnabled;
    1099             : }
    1100           0 : const rtl::OUString&  MergedSettings::getUserClassPath() const
    1101             : {
    1102           0 :     return m_sClassPath;
    1103             : }
    1104             : 
    1105           0 : ::std::vector< ::rtl::OString> MergedSettings::getVmParametersUtf8() const
    1106             : {
    1107           0 :     ::std::vector< ::rtl::OString> ret;
    1108             :     typedef ::std::vector< ::rtl::OUString>::const_iterator cit;
    1109           0 :     for (cit i = m_vmParams.begin(); i != m_vmParams.end(); ++i)
    1110             :     {
    1111           0 :         ret.push_back( ::rtl::OUStringToOString(*i, RTL_TEXTENCODING_UTF8));
    1112             :     }
    1113           0 :     return ret;
    1114             : }
    1115             : 
    1116           0 : const ::rtl::OString  & MergedSettings::getJavaInfoAttrVendorUpdate() const
    1117             : {
    1118           0 :     return m_javaInfo.sAttrVendorUpdate;
    1119             : }
    1120             : 
    1121             : 
    1122           0 : JavaInfo * MergedSettings::createJavaInfo() const
    1123             : {
    1124           0 :     return m_javaInfo.makeJavaInfo();
    1125             : }
    1126             : #ifdef WNT
    1127             : bool MergedSettings::getJavaInfoAttrAutoSelect() const
    1128             : {
    1129             :     return m_javaInfo.bAutoSelect;
    1130             : }
    1131             : #endif
    1132           0 : void MergedSettings::getVmParametersArray(
    1133             :     rtl_uString *** parParams, sal_Int32 * size) const
    1134             : {
    1135           0 :     osl::MutexGuard guard(FwkMutex::get());
    1136             :     OSL_ASSERT(parParams != NULL && size != NULL);
    1137             : 
    1138             :     *parParams = (rtl_uString **)
    1139           0 :         rtl_allocateMemory(sizeof(rtl_uString*) * m_vmParams.size());
    1140           0 :     if (*parParams == NULL)
    1141           0 :         return;
    1142             : 
    1143           0 :     int j=0;
    1144             :     typedef std::vector<rtl::OUString>::const_iterator it;
    1145           0 :     for (it i = m_vmParams.begin(); i != m_vmParams.end();
    1146             :          ++i, ++j)
    1147             :     {
    1148           0 :         (*parParams)[j] = i->pData;
    1149           0 :         rtl_uString_acquire(i->pData);
    1150             :     }
    1151           0 :     *size = m_vmParams.size();
    1152             : }
    1153             : 
    1154           0 : void MergedSettings::getJRELocations(
    1155             :     rtl_uString *** parLocations, sal_Int32 * size) const
    1156             : {
    1157           0 :     osl::MutexGuard guard(FwkMutex::get());
    1158             :     OSL_ASSERT(parLocations != NULL && size != NULL);
    1159             : 
    1160             :     *parLocations = (rtl_uString **)
    1161           0 :         rtl_allocateMemory(sizeof(rtl_uString*) * m_JRELocations.size());
    1162           0 :     if (*parLocations == NULL)
    1163           0 :         return;
    1164             : 
    1165           0 :     int j=0;
    1166             :     typedef std::vector<rtl::OUString>::const_iterator it;
    1167           0 :     for (it i = m_JRELocations.begin(); i != m_JRELocations.end();
    1168             :          ++i, ++j)
    1169             :     {
    1170           0 :         (*parLocations)[j] = i->pData;
    1171           0 :         rtl_uString_acquire(i->pData);
    1172             :     }
    1173           0 :     *size = m_JRELocations.size();
    1174             : }
    1175           0 : const std::vector<rtl::OUString> & MergedSettings::getJRELocations() const
    1176             : {
    1177           0 :     return m_JRELocations;
    1178             : }
    1179             : }
    1180             : 
    1181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10