Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "osl/file.hxx"
22 :
23 : #include "vendorbase.hxx"
24 : #include "util.hxx"
25 : #include "sunjre.hxx"
26 :
27 : using namespace std;
28 : using namespace osl;
29 :
30 : using ::rtl::OUString;
31 :
32 : namespace jfw_plugin
33 : {
34 : rtl::Reference<VendorBase> createInstance(createInstance_func pFunc,
35 : vector<pair<OUString, OUString> > properties);
36 :
37 :
38 :
39 :
40 :
41 :
42 :
43 : //##############################################################################
44 :
45 0 : MalformedVersionException::MalformedVersionException()
46 0 : {}
47 0 : MalformedVersionException::MalformedVersionException(
48 0 : const MalformedVersionException & )
49 0 : {}
50 0 : MalformedVersionException::~MalformedVersionException()
51 0 : {}
52 : MalformedVersionException &
53 0 : MalformedVersionException::operator =(
54 : const MalformedVersionException &)
55 : {
56 0 : return *this;
57 : }
58 : //##############################################################################
59 :
60 :
61 0 : VendorBase::VendorBase(): m_bAccessibility(false)
62 : {
63 0 : }
64 :
65 0 : rtl::Reference<VendorBase> VendorBase::createInstance()
66 : {
67 0 : VendorBase *pBase = new VendorBase();
68 0 : return rtl::Reference<VendorBase>(pBase);
69 : }
70 :
71 0 : bool VendorBase::initialize(vector<pair<OUString, OUString> > props)
72 : {
73 : //get java.vendor, java.version, java.home,
74 : //javax.accessibility.assistive_technologies from system properties
75 :
76 : typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
77 : OUString sVendorProperty(
78 0 : RTL_CONSTASCII_USTRINGPARAM("java.vendor"));
79 : OUString sVersionProperty(
80 0 : RTL_CONSTASCII_USTRINGPARAM("java.version"));
81 : OUString sHomeProperty(
82 0 : RTL_CONSTASCII_USTRINGPARAM("java.home"));
83 : OUString sAccessProperty(
84 0 : RTL_CONSTASCII_USTRINGPARAM("javax.accessibility.assistive_technologies"));
85 :
86 0 : bool bVersion = false;
87 0 : bool bVendor = false;
88 0 : bool bHome = false;
89 0 : bool bAccess = false;
90 :
91 : typedef vector<pair<OUString, OUString> >::const_iterator it_prop;
92 0 : for (it_prop i = props.begin(); i != props.end(); ++i)
93 : {
94 0 : if(! bVendor && sVendorProperty.equals(i->first))
95 : {
96 0 : m_sVendor = i->second;
97 0 : bVendor = true;
98 : }
99 0 : else if (!bVersion && sVersionProperty.equals(i->first))
100 : {
101 0 : m_sVersion = i->second;
102 0 : bVersion = true;
103 : }
104 0 : else if (!bHome && sHomeProperty.equals(i->first))
105 : {
106 : #ifndef JVM_ONE_PATH_CHECK
107 0 : OUString fileURL;
108 0 : if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) ==
109 : osl_File_E_None)
110 : {
111 : //make sure that the drive letter have all the same case
112 : //otherwise file:///c:/jre and file:///C:/jre produce two
113 : //different objects!!!
114 0 : if (makeDriveLetterSame( & fileURL))
115 : {
116 0 : m_sHome = fileURL;
117 0 : bHome = true;
118 : }
119 0 : }
120 : #else
121 : m_sHome = i->second;
122 : bHome = true;
123 : #endif
124 : }
125 0 : else if (!bAccess && sAccessProperty.equals(i->first))
126 : {
127 0 : if (!i->second.isEmpty())
128 : {
129 0 : m_bAccessibility = true;
130 0 : bAccess = true;
131 : }
132 : }
133 : // the javax.accessibility.xxx property may not be set. Therefore we
134 : //must search through all properties.
135 :
136 : }
137 0 : if (!bVersion || !bVendor || !bHome)
138 0 : return false;
139 :
140 : // init m_sRuntimeLibrary
141 : OSL_ASSERT(!m_sHome.isEmpty());
142 : //call virtual function to get the possible paths to the runtime library.
143 :
144 0 : int size = 0;
145 0 : char const* const* arRtPaths = getRuntimePaths( & size);
146 0 : vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size);
147 :
148 0 : bool bRt = false;
149 : typedef vector<OUString>::const_iterator i_path;
150 0 : for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip)
151 : {
152 : //Construct an absolute path to the possible runtime
153 0 : OUString usRt= m_sHome + *ip;
154 0 : DirectoryItem item;
155 0 : if(DirectoryItem::get(usRt, item) == File::E_None)
156 : {
157 : //found runtime lib
158 0 : m_sRuntimeLibrary = usRt;
159 0 : bRt = true;
160 : break;
161 : }
162 0 : }
163 0 : if (!bRt)
164 0 : return false;
165 :
166 : // init m_sLD_LIBRARY_PATH
167 : OSL_ASSERT(!m_sHome.isEmpty());
168 0 : size = 0;
169 0 : char const * const * arLDPaths = getLibraryPaths( & size);
170 0 : vector<OUString> ld_paths = getVectorFromCharArray(arLDPaths, size);
171 :
172 0 : char arSep[]= {SAL_PATHSEPARATOR, 0};
173 0 : OUString sPathSep= OUString::createFromAscii(arSep);
174 0 : bool bLdPath = true;
175 0 : int c = 0;
176 0 : for(i_path il = ld_paths.begin(); il != ld_paths.end(); ++il, ++c)
177 : {
178 0 : OUString usAbsUrl= m_sHome + *il;
179 : // convert to system path
180 0 : OUString usSysPath;
181 0 : if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None)
182 : {
183 :
184 0 : if(c > 0)
185 0 : m_sLD_LIBRARY_PATH+= sPathSep;
186 0 : m_sLD_LIBRARY_PATH+= usSysPath;
187 : }
188 : else
189 : {
190 0 : bLdPath = false;
191 : break;
192 : }
193 0 : }
194 0 : if (bLdPath == false)
195 0 : return false;
196 :
197 0 : return true;
198 : }
199 :
200 0 : char const* const* VendorBase::getRuntimePaths(int* /*size*/)
201 : {
202 0 : return NULL;
203 : }
204 :
205 0 : char const* const* VendorBase::getLibraryPaths(int* /*size*/)
206 : {
207 0 : return NULL;
208 : }
209 :
210 0 : const OUString & VendorBase::getVendor() const
211 : {
212 0 : return m_sVendor;
213 : }
214 0 : const OUString & VendorBase::getVersion() const
215 : {
216 0 : return m_sVersion;
217 : }
218 :
219 0 : const OUString & VendorBase::getHome() const
220 : {
221 0 : return m_sHome;
222 : }
223 :
224 0 : const OUString & VendorBase::getLibraryPaths() const
225 : {
226 0 : return m_sLD_LIBRARY_PATH;
227 : }
228 :
229 0 : const OUString & VendorBase::getRuntimeLibrary() const
230 : {
231 0 : return m_sRuntimeLibrary;
232 : }
233 0 : bool VendorBase::supportsAccessibility() const
234 : {
235 0 : return m_bAccessibility;
236 : }
237 :
238 0 : bool VendorBase::needsRestart() const
239 : {
240 0 : if (!getLibraryPaths().isEmpty())
241 0 : return true;
242 0 : return false;
243 : }
244 :
245 0 : int VendorBase::compareVersions(const rtl::OUString& /*sSecond*/) const
246 : {
247 : OSL_FAIL("[Java framework] VendorBase::compareVersions must be "
248 : "overridden in derived class.");
249 0 : return 0;
250 : }
251 :
252 :
253 :
254 :
255 : }
256 :
257 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|