1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_jvmfwk.hxx" 30 31 #include "osl/file.hxx" 32 33 #include "vendorbase.hxx" 34 #include "util.hxx" 35 #include "sunjre.hxx" 36 37 using namespace std; 38 using namespace rtl; 39 using namespace osl; 40 41 namespace jfw_plugin 42 { 43 rtl::Reference<VendorBase> createInstance(createInstance_func pFunc, 44 vector<pair<OUString, OUString> > properties); 45 46 47 48 49 50 51 52 //############################################################################## 53 54 MalformedVersionException::MalformedVersionException() 55 {} 56 MalformedVersionException::MalformedVersionException( 57 const MalformedVersionException & ) 58 {} 59 MalformedVersionException::~MalformedVersionException() 60 {} 61 MalformedVersionException & 62 MalformedVersionException::operator =( 63 const MalformedVersionException &) 64 { 65 return *this; 66 } 67 //############################################################################## 68 69 70 VendorBase::VendorBase(): m_bAccessibility(false) 71 { 72 } 73 74 char const* const * VendorBase::getJavaExePaths(int* size) 75 { 76 static char const * ar[] = { 77 #if defined(WNT) || defined(OS2) 78 "java.exe", 79 "bin/java.exe" 80 #elif UNX 81 "java", 82 "bin/java" 83 #endif 84 }; 85 *size = sizeof(ar) / sizeof(char*); 86 return ar; 87 } 88 89 90 rtl::Reference<VendorBase> VendorBase::createInstance() 91 { 92 VendorBase *pBase = new VendorBase(); 93 return rtl::Reference<VendorBase>(pBase); 94 } 95 96 bool VendorBase::initialize(vector<pair<OUString, OUString> > props) 97 { 98 //get java.vendor, java.version, java.home, 99 //javax.accessibility.assistive_technologies from system properties 100 101 OUString sVendor; 102 typedef vector<pair<OUString, OUString> >::const_iterator it_prop; 103 OUString sVendorProperty( 104 RTL_CONSTASCII_USTRINGPARAM("java.vendor")); 105 OUString sVersionProperty( 106 RTL_CONSTASCII_USTRINGPARAM("java.version")); 107 OUString sHomeProperty( 108 RTL_CONSTASCII_USTRINGPARAM("java.home")); 109 OUString sAccessProperty( 110 RTL_CONSTASCII_USTRINGPARAM("javax.accessibility.assistive_technologies")); 111 112 bool bVersion = false; 113 bool bVendor = false; 114 bool bHome = false; 115 bool bAccess = false; 116 117 typedef vector<pair<OUString, OUString> >::const_iterator it_prop; 118 for (it_prop i = props.begin(); i != props.end(); i++) 119 { 120 if(! bVendor && sVendorProperty.equals(i->first)) 121 { 122 m_sVendor = i->second; 123 bVendor = true; 124 } 125 else if (!bVersion && sVersionProperty.equals(i->first)) 126 { 127 m_sVersion = i->second; 128 bVersion = true; 129 } 130 else if (!bHome && sHomeProperty.equals(i->first)) 131 { 132 OUString fileURL; 133 if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) == 134 osl_File_E_None) 135 { 136 //make sure that the drive letter have all the same case 137 //otherwise file:///c:/jre and file:///C:/jre produce two 138 //different objects!!! 139 if (makeDriveLetterSame( & fileURL)) 140 { 141 m_sHome = fileURL; 142 bHome = true; 143 } 144 } 145 } 146 else if (!bAccess && sAccessProperty.equals(i->first)) 147 { 148 if (i->second.getLength() > 0) 149 { 150 m_bAccessibility = true; 151 bAccess = true; 152 } 153 } 154 // the javax.accessibility.xxx property may not be set. Therefore we 155 //must search through all properties. 156 157 } 158 if (!bVersion || !bVendor || !bHome) 159 return false; 160 161 // init m_sRuntimeLibrary 162 OSL_ASSERT(m_sHome.getLength()); 163 //call virtual function to get the possible paths to the runtime library. 164 165 int size = 0; 166 char const* const* arRtPaths = getRuntimePaths( & size); 167 vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size); 168 169 bool bRt = false; 170 typedef vector<OUString>::const_iterator i_path; 171 for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++) 172 { 173 //Construct an absolute path to the possible runtime 174 OUString usRt= m_sHome + *ip; 175 DirectoryItem item; 176 if(DirectoryItem::get(usRt, item) == File::E_None) 177 { 178 //found runtime lib 179 m_sRuntimeLibrary = usRt; 180 bRt = true; 181 break; 182 } 183 } 184 if (!bRt) 185 return false; 186 187 // init m_sLD_LIBRARY_PATH 188 OSL_ASSERT(m_sHome.getLength()); 189 size = 0; 190 char const * const * arLDPaths = getLibraryPaths( & size); 191 vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size); 192 193 char arSep[]= {SAL_PATHSEPARATOR, 0}; 194 OUString sPathSep= OUString::createFromAscii(arSep); 195 bool bLdPath = true; 196 int c = 0; 197 for(i_path il = ld_paths.begin(); il != ld_paths.end(); il ++, c++) 198 { 199 OUString usAbsUrl= m_sHome + *il; 200 // convert to system path 201 OUString usSysPath; 202 if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None) 203 { 204 205 if(c > 0) 206 m_sLD_LIBRARY_PATH+= sPathSep; 207 m_sLD_LIBRARY_PATH+= usSysPath; 208 } 209 else 210 { 211 bLdPath = false; 212 break; 213 } 214 } 215 if (bLdPath == false) 216 return false; 217 218 return true; 219 } 220 221 char const* const* VendorBase::getRuntimePaths(int* /*size*/) 222 { 223 return NULL; 224 } 225 226 char const* const* VendorBase::getLibraryPaths(int* /*size*/) 227 { 228 return NULL; 229 } 230 231 const OUString & VendorBase::getVendor() const 232 { 233 return m_sVendor; 234 } 235 const OUString & VendorBase::getVersion() const 236 { 237 return m_sVersion; 238 } 239 240 const OUString & VendorBase::getHome() const 241 { 242 return m_sHome; 243 } 244 245 const OUString & VendorBase::getLibraryPaths() const 246 { 247 return m_sLD_LIBRARY_PATH; 248 } 249 250 const OUString & VendorBase::getRuntimeLibrary() const 251 { 252 return m_sRuntimeLibrary; 253 } 254 bool VendorBase::supportsAccessibility() const 255 { 256 return m_bAccessibility; 257 } 258 259 bool VendorBase::needsRestart() const 260 { 261 if (getLibraryPaths().getLength() > 0) 262 return true; 263 return false; 264 } 265 266 int VendorBase::compareVersions(const rtl::OUString& /*sSecond*/) const 267 { 268 OSL_ENSURE(0, "[Java framework] VendorBase::compareVersions must be " 269 "overridden in derived class."); 270 return 0; 271 } 272 273 274 275 276 } 277