Linux x86 build fix
[LibreOffice.git] / jvmfwk / plugins / sunmajor / pluginlib / vendorbase.cxx
blob5ee17d7bd86939f7d091a1ff2b5677b7735b0a62
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()
37 MalformedVersionException::MalformedVersionException(
38 const MalformedVersionException & )
41 MalformedVersionException::~MalformedVersionException()
44 MalformedVersionException &
45 MalformedVersionException::operator =(
46 const MalformedVersionException &)
48 return *this;
53 VendorBase::VendorBase(): m_bAccessibility(false)
57 bool VendorBase::initialize(vector<pair<OUString, OUString> > props)
59 //get java.vendor, java.version, java.home,
60 //javax.accessibility.assistive_technologies from system properties
62 typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
63 OUString sVendorProperty("java.vendor");
64 OUString sVersionProperty("java.version");
65 OUString sHomeProperty("java.home");
66 OUString sAccessProperty("javax.accessibility.assistive_technologies");
68 bool bVersion = false;
69 bool bVendor = false;
70 bool bHome = false;
71 bool bAccess = false;
73 typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
74 for (it_prop i = props.begin(); i != props.end(); ++i)
76 if(! bVendor && sVendorProperty.equals(i->first))
78 m_sVendor = i->second;
79 bVendor = true;
81 else if (!bVersion && sVersionProperty.equals(i->first))
83 m_sVersion = i->second;
84 bVersion = true;
86 else if (!bHome && sHomeProperty.equals(i->first))
88 #ifndef JVM_ONE_PATH_CHECK
89 OUString fileURL;
90 if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) ==
91 osl_File_E_None)
93 //make sure that the drive letter have all the same case
94 //otherwise file:///c:/jre and file:///C:/jre produce two
95 //different objects!!!
96 if (makeDriveLetterSame( & fileURL))
98 m_sHome = fileURL;
99 bHome = true;
102 #else
103 m_sHome = i->second;
104 bHome = true;
105 #endif
107 else if (!bAccess && sAccessProperty.equals(i->first))
109 if (!i->second.isEmpty())
111 m_bAccessibility = true;
112 bAccess = true;
115 // the javax.accessibility.xxx property may not be set. Therefore we
116 //must search through all properties.
119 if (!bVersion || !bVendor || !bHome)
120 return false;
122 // init m_sRuntimeLibrary
123 OSL_ASSERT(!m_sHome.isEmpty());
124 //call virtual function to get the possible paths to the runtime library.
126 int size = 0;
127 char const* const* arRtPaths = getRuntimePaths( & size);
128 vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size);
130 bool bRt = false;
131 typedef vector<OUString>::const_iterator i_path;
132 for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
134 //Construct an absolute path to the possible runtime
135 OUString usRt= m_sHome + *ip;
136 DirectoryItem item;
137 if(DirectoryItem::get(usRt, item) == File::E_None)
139 //found runtime lib
140 m_sRuntimeLibrary = usRt;
141 bRt = true;
142 break;
145 if (!bRt)
146 return false;
148 // init m_sLD_LIBRARY_PATH
149 OSL_ASSERT(!m_sHome.isEmpty());
150 size = 0;
151 char const * const * arLDPaths = getLibraryPaths( & size);
152 vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size);
154 char arSep[]= {SAL_PATHSEPARATOR, 0};
155 OUString sPathSep= OUString::createFromAscii(arSep);
156 bool bLdPath = true;
157 int c = 0;
158 for(i_path il = ld_paths.begin(); il != ld_paths.end(); ++il, ++c)
160 OUString usAbsUrl= m_sHome + *il;
161 // convert to system path
162 OUString usSysPath;
163 if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
166 if(c > 0)
167 m_sLD_LIBRARY_PATH+= sPathSep;
168 m_sLD_LIBRARY_PATH+= usSysPath;
170 else
172 bLdPath = false;
173 break;
176 if (!bLdPath)
177 return false;
179 return true;
182 const OUString & VendorBase::getVendor() const
184 return m_sVendor;
186 const OUString & VendorBase::getVersion() const
188 return m_sVersion;
191 const OUString & VendorBase::getHome() const
193 return m_sHome;
196 const OUString & VendorBase::getLibraryPath() const
198 return m_sLD_LIBRARY_PATH;
201 const OUString & VendorBase::getRuntimeLibrary() const
203 return m_sRuntimeLibrary;
205 bool VendorBase::supportsAccessibility() const
207 return m_bAccessibility;
210 bool VendorBase::needsRestart() const
212 if (!getLibraryPath().isEmpty())
213 return true;
214 return false;
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */