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

Generated by: LCOV version 1.10