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