1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vendorbase.cxx,v $
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"
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
&)
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)
88 *size
= sizeof(ar
) / sizeof(char*);
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
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;
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
;
128 else if (!bVersion
&& sVersionProperty
.equals(i
->first
))
130 m_sVersion
= i
->second
;
133 else if (!bHome
&& sHomeProperty
.equals(i
->first
))
136 if (osl_getFileURLFromSystemPath(i
->second
.pData
,& fileURL
.pData
) ==
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
))
149 else if (!bAccess
&& sAccessProperty
.equals(i
->first
))
151 if (i
->second
.getLength() > 0)
153 m_bAccessibility
= true;
157 // the javax.accessibility.xxx property may not be set. Therefore we
158 //must search through all properties.
161 if (!bVersion
|| !bVendor
|| !bHome
)
164 // init m_sRuntimeLibrary
165 OSL_ASSERT(m_sHome
.getLength());
166 //call virtual function to get the possible paths to the runtime library.
169 char const* const* arRtPaths
= getRuntimePaths( & size
);
170 vector
<OUString
> libpaths
= getVectorFromCharArray(arRtPaths
, size
);
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
;
179 if(DirectoryItem::get(usRt
, item
) == File::E_None
)
182 m_sRuntimeLibrary
= usRt
;
190 // init m_sLD_LIBRARY_PATH
191 OSL_ASSERT(m_sHome
.getLength());
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
);
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
205 if(File::getSystemPathFromFileURL(usAbsUrl
, usSysPath
) == File::E_None
)
209 m_sLD_LIBRARY_PATH
+= sPathSep
;
210 m_sLD_LIBRARY_PATH
+= usSysPath
;
218 if (bLdPath
== false)
224 char const* const* VendorBase::getRuntimePaths(int* /*size*/)
229 char const* const* VendorBase::getLibraryPaths(int* /*size*/)
234 const OUString
& VendorBase::getVendor() const
238 const OUString
& VendorBase::getVersion() const
243 const OUString
& VendorBase::getHome() const
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)
269 int VendorBase::compareVersions(const rtl::OUString
& /*sSecond*/) const
271 OSL_ENSURE(0, "[Java framework] VendorBase::compareVersions must be "
272 "overridden in derived class.");