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