Update ooo320-m1
[ooovba.git] / jvmfwk / plugins / sunmajor / pluginlib / vendorbase.cxx
blob01c00831c8bffa9c7f732ff498e097925cc99a9c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vendorbase.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_jvmfwk.hxx"
34 #include "osl/file.hxx"
36 #include "vendorbase.hxx"
37 #include "util.hxx"
38 #include "sunjre.hxx"
40 using namespace std;
41 using namespace rtl;
42 using namespace osl;
44 namespace jfw_plugin
46 rtl::Reference<VendorBase> createInstance(createInstance_func pFunc,
47 vector<pair<OUString, OUString> > properties);
55 //##############################################################################
57 MalformedVersionException::MalformedVersionException()
59 MalformedVersionException::MalformedVersionException(
60 const MalformedVersionException & )
62 MalformedVersionException::~MalformedVersionException()
64 MalformedVersionException &
65 MalformedVersionException::operator =(
66 const MalformedVersionException &)
68 return *this;
70 //##############################################################################
73 VendorBase::VendorBase(): m_bAccessibility(false)
77 char const* const * VendorBase::getJavaExePaths(int* size)
79 static char const * ar[] = {
80 #if defined(WNT) || defined(OS2)
81 "java.exe",
82 "bin/java.exe"
83 #elif UNX
84 "java",
85 "bin/java"
86 #endif
88 *size = sizeof(ar) / sizeof(char*);
89 return ar;
93 rtl::Reference<VendorBase> VendorBase::createInstance()
95 VendorBase *pBase = new VendorBase();
96 return rtl::Reference<VendorBase>(pBase);
99 bool VendorBase::initialize(vector<pair<OUString, OUString> > props)
101 //get java.vendor, java.version, java.home,
102 //javax.accessibility.assistive_technologies from system properties
104 OUString sVendor;
105 typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
106 OUString sVendorProperty(
107 RTL_CONSTASCII_USTRINGPARAM("java.vendor"));
108 OUString sVersionProperty(
109 RTL_CONSTASCII_USTRINGPARAM("java.version"));
110 OUString sHomeProperty(
111 RTL_CONSTASCII_USTRINGPARAM("java.home"));
112 OUString sAccessProperty(
113 RTL_CONSTASCII_USTRINGPARAM("javax.accessibility.assistive_technologies"));
115 bool bVersion = false;
116 bool bVendor = false;
117 bool bHome = false;
118 bool bAccess = false;
120 typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
121 for (it_prop i = props.begin(); i != props.end(); i++)
123 if(! bVendor && sVendorProperty.equals(i->first))
125 m_sVendor = i->second;
126 bVendor = true;
128 else if (!bVersion && sVersionProperty.equals(i->first))
130 m_sVersion = i->second;
131 bVersion = true;
133 else if (!bHome && sHomeProperty.equals(i->first))
135 OUString fileURL;
136 if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) ==
137 osl_File_E_None)
139 //make sure that the drive letter have all the same case
140 //otherwise file:///c:/jre and file:///C:/jre produce two
141 //different objects!!!
142 if (makeDriveLetterSame( & fileURL))
144 m_sHome = fileURL;
145 bHome = true;
149 else if (!bAccess && sAccessProperty.equals(i->first))
151 if (i->second.getLength() > 0)
153 m_bAccessibility = true;
154 bAccess = true;
157 // the javax.accessibility.xxx property may not be set. Therefore we
158 //must search through all properties.
161 if (!bVersion || !bVendor || !bHome)
162 return false;
164 // init m_sRuntimeLibrary
165 OSL_ASSERT(m_sHome.getLength());
166 //call virtual function to get the possible paths to the runtime library.
168 int size = 0;
169 char const* const* arRtPaths = getRuntimePaths( & size);
170 vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size);
172 bool bRt = false;
173 typedef vector<OUString>::const_iterator i_path;
174 for(i_path ip = libpaths.begin(); ip != libpaths.end(); ip++)
176 //Construct an absolute path to the possible runtime
177 OUString usRt= m_sHome + *ip;
178 DirectoryItem item;
179 if(DirectoryItem::get(usRt, item) == File::E_None)
181 //found runtime lib
182 m_sRuntimeLibrary = usRt;
183 bRt = true;
184 break;
187 if (!bRt)
188 return false;
190 // init m_sLD_LIBRARY_PATH
191 OSL_ASSERT(m_sHome.getLength());
192 size = 0;
193 char const * const * arLDPaths = getLibraryPaths( & size);
194 vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size);
196 char arSep[]= {SAL_PATHSEPARATOR, 0};
197 OUString sPathSep= OUString::createFromAscii(arSep);
198 bool bLdPath = true;
199 int c = 0;
200 for(i_path il = ld_paths.begin(); il != ld_paths.end(); il ++, c++)
202 OUString usAbsUrl= m_sHome + *il;
203 // convert to system path
204 OUString usSysPath;
205 if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
208 if(c > 0)
209 m_sLD_LIBRARY_PATH+= sPathSep;
210 m_sLD_LIBRARY_PATH+= usSysPath;
212 else
214 bLdPath = false;
215 break;
218 if (bLdPath == false)
219 return false;
221 return true;
224 char const* const* VendorBase::getRuntimePaths(int* /*size*/)
226 return NULL;
229 char const* const* VendorBase::getLibraryPaths(int* /*size*/)
231 return NULL;
234 const OUString & VendorBase::getVendor() const
236 return m_sVendor;
238 const OUString & VendorBase::getVersion() const
240 return m_sVersion;
243 const OUString & VendorBase::getHome() const
245 return m_sHome;
248 const OUString & VendorBase::getLibraryPaths() const
250 return m_sLD_LIBRARY_PATH;
253 const OUString & VendorBase::getRuntimeLibrary() const
255 return m_sRuntimeLibrary;
257 bool VendorBase::supportsAccessibility() const
259 return m_bAccessibility;
262 bool VendorBase::needsRestart() const
264 if (getLibraryPaths().getLength() > 0)
265 return true;
266 return false;
269 int VendorBase::compareVersions(const rtl::OUString& /*sSecond*/) const
271 OSL_ENSURE(0, "[Java framework] VendorBase::compareVersions must be "
272 "overridden in derived class.");
273 return 0;