lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / jvmfwk / plugins / sunmajor / pluginlib / vendorbase.cxx
blob254f17e16de9af6a257a194c26eb3e856b128762
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include "util.hxx"
25 #include "sunjre.hxx"
27 using namespace std;
28 using namespace osl;
31 namespace jfw_plugin
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;
46 bool bVendor = false;
47 bool bHome = false;
48 bool bAccess = false;
49 bool bArch = false;
51 for (auto const& prop : props)
53 if(! bVendor && prop.first == "java.vendor")
55 m_sVendor = prop.second;
56 bVendor = true;
58 else if (!bVersion && prop.first == "java.version")
60 m_sVersion = prop.second;
61 bVersion = true;
63 else if (!bHome && prop.first == "java.home")
65 #ifndef JVM_ONE_PATH_CHECK
66 OUString fileURL;
67 if (osl_getFileURLFromSystemPath(prop.second.pData,& fileURL.pData) ==
68 osl_File_E_None)
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))
75 m_sHome = fileURL;
76 bHome = true;
79 #else
80 m_sHome = prop.second;
81 bHome = true;
82 #endif
84 else if (!bArch && prop.first == "os.arch")
86 m_sArch = prop.second;
87 bArch = true;
89 else if (!bAccess
90 && prop.first == "javax.accessibility.assistive_technologies")
92 if (!prop.second.isEmpty())
94 m_bAccessibility = true;
95 bAccess = 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)
103 return false;
105 // init m_sRuntimeLibrary
106 OSL_ASSERT(!m_sHome.isEmpty());
107 //call virtual function to get the possible paths to the runtime library.
109 int size = 0;
110 char const* const* arRtPaths = getRuntimePaths( & size);
111 vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size);
113 bool bRt = false;
114 for (auto const& libpath : libpaths)
116 //Construct an absolute path to the possible runtime
117 OUString usRt= m_sHome + libpath;
118 DirectoryItem item;
119 if(DirectoryItem::get(usRt, item) == File::E_None)
121 //found runtime lib
122 m_sRuntimeLibrary = usRt;
123 bRt = true;
124 break;
127 if (!bRt)
128 return false;
130 // init m_sLD_LIBRARY_PATH
131 OSL_ASSERT(!m_sHome.isEmpty());
132 size = 0;
133 char const * const * arLDPaths = getLibraryPaths( & size);
134 vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size);
136 bool bLdPath = true;
137 int c = 0;
138 for (auto const& ld_path : ld_paths)
140 OUString usAbsUrl= m_sHome + ld_path;
141 // convert to system path
142 OUString usSysPath;
143 if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
146 if(c > 0)
147 m_sLD_LIBRARY_PATH+= OUStringLiteral1(SAL_PATHSEPARATOR);
148 m_sLD_LIBRARY_PATH+= usSysPath;
150 else
152 bLdPath = false;
153 break;
155 ++c;
157 return bLdPath;
160 const OUString & VendorBase::getVendor() const
162 return m_sVendor;
164 const OUString & VendorBase::getVersion() const
166 return m_sVersion;
169 const OUString & VendorBase::getHome() const
171 return m_sHome;
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.
190 #if defined _WIN64
191 return m_sArch == "amd64" || m_sArch == "x86_64";
192 #elif defined _WIN32
193 return m_sArch == "x86" || m_sArch == "i386" || m_sArch == "i686";
194 #else
195 (void)this;
196 return true;
197 #endif
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: */