1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <osl/file.hxx>
23 #include <vendorbase.hxx>
34 MalformedVersionException::~MalformedVersionException() = default;
36 VendorBase::VendorBase(): m_bAccessibility(false)
40 bool VendorBase::initialize(vector
<pair
<OUString
, OUString
> > props
)
42 //get java.vendor, java.version, java.home,
43 //javax.accessibility.assistive_technologies from system properties
45 bool bVersion
= false;
51 for (auto const& prop
: props
)
53 if(! bVendor
&& prop
.first
== "java.vendor")
55 m_sVendor
= prop
.second
;
58 else if (!bVersion
&& prop
.first
== "java.version")
60 m_sVersion
= prop
.second
;
63 else if (!bHome
&& prop
.first
== "java.home")
65 #ifndef JVM_ONE_PATH_CHECK
67 if (osl_getFileURLFromSystemPath(prop
.second
.pData
,& fileURL
.pData
) ==
70 //make sure that the drive letter have all the same case
71 //otherwise file:///c:/jre and file:///C:/jre produce two
72 //different objects!!!
73 if (makeDriveLetterSame( & fileURL
))
80 m_sHome
= prop
.second
;
84 else if (!bArch
&& prop
.first
== "os.arch")
86 m_sArch
= prop
.second
;
90 && prop
.first
== "javax.accessibility.assistive_technologies")
92 if (!prop
.second
.isEmpty())
94 m_bAccessibility
= true;
98 // the javax.accessibility.xxx property may not be set. Therefore we
99 //must search through all properties.
102 if (!bVersion
|| !bVendor
|| !bHome
|| !bArch
)
105 // init m_sRuntimeLibrary
106 OSL_ASSERT(!m_sHome
.isEmpty());
107 //call virtual function to get the possible paths to the runtime library.
110 char const* const* arRtPaths
= getRuntimePaths( & size
);
111 vector
<OUString
> libpaths
= getVectorFromCharArray(arRtPaths
, size
);
114 for (auto const& libpath
: libpaths
)
116 //Construct an absolute path to the possible runtime
117 OUString usRt
= m_sHome
+ libpath
;
119 if(DirectoryItem::get(usRt
, item
) == File::E_None
)
122 m_sRuntimeLibrary
= usRt
;
130 // init m_sLD_LIBRARY_PATH
131 OSL_ASSERT(!m_sHome
.isEmpty());
133 char const * const * arLDPaths
= getLibraryPaths( & size
);
134 vector
<OUString
> ld_paths
= getVectorFromCharArray(arLDPaths
, size
);
138 for (auto const& ld_path
: ld_paths
)
140 OUString usAbsUrl
= m_sHome
+ ld_path
;
141 // convert to system path
143 if(File::getSystemPathFromFileURL(usAbsUrl
, usSysPath
) == File::E_None
)
147 m_sLD_LIBRARY_PATH
+= OUStringLiteral1(SAL_PATHSEPARATOR
);
148 m_sLD_LIBRARY_PATH
+= usSysPath
;
160 const OUString
& VendorBase::getVendor() const
164 const OUString
& VendorBase::getVersion() const
169 const OUString
& VendorBase::getHome() const
174 const OUString
& VendorBase::getLibraryPath() const
176 return m_sLD_LIBRARY_PATH
;
179 const OUString
& VendorBase::getRuntimeLibrary() const
181 return m_sRuntimeLibrary
;
184 bool VendorBase::isValidArch() const
186 // Warning: These values come from the "os.arch" property.
187 // It is not defined what the exact values are.
188 // Oracle JRE 8 has "x86" and "amd64", the others were found at http://lopica.sourceforge.net/os.html .
189 // There might still be missing some options; we need to extend the check once we find out.
191 return m_sArch
== "amd64" || m_sArch
== "x86_64";
193 return m_sArch
== "x86" || m_sArch
== "i386" || m_sArch
== "i686";
200 bool VendorBase::supportsAccessibility() const
202 return m_bAccessibility
;
205 bool VendorBase::needsRestart() const
207 return !getLibraryPath().isEmpty();
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */