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 31*cdf0e10cSrcweir #include "osl/file.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "vendorbase.hxx" 34*cdf0e10cSrcweir #include "util.hxx" 35*cdf0e10cSrcweir #include "sunjre.hxx" 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir using namespace std; 38*cdf0e10cSrcweir using namespace rtl; 39*cdf0e10cSrcweir using namespace osl; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir namespace jfw_plugin 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir rtl::Reference<VendorBase> createInstance(createInstance_func pFunc, 44*cdf0e10cSrcweir vector<pair<OUString, OUString> > properties); 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir //############################################################################## 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir MalformedVersionException::MalformedVersionException() 55*cdf0e10cSrcweir {} 56*cdf0e10cSrcweir MalformedVersionException::MalformedVersionException( 57*cdf0e10cSrcweir const MalformedVersionException & ) 58*cdf0e10cSrcweir {} 59*cdf0e10cSrcweir MalformedVersionException::~MalformedVersionException() 60*cdf0e10cSrcweir {} 61*cdf0e10cSrcweir MalformedVersionException & 62*cdf0e10cSrcweir MalformedVersionException::operator =( 63*cdf0e10cSrcweir const MalformedVersionException &) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir return *this; 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir //############################################################################## 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir VendorBase::VendorBase(): m_bAccessibility(false) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir char const* const * VendorBase::getJavaExePaths(int* size) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir static char const * ar[] = { 77*cdf0e10cSrcweir #if defined(WNT) || defined(OS2) 78*cdf0e10cSrcweir "java.exe", 79*cdf0e10cSrcweir "bin/java.exe" 80*cdf0e10cSrcweir #elif UNX 81*cdf0e10cSrcweir "java", 82*cdf0e10cSrcweir "bin/java" 83*cdf0e10cSrcweir #endif 84*cdf0e10cSrcweir }; 85*cdf0e10cSrcweir *size = sizeof(ar) / sizeof(char*); 86*cdf0e10cSrcweir return ar; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir rtl::Reference<VendorBase> VendorBase::createInstance() 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir VendorBase *pBase = new VendorBase(); 93*cdf0e10cSrcweir return rtl::Reference<VendorBase>(pBase); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir bool VendorBase::initialize(vector<pair<OUString, OUString> > props) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir //get java.vendor, java.version, java.home, 99*cdf0e10cSrcweir //javax.accessibility.assistive_technologies from system properties 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir OUString sVendor; 102*cdf0e10cSrcweir typedef vector<pair<OUString, OUString> >::const_iterator it_prop; 103*cdf0e10cSrcweir OUString sVendorProperty( 104*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("java.vendor")); 105*cdf0e10cSrcweir OUString sVersionProperty( 106*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("java.version")); 107*cdf0e10cSrcweir OUString sHomeProperty( 108*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("java.home")); 109*cdf0e10cSrcweir OUString sAccessProperty( 110*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("javax.accessibility.assistive_technologies")); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir bool bVersion = false; 113*cdf0e10cSrcweir bool bVendor = false; 114*cdf0e10cSrcweir bool bHome = false; 115*cdf0e10cSrcweir bool bAccess = false; 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir typedef vector<pair<OUString, OUString> >::const_iterator it_prop; 118*cdf0e10cSrcweir for (it_prop i = props.begin(); i != props.end(); i++) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir if(! bVendor && sVendorProperty.equals(i->first)) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir m_sVendor = i->second; 123*cdf0e10cSrcweir bVendor = true; 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir else if (!bVersion && sVersionProperty.equals(i->first)) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir m_sVersion = i->second; 128*cdf0e10cSrcweir bVersion = true; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir else if (!bHome && sHomeProperty.equals(i->first)) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir OUString fileURL; 133*cdf0e10cSrcweir if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) == 134*cdf0e10cSrcweir osl_File_E_None) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir //make sure that the drive letter have all the same case 137*cdf0e10cSrcweir //otherwise file:///c:/jre and file:///C:/jre produce two 138*cdf0e10cSrcweir //different objects!!! 139*cdf0e10cSrcweir if (makeDriveLetterSame( & fileURL)) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir m_sHome = fileURL; 142*cdf0e10cSrcweir bHome = true; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir else if (!bAccess && sAccessProperty.equals(i->first)) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir if (i->second.getLength() > 0) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir m_bAccessibility = true; 151*cdf0e10cSrcweir bAccess = true; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir // the javax.accessibility.xxx property may not be set. Therefore we 155*cdf0e10cSrcweir //must search through all properties. 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir if (!bVersion || !bVendor || !bHome) 159*cdf0e10cSrcweir return false; 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir // init m_sRuntimeLibrary 162*cdf0e10cSrcweir OSL_ASSERT(m_sHome.getLength()); 163*cdf0e10cSrcweir //call virtual function to get the possible paths to the runtime library. 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir int size = 0; 166*cdf0e10cSrcweir char const* const* arRtPaths = getRuntimePaths( & size); 167*cdf0e10cSrcweir vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir bool bRt = false; 170*cdf0e10cSrcweir typedef vector<OUString>::const_iterator i_path; 171*cdf0e10cSrcweir for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir //Construct an absolute path to the possible runtime 174*cdf0e10cSrcweir OUString usRt= m_sHome + *ip; 175*cdf0e10cSrcweir DirectoryItem item; 176*cdf0e10cSrcweir if(DirectoryItem::get(usRt, item) == File::E_None) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir //found runtime lib 179*cdf0e10cSrcweir m_sRuntimeLibrary = usRt; 180*cdf0e10cSrcweir bRt = true; 181*cdf0e10cSrcweir break; 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir if (!bRt) 185*cdf0e10cSrcweir return false; 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // init m_sLD_LIBRARY_PATH 188*cdf0e10cSrcweir OSL_ASSERT(m_sHome.getLength()); 189*cdf0e10cSrcweir size = 0; 190*cdf0e10cSrcweir char const * const * arLDPaths = getLibraryPaths( & size); 191*cdf0e10cSrcweir vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir char arSep[]= {SAL_PATHSEPARATOR, 0}; 194*cdf0e10cSrcweir OUString sPathSep= OUString::createFromAscii(arSep); 195*cdf0e10cSrcweir bool bLdPath = true; 196*cdf0e10cSrcweir int c = 0; 197*cdf0e10cSrcweir for(i_path il = ld_paths.begin(); il != ld_paths.end(); il ++, c++) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir OUString usAbsUrl= m_sHome + *il; 200*cdf0e10cSrcweir // convert to system path 201*cdf0e10cSrcweir OUString usSysPath; 202*cdf0e10cSrcweir if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir if(c > 0) 206*cdf0e10cSrcweir m_sLD_LIBRARY_PATH+= sPathSep; 207*cdf0e10cSrcweir m_sLD_LIBRARY_PATH+= usSysPath; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir else 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir bLdPath = false; 212*cdf0e10cSrcweir break; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir if (bLdPath == false) 216*cdf0e10cSrcweir return false; 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir return true; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir char const* const* VendorBase::getRuntimePaths(int* /*size*/) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir return NULL; 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir char const* const* VendorBase::getLibraryPaths(int* /*size*/) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir return NULL; 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir const OUString & VendorBase::getVendor() const 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir return m_sVendor; 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir const OUString & VendorBase::getVersion() const 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir return m_sVersion; 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir const OUString & VendorBase::getHome() const 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir return m_sHome; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir const OUString & VendorBase::getLibraryPaths() const 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir return m_sLD_LIBRARY_PATH; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir const OUString & VendorBase::getRuntimeLibrary() const 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir return m_sRuntimeLibrary; 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir bool VendorBase::supportsAccessibility() const 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir return m_bAccessibility; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir bool VendorBase::needsRestart() const 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir if (getLibraryPaths().getLength() > 0) 262*cdf0e10cSrcweir return true; 263*cdf0e10cSrcweir return false; 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir int VendorBase::compareVersions(const rtl::OUString& /*sSecond*/) const 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir OSL_ENSURE(0, "[Java framework] VendorBase::compareVersions must be " 269*cdf0e10cSrcweir "overridden in derived class."); 270*cdf0e10cSrcweir return 0; 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir } 277