12005
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Copyright 2001-2004 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* You may obtain a copy of the License at
|
|
11 |
*
|
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13 |
*
|
|
14 |
* Unless required by applicable law or agreed to in writing, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*/
|
|
20 |
/*
|
|
21 |
* $Id: EnvironmentCheck.java,v 1.2.4.1 2005/09/09 07:13:59 pvedula Exp $
|
|
22 |
*/
|
|
23 |
package com.sun.org.apache.xalan.internal.xslt;
|
|
24 |
|
12458
|
25 |
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
|
|
26 |
|
12005
|
27 |
import java.io.File;
|
|
28 |
import java.io.FileWriter;
|
|
29 |
import java.io.PrintWriter;
|
|
30 |
import java.lang.reflect.Field;
|
|
31 |
import java.lang.reflect.Method;
|
|
32 |
import java.util.Enumeration;
|
|
33 |
import java.util.Hashtable;
|
|
34 |
import java.util.StringTokenizer;
|
|
35 |
import java.util.Vector;
|
|
36 |
|
|
37 |
import org.w3c.dom.Document;
|
|
38 |
import org.w3c.dom.Element;
|
|
39 |
import org.w3c.dom.Node;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* Utility class to report simple information about the environment.
|
|
43 |
* Simplistic reporting about certain classes found in your JVM may
|
|
44 |
* help answer some FAQs for simple problems.
|
|
45 |
*
|
|
46 |
* <p>Usage-command line:
|
|
47 |
* <code>
|
|
48 |
* java com.sun.org.apache.xalan.internal.xslt.EnvironmentCheck [-out outFile]
|
|
49 |
* </code></p>
|
|
50 |
*
|
|
51 |
* <p>Usage-from program:
|
|
52 |
* <code>
|
|
53 |
* boolean environmentOK =
|
|
54 |
* (new EnvironmentCheck()).checkEnvironment(yourPrintWriter);
|
|
55 |
* </code></p>
|
|
56 |
*
|
|
57 |
* <p>Usage-from stylesheet:
|
|
58 |
* <code><pre>
|
|
59 |
* <?xml version="1.0"?>
|
|
60 |
* <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
|
|
61 |
* xmlns:xalan="http://xml.apache.org/xalan"
|
|
62 |
* exclude-result-prefixes="xalan">
|
|
63 |
* <xsl:output indent="yes"/>
|
|
64 |
* <xsl:template match="/">
|
|
65 |
* <xsl:copy-of select="xalan:checkEnvironment()"/>
|
|
66 |
* </xsl:template>
|
|
67 |
* </xsl:stylesheet>
|
|
68 |
* </pre></code></p>
|
|
69 |
*
|
|
70 |
* <p>Xalan users reporting problems are encouraged to use this class
|
|
71 |
* to see if there are potential problems with their actual
|
|
72 |
* Java environment <b>before</b> reporting a bug. Note that you
|
|
73 |
* should both check from the JVM/JRE's command line as well as
|
|
74 |
* temporarily calling checkEnvironment() directly from your code,
|
|
75 |
* since the classpath may differ (especially for servlets, etc).</p>
|
|
76 |
*
|
|
77 |
* <p>Also see http://xml.apache.org/xalan-j/faq.html</p>
|
|
78 |
*
|
|
79 |
* <p>Note: This class is pretty simplistic:
|
|
80 |
* results are not necessarily definitive nor will it find all
|
|
81 |
* problems related to environment setup. Also, you should avoid
|
|
82 |
* calling this in deployed production code, both because it is
|
|
83 |
* quite slow and because it forces classes to get loaded.</p>
|
|
84 |
*
|
|
85 |
* <p>Note: This class explicitly has very limited compile-time
|
|
86 |
* dependencies to enable easy compilation and usage even when
|
|
87 |
* Xalan, DOM/SAX/JAXP, etc. are not present.</p>
|
|
88 |
*
|
|
89 |
* <p>Note: for an improved version of this utility, please see
|
|
90 |
* the xml-commons' project Which utility which does the same kind
|
|
91 |
* of thing but in a much simpler manner.</p>
|
|
92 |
*
|
|
93 |
* @author Shane_Curcuru@us.ibm.com
|
|
94 |
* @version $Id: EnvironmentCheck.java,v 1.10 2010-11-01 04:34:13 joehw Exp $
|
|
95 |
*/
|
|
96 |
public class EnvironmentCheck
|
|
97 |
{
|
|
98 |
|
|
99 |
/**
|
|
100 |
* Command line runnability: checks for [-out outFilename] arg.
|
|
101 |
* <p>Command line entrypoint; Sets output and calls
|
|
102 |
* {@link #checkEnvironment(PrintWriter)}.</p>
|
|
103 |
* @param args command line args
|
|
104 |
*/
|
|
105 |
public static void main(String[] args)
|
|
106 |
{
|
|
107 |
// Default to System.out, autoflushing
|
|
108 |
PrintWriter sendOutputTo = new PrintWriter(System.out, true);
|
|
109 |
|
|
110 |
// Read our simplistic input args, if supplied
|
|
111 |
for (int i = 0; i < args.length; i++)
|
|
112 |
{
|
|
113 |
if ("-out".equalsIgnoreCase(args[i]))
|
|
114 |
{
|
|
115 |
i++;
|
|
116 |
|
|
117 |
if (i < args.length)
|
|
118 |
{
|
|
119 |
try
|
|
120 |
{
|
|
121 |
sendOutputTo = new PrintWriter(new FileWriter(args[i], true));
|
|
122 |
}
|
|
123 |
catch (Exception e)
|
|
124 |
{
|
|
125 |
System.err.println("# WARNING: -out " + args[i] + " threw "
|
|
126 |
+ e.toString());
|
|
127 |
}
|
|
128 |
}
|
|
129 |
else
|
|
130 |
{
|
|
131 |
System.err.println(
|
|
132 |
"# WARNING: -out argument should have a filename, output sent to console");
|
|
133 |
}
|
|
134 |
}
|
|
135 |
}
|
|
136 |
|
|
137 |
EnvironmentCheck app = new EnvironmentCheck();
|
|
138 |
app.checkEnvironment(sendOutputTo);
|
|
139 |
}
|
|
140 |
|
|
141 |
/**
|
|
142 |
* Programmatic entrypoint: Report on basic Java environment
|
|
143 |
* and CLASSPATH settings that affect Xalan.
|
|
144 |
*
|
|
145 |
* <p>Note that this class is not advanced enough to tell you
|
|
146 |
* everything about the environment that affects Xalan, and
|
|
147 |
* sometimes reports errors that will not actually affect
|
|
148 |
* Xalan's behavior. Currently, it very simplistically
|
|
149 |
* checks the JVM's environment for some basic properties and
|
|
150 |
* logs them out; it will report a problem if it finds a setting
|
|
151 |
* or .jar file that is <i>likely</i> to cause problems.</p>
|
|
152 |
*
|
|
153 |
* <p>Advanced users can peruse the code herein to help them
|
|
154 |
* investigate potential environment problems found; other users
|
|
155 |
* may simply send the output from this tool along with any bugs
|
|
156 |
* they submit to help us in the debugging process.</p>
|
|
157 |
*
|
|
158 |
* @param pw PrintWriter to send output to; can be sent to a
|
|
159 |
* file that will look similar to a Properties file; defaults
|
|
160 |
* to System.out if null
|
|
161 |
* @return true if your environment appears to have no major
|
|
162 |
* problems; false if potential environment problems found
|
|
163 |
* @see #getEnvironmentHash()
|
|
164 |
*/
|
|
165 |
public boolean checkEnvironment(PrintWriter pw)
|
|
166 |
{
|
|
167 |
|
|
168 |
// Use user-specified output writer if non-null
|
|
169 |
if (null != pw)
|
|
170 |
outWriter = pw;
|
|
171 |
|
|
172 |
// Setup a hash to store various environment information in
|
|
173 |
Hashtable hash = getEnvironmentHash();
|
|
174 |
|
|
175 |
// Check for ERROR keys in the hashtable, and print report
|
|
176 |
boolean environmentHasErrors = writeEnvironmentReport(hash);
|
|
177 |
|
|
178 |
if (environmentHasErrors)
|
|
179 |
{
|
|
180 |
// Note: many logMsg calls have # at the start to
|
|
181 |
// fake a property-file like output
|
|
182 |
logMsg("# WARNING: Potential problems found in your environment!");
|
|
183 |
logMsg("# Check any 'ERROR' items above against the Xalan FAQs");
|
|
184 |
logMsg("# to correct potential problems with your classes/jars");
|
|
185 |
logMsg("# http://xml.apache.org/xalan-j/faq.html");
|
|
186 |
if (null != outWriter)
|
|
187 |
outWriter.flush();
|
|
188 |
return false;
|
|
189 |
}
|
|
190 |
else
|
|
191 |
{
|
|
192 |
logMsg("# YAHOO! Your environment seems to be OK.");
|
|
193 |
if (null != outWriter)
|
|
194 |
outWriter.flush();
|
|
195 |
return true;
|
|
196 |
}
|
|
197 |
}
|
|
198 |
|
|
199 |
/**
|
|
200 |
* Fill a hash with basic environment settings that affect Xalan.
|
|
201 |
*
|
|
202 |
* <p>Worker method called from various places.</p>
|
|
203 |
* <p>Various system and CLASSPATH, etc. properties are put into
|
|
204 |
* the hash as keys with a brief description of the current state
|
|
205 |
* of that item as the value. Any serious problems will be put in
|
|
206 |
* with a key that is prefixed with {@link #ERROR 'ERROR.'} so it
|
|
207 |
* stands out in any resulting report; also a key with just that
|
|
208 |
* constant will be set as well for any error.</p>
|
|
209 |
* <p>Note that some legitimate cases are flaged as potential
|
|
210 |
* errors - namely when a developer recompiles xalan.jar on their
|
|
211 |
* own - and even a non-error state doesn't guaruntee that
|
|
212 |
* everything in the environment is correct. But this will help
|
|
213 |
* point out the most common classpath and system property
|
|
214 |
* problems that we've seen.</p>
|
|
215 |
*
|
|
216 |
* @return Hashtable full of useful environment info about Xalan
|
|
217 |
* and related system properties, etc.
|
|
218 |
*/
|
|
219 |
public Hashtable getEnvironmentHash()
|
|
220 |
{
|
|
221 |
// Setup a hash to store various environment information in
|
|
222 |
Hashtable hash = new Hashtable();
|
|
223 |
|
|
224 |
// Call various worker methods to fill in the hash
|
|
225 |
// These are explicitly separate for maintenance and so
|
|
226 |
// advanced users could call them standalone
|
|
227 |
checkJAXPVersion(hash);
|
|
228 |
checkProcessorVersion(hash);
|
|
229 |
checkParserVersion(hash);
|
|
230 |
checkAntVersion(hash);
|
|
231 |
if (!checkDOML3(hash)) {
|
|
232 |
checkDOMVersion(hash);
|
|
233 |
}
|
|
234 |
checkSAXVersion(hash);
|
|
235 |
checkSystemProperties(hash);
|
|
236 |
|
|
237 |
return hash;
|
|
238 |
}
|
|
239 |
|
|
240 |
/**
|
|
241 |
* Dump a basic Xalan environment report to outWriter.
|
|
242 |
*
|
|
243 |
* <p>This dumps a simple header and then each of the entries in
|
|
244 |
* the Hashtable to our PrintWriter; it does special processing
|
|
245 |
* for entries that are .jars found in the classpath.</p>
|
|
246 |
*
|
|
247 |
* @param h Hashtable of items to report on; presumably
|
|
248 |
* filled in by our various check*() methods
|
|
249 |
* @return true if your environment appears to have no major
|
|
250 |
* problems; false if potential environment problems found
|
|
251 |
* @see #appendEnvironmentReport(Node, Document, Hashtable)
|
|
252 |
* for an equivalent that appends to a Node instead
|
|
253 |
*/
|
|
254 |
protected boolean writeEnvironmentReport(Hashtable h)
|
|
255 |
{
|
|
256 |
|
|
257 |
if (null == h)
|
|
258 |
{
|
|
259 |
logMsg("# ERROR: writeEnvironmentReport called with null Hashtable");
|
|
260 |
return false;
|
|
261 |
}
|
|
262 |
|
|
263 |
boolean errors = false;
|
|
264 |
|
|
265 |
logMsg(
|
|
266 |
"#---- BEGIN writeEnvironmentReport($Revision: 1.10 $): Useful stuff found: ----");
|
|
267 |
|
|
268 |
// Fake the Properties-like output
|
|
269 |
for (Enumeration keys = h.keys();
|
|
270 |
keys.hasMoreElements();
|
|
271 |
/* no increment portion */
|
|
272 |
)
|
|
273 |
{
|
|
274 |
Object key = keys.nextElement();
|
|
275 |
String keyStr = (String) key;
|
|
276 |
try
|
|
277 |
{
|
|
278 |
// Special processing for classes found..
|
|
279 |
if (keyStr.startsWith(FOUNDCLASSES))
|
|
280 |
{
|
|
281 |
Vector v = (Vector) h.get(keyStr);
|
|
282 |
errors |= logFoundJars(v, keyStr);
|
|
283 |
}
|
|
284 |
// ..normal processing for all other entries
|
|
285 |
else
|
|
286 |
{
|
|
287 |
// Note: we could just check for the ERROR key by itself,
|
|
288 |
// since we now set that, but since we have to go
|
|
289 |
// through the whole hash anyway, do it this way,
|
|
290 |
// which is safer for maintenance
|
|
291 |
if (keyStr.startsWith(ERROR))
|
|
292 |
{
|
|
293 |
errors = true;
|
|
294 |
}
|
|
295 |
logMsg(keyStr + "=" + h.get(keyStr));
|
|
296 |
}
|
|
297 |
}
|
|
298 |
catch (Exception e)
|
|
299 |
{
|
|
300 |
logMsg("Reading-" + key + "= threw: " + e.toString());
|
|
301 |
}
|
|
302 |
}
|
|
303 |
|
|
304 |
logMsg(
|
|
305 |
"#----- END writeEnvironmentReport: Useful properties found: -----");
|
|
306 |
|
|
307 |
return errors;
|
|
308 |
}
|
|
309 |
|
|
310 |
/** Prefixed to hash keys that signify serious problems. */
|
|
311 |
public static final String ERROR = "ERROR.";
|
|
312 |
|
|
313 |
/** Added to descriptions that signify potential problems. */
|
|
314 |
public static final String WARNING = "WARNING.";
|
|
315 |
|
|
316 |
/** Value for any error found. */
|
|
317 |
public static final String ERROR_FOUND = "At least one error was found!";
|
|
318 |
|
|
319 |
/** Prefixed to hash keys that signify version numbers. */
|
|
320 |
public static final String VERSION = "version.";
|
|
321 |
|
|
322 |
/** Prefixed to hash keys that signify .jars found in classpath. */
|
|
323 |
public static final String FOUNDCLASSES = "foundclasses.";
|
|
324 |
|
|
325 |
/** Marker that a class or .jar was found. */
|
|
326 |
public static final String CLASS_PRESENT = "present-unknown-version";
|
|
327 |
|
|
328 |
/** Marker that a class or .jar was not found. */
|
|
329 |
public static final String CLASS_NOTPRESENT = "not-present";
|
|
330 |
|
|
331 |
/** Listing of common .jar files that include Xalan-related classes. */
|
|
332 |
public String[] jarNames =
|
|
333 |
{
|
|
334 |
"xalan.jar", "xalansamples.jar", "xalanj1compat.jar", "xalanservlet.jar",
|
|
335 |
"serializer.jar", // Serializer (shared between Xalan & Xerces)
|
|
336 |
"xerces.jar", // Xerces-J 1.x
|
|
337 |
"xercesImpl.jar", // Xerces-J 2.x
|
|
338 |
"testxsl.jar",
|
|
339 |
"crimson.jar",
|
|
340 |
"lotusxsl.jar",
|
|
341 |
"jaxp.jar", "parser.jar", "dom.jar", "sax.jar", "xml.jar",
|
|
342 |
"xml-apis.jar",
|
|
343 |
"xsltc.jar"
|
|
344 |
};
|
|
345 |
|
|
346 |
/**
|
|
347 |
* Print out report of .jars found in a classpath.
|
|
348 |
*
|
|
349 |
* Takes the information encoded from a checkPathForJars()
|
|
350 |
* call and dumps it out to our PrintWriter.
|
|
351 |
*
|
|
352 |
* @param v Vector of Hashtables of .jar file info
|
|
353 |
* @param desc description to print out in header
|
|
354 |
*
|
|
355 |
* @return false if OK, true if any .jars were reported
|
|
356 |
* as having errors
|
|
357 |
* @see #checkPathForJars(String, String[])
|
|
358 |
*/
|
|
359 |
protected boolean logFoundJars(Vector v, String desc)
|
|
360 |
{
|
|
361 |
|
|
362 |
if ((null == v) || (v.size() < 1))
|
|
363 |
return false;
|
|
364 |
|
|
365 |
boolean errors = false;
|
|
366 |
|
|
367 |
logMsg("#---- BEGIN Listing XML-related jars in: " + desc + " ----");
|
|
368 |
|
|
369 |
for (int i = 0; i < v.size(); i++)
|
|
370 |
{
|
|
371 |
Hashtable subhash = (Hashtable) v.elementAt(i);
|
|
372 |
|
|
373 |
for (Enumeration keys = subhash.keys();
|
|
374 |
keys.hasMoreElements();
|
|
375 |
/* no increment portion */
|
|
376 |
)
|
|
377 |
{
|
|
378 |
Object key = keys.nextElement();
|
|
379 |
String keyStr = (String) key;
|
|
380 |
try
|
|
381 |
{
|
|
382 |
if (keyStr.startsWith(ERROR))
|
|
383 |
{
|
|
384 |
errors = true;
|
|
385 |
}
|
|
386 |
logMsg(keyStr + "=" + subhash.get(keyStr));
|
|
387 |
|
|
388 |
}
|
|
389 |
catch (Exception e)
|
|
390 |
{
|
|
391 |
errors = true;
|
|
392 |
logMsg("Reading-" + key + "= threw: " + e.toString());
|
|
393 |
}
|
|
394 |
}
|
|
395 |
}
|
|
396 |
|
|
397 |
logMsg("#----- END Listing XML-related jars in: " + desc + " -----");
|
|
398 |
|
|
399 |
return errors;
|
|
400 |
}
|
|
401 |
|
|
402 |
/**
|
|
403 |
* Stylesheet extension entrypoint: Dump a basic Xalan
|
|
404 |
* environment report from getEnvironmentHash() to a Node.
|
|
405 |
*
|
|
406 |
* <p>Copy of writeEnvironmentReport that creates a Node suitable
|
|
407 |
* for other processing instead of a properties-like text output.
|
|
408 |
* </p>
|
|
409 |
* @param container Node to append our report to
|
|
410 |
* @param factory Document providing createElement, etc. services
|
|
411 |
* @param h Hash presumably from {@link #getEnvironmentHash()}
|
|
412 |
* @see #writeEnvironmentReport(Hashtable)
|
|
413 |
* for an equivalent that writes to a PrintWriter instead
|
|
414 |
*/
|
|
415 |
public void appendEnvironmentReport(Node container, Document factory, Hashtable h)
|
|
416 |
{
|
|
417 |
if ((null == container) || (null == factory))
|
|
418 |
{
|
|
419 |
return;
|
|
420 |
}
|
|
421 |
|
|
422 |
try
|
|
423 |
{
|
|
424 |
Element envCheckNode = factory.createElement("EnvironmentCheck");
|
|
425 |
envCheckNode.setAttribute("version", "$Revision: 1.10 $");
|
|
426 |
container.appendChild(envCheckNode);
|
|
427 |
|
|
428 |
if (null == h)
|
|
429 |
{
|
|
430 |
Element statusNode = factory.createElement("status");
|
|
431 |
statusNode.setAttribute("result", "ERROR");
|
|
432 |
statusNode.appendChild(factory.createTextNode("appendEnvironmentReport called with null Hashtable!"));
|
|
433 |
envCheckNode.appendChild(statusNode);
|
|
434 |
return;
|
|
435 |
}
|
|
436 |
|
|
437 |
boolean errors = false;
|
|
438 |
|
|
439 |
Element hashNode = factory.createElement("environment");
|
|
440 |
envCheckNode.appendChild(hashNode);
|
|
441 |
|
|
442 |
for (Enumeration keys = h.keys();
|
|
443 |
keys.hasMoreElements();
|
|
444 |
/* no increment portion */
|
|
445 |
)
|
|
446 |
{
|
|
447 |
Object key = keys.nextElement();
|
|
448 |
String keyStr = (String) key;
|
|
449 |
try
|
|
450 |
{
|
|
451 |
// Special processing for classes found..
|
|
452 |
if (keyStr.startsWith(FOUNDCLASSES))
|
|
453 |
{
|
|
454 |
Vector v = (Vector) h.get(keyStr);
|
|
455 |
// errors |= logFoundJars(v, keyStr);
|
|
456 |
errors |= appendFoundJars(hashNode, factory, v, keyStr);
|
|
457 |
}
|
|
458 |
// ..normal processing for all other entries
|
|
459 |
else
|
|
460 |
{
|
|
461 |
// Note: we could just check for the ERROR key by itself,
|
|
462 |
// since we now set that, but since we have to go
|
|
463 |
// through the whole hash anyway, do it this way,
|
|
464 |
// which is safer for maintenance
|
|
465 |
if (keyStr.startsWith(ERROR))
|
|
466 |
{
|
|
467 |
errors = true;
|
|
468 |
}
|
|
469 |
Element node = factory.createElement("item");
|
|
470 |
node.setAttribute("key", keyStr);
|
|
471 |
node.appendChild(factory.createTextNode((String)h.get(keyStr)));
|
|
472 |
hashNode.appendChild(node);
|
|
473 |
}
|
|
474 |
}
|
|
475 |
catch (Exception e)
|
|
476 |
{
|
|
477 |
errors = true;
|
|
478 |
Element node = factory.createElement("item");
|
|
479 |
node.setAttribute("key", keyStr);
|
|
480 |
node.appendChild(factory.createTextNode(ERROR + " Reading " + key + " threw: " + e.toString()));
|
|
481 |
hashNode.appendChild(node);
|
|
482 |
}
|
|
483 |
} // end of for...
|
|
484 |
|
|
485 |
Element statusNode = factory.createElement("status");
|
|
486 |
statusNode.setAttribute("result", (errors ? "ERROR" : "OK" ));
|
|
487 |
envCheckNode.appendChild(statusNode);
|
|
488 |
}
|
|
489 |
catch (Exception e2)
|
|
490 |
{
|
|
491 |
System.err.println("appendEnvironmentReport threw: " + e2.toString());
|
|
492 |
e2.printStackTrace();
|
|
493 |
}
|
|
494 |
}
|
|
495 |
|
|
496 |
/**
|
|
497 |
* Print out report of .jars found in a classpath.
|
|
498 |
*
|
|
499 |
* Takes the information encoded from a checkPathForJars()
|
|
500 |
* call and dumps it out to our PrintWriter.
|
|
501 |
*
|
|
502 |
* @param container Node to append our report to
|
|
503 |
* @param factory Document providing createElement, etc. services
|
|
504 |
* @param v Vector of Hashtables of .jar file info
|
|
505 |
* @param desc description to print out in header
|
|
506 |
*
|
|
507 |
* @return false if OK, true if any .jars were reported
|
|
508 |
* as having errors
|
|
509 |
* @see #checkPathForJars(String, String[])
|
|
510 |
*/
|
|
511 |
protected boolean appendFoundJars(Node container, Document factory,
|
|
512 |
Vector v, String desc)
|
|
513 |
{
|
|
514 |
|
|
515 |
if ((null == v) || (v.size() < 1))
|
|
516 |
return false;
|
|
517 |
|
|
518 |
boolean errors = false;
|
|
519 |
|
|
520 |
for (int i = 0; i < v.size(); i++)
|
|
521 |
{
|
|
522 |
Hashtable subhash = (Hashtable) v.elementAt(i);
|
|
523 |
|
|
524 |
for (Enumeration keys = subhash.keys();
|
|
525 |
keys.hasMoreElements();
|
|
526 |
/* no increment portion */
|
|
527 |
)
|
|
528 |
{
|
|
529 |
Object key = keys.nextElement();
|
|
530 |
try
|
|
531 |
{
|
|
532 |
String keyStr = (String) key;
|
|
533 |
if (keyStr.startsWith(ERROR))
|
|
534 |
{
|
|
535 |
errors = true;
|
|
536 |
}
|
|
537 |
Element node = factory.createElement("foundJar");
|
|
538 |
node.setAttribute("name", keyStr.substring(0, keyStr.indexOf("-")));
|
|
539 |
node.setAttribute("desc", keyStr.substring(keyStr.indexOf("-") + 1));
|
|
540 |
node.appendChild(factory.createTextNode((String)subhash.get(keyStr)));
|
|
541 |
container.appendChild(node);
|
|
542 |
}
|
|
543 |
catch (Exception e)
|
|
544 |
{
|
|
545 |
errors = true;
|
|
546 |
Element node = factory.createElement("foundJar");
|
|
547 |
node.appendChild(factory.createTextNode(ERROR + " Reading " + key + " threw: " + e.toString()));
|
|
548 |
container.appendChild(node);
|
|
549 |
}
|
|
550 |
}
|
|
551 |
}
|
|
552 |
return errors;
|
|
553 |
}
|
|
554 |
|
|
555 |
/**
|
|
556 |
* Fillin hash with info about SystemProperties.
|
|
557 |
*
|
|
558 |
* Logs java.class.path and other likely paths; then attempts
|
|
559 |
* to search those paths for .jar files with Xalan-related classes.
|
|
560 |
*
|
|
561 |
* //@todo NOTE: We don't actually search java.ext.dirs for
|
|
562 |
* // *.jar files therein! This should be updated
|
|
563 |
*
|
|
564 |
* @param h Hashtable to put information in
|
|
565 |
* @see #jarNames
|
|
566 |
* @see #checkPathForJars(String, String[])
|
|
567 |
*/
|
|
568 |
protected void checkSystemProperties(Hashtable h)
|
|
569 |
{
|
|
570 |
|
|
571 |
if (null == h)
|
|
572 |
h = new Hashtable();
|
|
573 |
|
|
574 |
// Grab java version for later use
|
|
575 |
try
|
|
576 |
{
|
|
577 |
String javaVersion = System.getProperty("java.version");
|
|
578 |
|
|
579 |
h.put("java.version", javaVersion);
|
|
580 |
}
|
|
581 |
catch (SecurityException se)
|
|
582 |
{
|
|
583 |
|
|
584 |
// For applet context, etc.
|
|
585 |
h.put(
|
|
586 |
"java.version",
|
|
587 |
"WARNING: SecurityException thrown accessing system version properties");
|
|
588 |
}
|
|
589 |
|
|
590 |
// Printout jar files on classpath(s) that may affect operation
|
|
591 |
// Do this in order
|
|
592 |
try
|
|
593 |
{
|
|
594 |
|
|
595 |
// This is present in all JVM's
|
|
596 |
String cp = System.getProperty("java.class.path");
|
|
597 |
|
|
598 |
h.put("java.class.path", cp);
|
|
599 |
|
|
600 |
Vector classpathJars = checkPathForJars(cp, jarNames);
|
|
601 |
|
|
602 |
if (null != classpathJars)
|
|
603 |
h.put(FOUNDCLASSES + "java.class.path", classpathJars);
|
|
604 |
|
|
605 |
// Also check for JDK 1.2+ type classpaths
|
|
606 |
String othercp = System.getProperty("sun.boot.class.path");
|
|
607 |
|
|
608 |
if (null != othercp)
|
|
609 |
{
|
|
610 |
h.put("sun.boot.class.path", othercp);
|
|
611 |
|
|
612 |
classpathJars = checkPathForJars(othercp, jarNames);
|
|
613 |
|
|
614 |
if (null != classpathJars)
|
|
615 |
h.put(FOUNDCLASSES + "sun.boot.class.path", classpathJars);
|
|
616 |
}
|
|
617 |
|
|
618 |
//@todo NOTE: We don't actually search java.ext.dirs for
|
|
619 |
// *.jar files therein! This should be updated
|
|
620 |
othercp = System.getProperty("java.ext.dirs");
|
|
621 |
|
|
622 |
if (null != othercp)
|
|
623 |
{
|
|
624 |
h.put("java.ext.dirs", othercp);
|
|
625 |
|
|
626 |
classpathJars = checkPathForJars(othercp, jarNames);
|
|
627 |
|
|
628 |
if (null != classpathJars)
|
|
629 |
h.put(FOUNDCLASSES + "java.ext.dirs", classpathJars);
|
|
630 |
}
|
|
631 |
|
|
632 |
//@todo also check other System properties' paths?
|
|
633 |
// v2 = checkPathForJars(System.getProperty("sun.boot.library.path"), jarNames); // ?? may not be needed
|
|
634 |
// v3 = checkPathForJars(System.getProperty("java.library.path"), jarNames); // ?? may not be needed
|
|
635 |
}
|
|
636 |
catch (SecurityException se2)
|
|
637 |
{
|
|
638 |
// For applet context, etc.
|
|
639 |
h.put(
|
|
640 |
"java.class.path",
|
|
641 |
"WARNING: SecurityException thrown accessing system classpath properties");
|
|
642 |
}
|
|
643 |
}
|
|
644 |
|
|
645 |
/**
|
|
646 |
* Cheap-o listing of specified .jars found in the classpath.
|
|
647 |
*
|
|
648 |
* cp should be separated by the usual File.pathSeparator. We
|
|
649 |
* then do a simplistic search of the path for any requested
|
|
650 |
* .jar filenames, and return a listing of their names and
|
|
651 |
* where (apparently) they came from.
|
|
652 |
*
|
|
653 |
* @param cp classpath to search
|
|
654 |
* @param jars array of .jar base filenames to look for
|
|
655 |
*
|
|
656 |
* @return Vector of Hashtables filled with info about found .jars
|
|
657 |
* @see #jarNames
|
|
658 |
* @see #logFoundJars(Vector, String)
|
|
659 |
* @see #appendFoundJars(Node, Document, Vector, String )
|
|
660 |
* @see #getApparentVersion(String, long)
|
|
661 |
*/
|
|
662 |
protected Vector checkPathForJars(String cp, String[] jars)
|
|
663 |
{
|
|
664 |
|
|
665 |
if ((null == cp) || (null == jars) || (0 == cp.length())
|
|
666 |
|| (0 == jars.length))
|
|
667 |
return null;
|
|
668 |
|
|
669 |
Vector v = new Vector();
|
|
670 |
StringTokenizer st = new StringTokenizer(cp, File.pathSeparator);
|
|
671 |
|
|
672 |
while (st.hasMoreTokens())
|
|
673 |
{
|
|
674 |
|
|
675 |
// Look at each classpath entry for each of our requested jarNames
|
|
676 |
String filename = st.nextToken();
|
|
677 |
|
|
678 |
for (int i = 0; i < jars.length; i++)
|
|
679 |
{
|
|
680 |
if (filename.indexOf(jars[i]) > -1)
|
|
681 |
{
|
|
682 |
File f = new File(filename);
|
|
683 |
|
|
684 |
if (f.exists())
|
|
685 |
{
|
|
686 |
|
|
687 |
// If any requested jarName exists, report on
|
|
688 |
// the details of that .jar file
|
|
689 |
try
|
|
690 |
{
|
|
691 |
Hashtable h = new Hashtable(2);
|
|
692 |
// Note "-" char is looked for in appendFoundJars
|
|
693 |
h.put(jars[i] + "-path", f.getAbsolutePath());
|
|
694 |
|
|
695 |
// We won't bother reporting on the xalan.jar apparent version
|
|
696 |
// since this requires knowing the jar size of the xalan.jar
|
|
697 |
// before we build it.
|
|
698 |
// For other jars, eg. xml-apis.jar and xercesImpl.jar, we
|
|
699 |
// report the apparent version of the file we've found
|
|
700 |
if (!("xalan.jar".equalsIgnoreCase(jars[i]))) {
|
|
701 |
h.put(jars[i] + "-apparent.version",
|
|
702 |
getApparentVersion(jars[i], f.length()));
|
|
703 |
}
|
|
704 |
v.addElement(h);
|
|
705 |
}
|
|
706 |
catch (Exception e)
|
|
707 |
{
|
|
708 |
|
|
709 |
/* no-op, don't add it */
|
|
710 |
}
|
|
711 |
}
|
|
712 |
else
|
|
713 |
{
|
|
714 |
Hashtable h = new Hashtable(2);
|
|
715 |
// Note "-" char is looked for in appendFoundJars
|
|
716 |
h.put(jars[i] + "-path", WARNING + " Classpath entry: "
|
|
717 |
+ filename + " does not exist");
|
|
718 |
h.put(jars[i] + "-apparent.version", CLASS_NOTPRESENT);
|
|
719 |
v.addElement(h);
|
|
720 |
}
|
|
721 |
}
|
|
722 |
}
|
|
723 |
}
|
|
724 |
|
|
725 |
return v;
|
|
726 |
}
|
|
727 |
|
|
728 |
/**
|
|
729 |
* Cheap-o method to determine the product version of a .jar.
|
|
730 |
*
|
|
731 |
* Currently does a lookup into a local table of some recent
|
|
732 |
* shipped Xalan builds to determine where the .jar probably
|
|
733 |
* came from. Note that if you recompile Xalan or Xerces
|
|
734 |
* yourself this will likely report a potential error, since
|
|
735 |
* we can't certify builds other than the ones we ship.
|
|
736 |
* Only reports against selected posted Xalan-J builds.
|
|
737 |
*
|
|
738 |
* //@todo actually look up version info in manifests
|
|
739 |
*
|
|
740 |
* @param jarName base filename of the .jarfile
|
|
741 |
* @param jarSize size of the .jarfile
|
|
742 |
*
|
|
743 |
* @return String describing where the .jar file probably
|
|
744 |
* came from
|
|
745 |
*/
|
|
746 |
protected String getApparentVersion(String jarName, long jarSize)
|
|
747 |
{
|
|
748 |
// If we found a matching size and it's for our
|
|
749 |
// jar, then return it's description
|
|
750 |
// Lookup in static jarVersions Hashtable
|
|
751 |
String foundSize = (String) jarVersions.get(new Long(jarSize));
|
|
752 |
|
|
753 |
if ((null != foundSize) && (foundSize.startsWith(jarName)))
|
|
754 |
{
|
|
755 |
return foundSize;
|
|
756 |
}
|
|
757 |
else
|
|
758 |
{
|
|
759 |
if ("xerces.jar".equalsIgnoreCase(jarName)
|
|
760 |
|| "xercesImpl.jar".equalsIgnoreCase(jarName))
|
|
761 |
// || "xalan.jar".equalsIgnoreCase(jarName))
|
|
762 |
{
|
|
763 |
|
|
764 |
// For xalan.jar and xerces.jar/xercesImpl.jar, which we ship together:
|
|
765 |
// The jar is not from a shipped copy of xalan-j, so
|
|
766 |
// it's up to the user to ensure that it's compatible
|
|
767 |
return jarName + " " + WARNING + CLASS_PRESENT;
|
|
768 |
}
|
|
769 |
else
|
|
770 |
{
|
|
771 |
|
|
772 |
// Otherwise, it's just a jar we don't have the version info calculated for
|
|
773 |
return jarName + " " + CLASS_PRESENT;
|
|
774 |
}
|
|
775 |
}
|
|
776 |
}
|
|
777 |
|
|
778 |
/**
|
|
779 |
* Report version information about JAXP interfaces.
|
|
780 |
*
|
|
781 |
* Currently distinguishes between JAXP 1.0.1 and JAXP 1.1,
|
|
782 |
* and not found; only tests the interfaces, and does not
|
|
783 |
* check for reference implementation versions.
|
|
784 |
*
|
|
785 |
* @param h Hashtable to put information in
|
|
786 |
*/
|
|
787 |
protected void checkJAXPVersion(Hashtable h)
|
|
788 |
{
|
|
789 |
|
|
790 |
if (null == h)
|
|
791 |
h = new Hashtable();
|
|
792 |
|
|
793 |
Class clazz = null;
|
|
794 |
|
|
795 |
try
|
|
796 |
{
|
|
797 |
final String JAXP1_CLASS = "javax.xml.stream.XMLStreamConstants";
|
|
798 |
|
12458
|
799 |
clazz = ObjectFactory.findProviderClass(JAXP1_CLASS, true);
|
12005
|
800 |
|
|
801 |
// If we succeeded, we have JAXP 1.4 available
|
|
802 |
h.put(VERSION + "JAXP", "1.4");
|
|
803 |
}
|
|
804 |
catch (Exception e)
|
|
805 |
{
|
|
806 |
h.put(ERROR + VERSION + "JAXP", "1.3");
|
|
807 |
h.put(ERROR, ERROR_FOUND);
|
|
808 |
}
|
|
809 |
}
|
|
810 |
|
|
811 |
/**
|
|
812 |
* Report product version information from Xalan-J.
|
|
813 |
*
|
|
814 |
* Looks for version info in xalan.jar from Xalan-J products.
|
|
815 |
*
|
|
816 |
* @param h Hashtable to put information in
|
|
817 |
*/
|
|
818 |
protected void checkProcessorVersion(Hashtable h)
|
|
819 |
{
|
|
820 |
|
|
821 |
if (null == h)
|
|
822 |
h = new Hashtable();
|
|
823 |
|
|
824 |
try
|
|
825 |
{
|
|
826 |
final String XALAN1_VERSION_CLASS =
|
|
827 |
"com.sun.org.apache.xalan.internal.xslt.XSLProcessorVersion";
|
|
828 |
|
12458
|
829 |
Class clazz = ObjectFactory.findProviderClass(XALAN1_VERSION_CLASS, true);
|
12005
|
830 |
|
|
831 |
// Found Xalan-J 1.x, grab it's version fields
|
|
832 |
StringBuffer buf = new StringBuffer();
|
|
833 |
Field f = clazz.getField("PRODUCT");
|
|
834 |
|
|
835 |
buf.append(f.get(null));
|
|
836 |
buf.append(';');
|
|
837 |
|
|
838 |
f = clazz.getField("LANGUAGE");
|
|
839 |
|
|
840 |
buf.append(f.get(null));
|
|
841 |
buf.append(';');
|
|
842 |
|
|
843 |
f = clazz.getField("S_VERSION");
|
|
844 |
|
|
845 |
buf.append(f.get(null));
|
|
846 |
buf.append(';');
|
|
847 |
h.put(VERSION + "xalan1", buf.toString());
|
|
848 |
}
|
|
849 |
catch (Exception e1)
|
|
850 |
{
|
|
851 |
h.put(VERSION + "xalan1", CLASS_NOTPRESENT);
|
|
852 |
}
|
|
853 |
|
|
854 |
try
|
|
855 |
{
|
|
856 |
// NOTE: This is the old Xalan 2.0, 2.1, 2.2 version class,
|
|
857 |
// is being replaced by class below
|
|
858 |
final String XALAN2_VERSION_CLASS =
|
|
859 |
"com.sun.org.apache.xalan.internal.processor.XSLProcessorVersion";
|
|
860 |
|
12458
|
861 |
Class clazz = ObjectFactory.findProviderClass(XALAN2_VERSION_CLASS, true);
|
12005
|
862 |
|
|
863 |
// Found Xalan-J 2.x, grab it's version fields
|
|
864 |
StringBuffer buf = new StringBuffer();
|
|
865 |
Field f = clazz.getField("S_VERSION");
|
|
866 |
buf.append(f.get(null));
|
|
867 |
|
|
868 |
h.put(VERSION + "xalan2x", buf.toString());
|
|
869 |
}
|
|
870 |
catch (Exception e2)
|
|
871 |
{
|
|
872 |
h.put(VERSION + "xalan2x", CLASS_NOTPRESENT);
|
|
873 |
}
|
|
874 |
try
|
|
875 |
{
|
|
876 |
// NOTE: This is the new Xalan 2.2+ version class
|
|
877 |
final String XALAN2_2_VERSION_CLASS =
|
|
878 |
"com.sun.org.apache.xalan.internal.Version";
|
|
879 |
final String XALAN2_2_VERSION_METHOD = "getVersion";
|
|
880 |
final Class noArgs[] = new Class[0];
|
|
881 |
|
12458
|
882 |
Class clazz = ObjectFactory.findProviderClass(XALAN2_2_VERSION_CLASS, true);
|
12005
|
883 |
|
|
884 |
Method method = clazz.getMethod(XALAN2_2_VERSION_METHOD, noArgs);
|
|
885 |
Object returnValue = method.invoke(null, new Object[0]);
|
|
886 |
|
|
887 |
h.put(VERSION + "xalan2_2", (String)returnValue);
|
|
888 |
}
|
|
889 |
catch (Exception e2)
|
|
890 |
{
|
|
891 |
h.put(VERSION + "xalan2_2", CLASS_NOTPRESENT);
|
|
892 |
}
|
|
893 |
}
|
|
894 |
|
|
895 |
/**
|
|
896 |
* Report product version information from common parsers.
|
|
897 |
*
|
|
898 |
* Looks for version info in xerces.jar/xercesImpl.jar/crimson.jar.
|
|
899 |
*
|
|
900 |
* //@todo actually look up version info in crimson manifest
|
|
901 |
*
|
|
902 |
* @param h Hashtable to put information in
|
|
903 |
*/
|
|
904 |
protected void checkParserVersion(Hashtable h)
|
|
905 |
{
|
|
906 |
|
|
907 |
if (null == h)
|
|
908 |
h = new Hashtable();
|
|
909 |
|
|
910 |
try
|
|
911 |
{
|
|
912 |
final String XERCES1_VERSION_CLASS = "com.sun.org.apache.xerces.internal.framework.Version";
|
|
913 |
|
12458
|
914 |
Class clazz = ObjectFactory.findProviderClass(XERCES1_VERSION_CLASS, true);
|
12005
|
915 |
|
|
916 |
// Found Xerces-J 1.x, grab it's version fields
|
|
917 |
Field f = clazz.getField("fVersion");
|
|
918 |
String parserVersion = (String) f.get(null);
|
|
919 |
|
|
920 |
h.put(VERSION + "xerces1", parserVersion);
|
|
921 |
}
|
|
922 |
catch (Exception e)
|
|
923 |
{
|
|
924 |
h.put(VERSION + "xerces1", CLASS_NOTPRESENT);
|
|
925 |
}
|
|
926 |
|
|
927 |
// Look for xerces1 and xerces2 parsers separately
|
|
928 |
try
|
|
929 |
{
|
|
930 |
final String XERCES2_VERSION_CLASS = "com.sun.org.apache.xerces.internal.impl.Version";
|
|
931 |
|
12458
|
932 |
Class clazz = ObjectFactory.findProviderClass(XERCES2_VERSION_CLASS, true);
|
12005
|
933 |
|
|
934 |
// Found Xerces-J 2.x, grab it's version fields
|
|
935 |
Field f = clazz.getField("fVersion");
|
|
936 |
String parserVersion = (String) f.get(null);
|
|
937 |
|
|
938 |
h.put(VERSION + "xerces2", parserVersion);
|
|
939 |
}
|
|
940 |
catch (Exception e)
|
|
941 |
{
|
|
942 |
h.put(VERSION + "xerces2", CLASS_NOTPRESENT);
|
|
943 |
}
|
|
944 |
|
|
945 |
try
|
|
946 |
{
|
|
947 |
final String CRIMSON_CLASS = "org.apache.crimson.parser.Parser2";
|
|
948 |
|
12458
|
949 |
Class clazz = ObjectFactory.findProviderClass(CRIMSON_CLASS, true);
|
12005
|
950 |
|
|
951 |
//@todo determine specific crimson version
|
|
952 |
h.put(VERSION + "crimson", CLASS_PRESENT);
|
|
953 |
}
|
|
954 |
catch (Exception e)
|
|
955 |
{
|
|
956 |
h.put(VERSION + "crimson", CLASS_NOTPRESENT);
|
|
957 |
}
|
|
958 |
}
|
|
959 |
|
|
960 |
/**
|
|
961 |
* Report product version information from Ant.
|
|
962 |
*
|
|
963 |
* @param h Hashtable to put information in
|
|
964 |
*/
|
|
965 |
protected void checkAntVersion(Hashtable h)
|
|
966 |
{
|
|
967 |
|
|
968 |
if (null == h)
|
|
969 |
h = new Hashtable();
|
|
970 |
|
|
971 |
try
|
|
972 |
{
|
|
973 |
final String ANT_VERSION_CLASS = "org.apache.tools.ant.Main";
|
|
974 |
final String ANT_VERSION_METHOD = "getAntVersion"; // noArgs
|
|
975 |
final Class noArgs[] = new Class[0];
|
|
976 |
|
12458
|
977 |
Class clazz = ObjectFactory.findProviderClass(ANT_VERSION_CLASS, true);
|
12005
|
978 |
|
|
979 |
Method method = clazz.getMethod(ANT_VERSION_METHOD, noArgs);
|
|
980 |
Object returnValue = method.invoke(null, new Object[0]);
|
|
981 |
|
|
982 |
h.put(VERSION + "ant", (String)returnValue);
|
|
983 |
}
|
|
984 |
catch (Exception e)
|
|
985 |
{
|
|
986 |
h.put(VERSION + "ant", CLASS_NOTPRESENT);
|
|
987 |
}
|
|
988 |
}
|
|
989 |
|
|
990 |
/**
|
|
991 |
* Report version info from DOM interfaces.
|
|
992 |
*
|
|
993 |
* @param h Hashtable to put information in
|
|
994 |
*/
|
|
995 |
protected boolean checkDOML3(Hashtable h)
|
|
996 |
{
|
|
997 |
|
|
998 |
if (null == h)
|
|
999 |
h = new Hashtable();
|
|
1000 |
|
|
1001 |
final String DOM_CLASS = "org.w3c.dom.Document";
|
|
1002 |
final String DOM_LEVEL3_METHOD = "getDoctype"; // no parameter
|
|
1003 |
|
|
1004 |
try
|
|
1005 |
{
|
12458
|
1006 |
Class clazz = ObjectFactory.findProviderClass(DOM_CLASS, true);
|
12005
|
1007 |
|
14942
|
1008 |
Method method = clazz.getMethod(DOM_LEVEL3_METHOD, (Class<?>[])null);
|
12005
|
1009 |
|
|
1010 |
// If we succeeded, we have loaded interfaces from a
|
|
1011 |
// level 3 DOM somewhere
|
|
1012 |
h.put(VERSION + "DOM", "3.0");
|
|
1013 |
return true;
|
|
1014 |
}
|
|
1015 |
catch (Exception e)
|
|
1016 |
{
|
|
1017 |
return false;
|
|
1018 |
}
|
|
1019 |
}
|
|
1020 |
|
|
1021 |
/**
|
|
1022 |
* Report version info from DOM interfaces.
|
|
1023 |
*
|
|
1024 |
* Currently distinguishes between pre-DOM level 2, the DOM
|
|
1025 |
* level 2 working draft, the DOM level 2 final draft,
|
|
1026 |
* and not found.
|
|
1027 |
*
|
|
1028 |
* @param h Hashtable to put information in
|
|
1029 |
*/
|
|
1030 |
protected void checkDOMVersion(Hashtable h)
|
|
1031 |
{
|
|
1032 |
|
|
1033 |
if (null == h)
|
|
1034 |
h = new Hashtable();
|
|
1035 |
|
|
1036 |
final String DOM_LEVEL2_CLASS = "org.w3c.dom.Document";
|
|
1037 |
final String DOM_LEVEL2_METHOD = "createElementNS"; // String, String
|
|
1038 |
final String DOM_LEVEL3_METHOD = "getDoctype"; // no parameter
|
|
1039 |
final String DOM_LEVEL2WD_CLASS = "org.w3c.dom.Node";
|
|
1040 |
final String DOM_LEVEL2WD_METHOD = "supported"; // String, String
|
|
1041 |
final String DOM_LEVEL2FD_CLASS = "org.w3c.dom.Node";
|
|
1042 |
final String DOM_LEVEL2FD_METHOD = "isSupported"; // String, String
|
|
1043 |
final Class twoStringArgs[] = { java.lang.String.class,
|
|
1044 |
java.lang.String.class };
|
|
1045 |
|
|
1046 |
try
|
|
1047 |
{
|
12458
|
1048 |
Class clazz = ObjectFactory.findProviderClass(DOM_LEVEL2_CLASS, true);
|
12005
|
1049 |
|
|
1050 |
Method method = clazz.getMethod(DOM_LEVEL2_METHOD, twoStringArgs);
|
|
1051 |
|
|
1052 |
// If we succeeded, we have loaded interfaces from a
|
|
1053 |
// level 2 DOM somewhere
|
|
1054 |
h.put(VERSION + "DOM", "2.0");
|
|
1055 |
|
|
1056 |
try
|
|
1057 |
{
|
|
1058 |
// Check for the working draft version, which is
|
|
1059 |
// commonly found, but won't work anymore
|
12458
|
1060 |
clazz = ObjectFactory.findProviderClass(DOM_LEVEL2WD_CLASS, true);
|
12005
|
1061 |
|
|
1062 |
method = clazz.getMethod(DOM_LEVEL2WD_METHOD, twoStringArgs);
|
|
1063 |
|
|
1064 |
h.put(ERROR + VERSION + "DOM.draftlevel", "2.0wd");
|
|
1065 |
h.put(ERROR, ERROR_FOUND);
|
|
1066 |
}
|
|
1067 |
catch (Exception e2)
|
|
1068 |
{
|
|
1069 |
try
|
|
1070 |
{
|
|
1071 |
// Check for the final draft version as well
|
12458
|
1072 |
clazz = ObjectFactory.findProviderClass(DOM_LEVEL2FD_CLASS, true);
|
12005
|
1073 |
|
|
1074 |
method = clazz.getMethod(DOM_LEVEL2FD_METHOD, twoStringArgs);
|
|
1075 |
|
|
1076 |
h.put(VERSION + "DOM.draftlevel", "2.0fd");
|
|
1077 |
}
|
|
1078 |
catch (Exception e3)
|
|
1079 |
{
|
|
1080 |
h.put(ERROR + VERSION + "DOM.draftlevel", "2.0unknown");
|
|
1081 |
h.put(ERROR, ERROR_FOUND);
|
|
1082 |
}
|
|
1083 |
}
|
|
1084 |
}
|
|
1085 |
catch (Exception e)
|
|
1086 |
{
|
|
1087 |
h.put(ERROR + VERSION + "DOM",
|
|
1088 |
"ERROR attempting to load DOM level 2 class: " + e.toString());
|
|
1089 |
h.put(ERROR, ERROR_FOUND);
|
|
1090 |
}
|
|
1091 |
|
|
1092 |
//@todo load an actual DOM implmementation and query it as well
|
|
1093 |
//@todo load an actual DOM implmementation and check if
|
|
1094 |
// isNamespaceAware() == true, which is needed to parse
|
|
1095 |
// xsl stylesheet files into a DOM
|
|
1096 |
}
|
|
1097 |
|
|
1098 |
/**
|
|
1099 |
* Report version info from SAX interfaces.
|
|
1100 |
*
|
|
1101 |
* Currently distinguishes between SAX 2, SAX 2.0beta2,
|
|
1102 |
* SAX1, and not found.
|
|
1103 |
*
|
|
1104 |
* @param h Hashtable to put information in
|
|
1105 |
*/
|
|
1106 |
protected void checkSAXVersion(Hashtable h)
|
|
1107 |
{
|
|
1108 |
|
|
1109 |
if (null == h)
|
|
1110 |
h = new Hashtable();
|
|
1111 |
|
|
1112 |
final String SAX_VERSION1_CLASS = "org.xml.sax.Parser";
|
|
1113 |
final String SAX_VERSION1_METHOD = "parse"; // String
|
|
1114 |
final String SAX_VERSION2_CLASS = "org.xml.sax.XMLReader";
|
|
1115 |
final String SAX_VERSION2_METHOD = "parse"; // String
|
|
1116 |
final String SAX_VERSION2BETA_CLASSNF = "org.xml.sax.helpers.AttributesImpl";
|
|
1117 |
final String SAX_VERSION2BETA_METHODNF = "setAttributes"; // Attributes
|
|
1118 |
final Class oneStringArg[] = { java.lang.String.class };
|
|
1119 |
// Note this introduces a minor compile dependency on SAX...
|
|
1120 |
final Class attributesArg[] = { org.xml.sax.Attributes.class };
|
|
1121 |
|
|
1122 |
try
|
|
1123 |
{
|
|
1124 |
// This method was only added in the final SAX 2.0 release;
|
|
1125 |
// see changes.html "Changes from SAX 2.0beta2 to SAX 2.0prerelease"
|
12458
|
1126 |
Class clazz = ObjectFactory.findProviderClass(SAX_VERSION2BETA_CLASSNF, true);
|
12005
|
1127 |
|
|
1128 |
Method method = clazz.getMethod(SAX_VERSION2BETA_METHODNF, attributesArg);
|
|
1129 |
|
|
1130 |
// If we succeeded, we have loaded interfaces from a
|
|
1131 |
// real, final SAX version 2.0 somewhere
|
|
1132 |
h.put(VERSION + "SAX", "2.0");
|
|
1133 |
}
|
|
1134 |
catch (Exception e)
|
|
1135 |
{
|
|
1136 |
// If we didn't find the SAX 2.0 class, look for a 2.0beta2
|
|
1137 |
h.put(ERROR + VERSION + "SAX",
|
|
1138 |
"ERROR attempting to load SAX version 2 class: " + e.toString());
|
|
1139 |
h.put(ERROR, ERROR_FOUND);
|
|
1140 |
|
|
1141 |
try
|
|
1142 |
{
|
12458
|
1143 |
Class clazz = ObjectFactory.findProviderClass(SAX_VERSION2_CLASS, true);
|
12005
|
1144 |
|
|
1145 |
Method method = clazz.getMethod(SAX_VERSION2_METHOD, oneStringArg);
|
|
1146 |
|
|
1147 |
// If we succeeded, we have loaded interfaces from a
|
|
1148 |
// SAX version 2.0beta2 or earlier; these might work but
|
|
1149 |
// you should really have the final SAX 2.0
|
|
1150 |
h.put(VERSION + "SAX-backlevel", "2.0beta2-or-earlier");
|
|
1151 |
}
|
|
1152 |
catch (Exception e2)
|
|
1153 |
{
|
|
1154 |
// If we didn't find the SAX 2.0beta2 class, look for a 1.0 one
|
|
1155 |
h.put(ERROR + VERSION + "SAX",
|
|
1156 |
"ERROR attempting to load SAX version 2 class: " + e.toString());
|
|
1157 |
h.put(ERROR, ERROR_FOUND);
|
|
1158 |
|
|
1159 |
try
|
|
1160 |
{
|
12458
|
1161 |
Class clazz = ObjectFactory.findProviderClass(SAX_VERSION1_CLASS, true);
|
12005
|
1162 |
|
|
1163 |
Method method = clazz.getMethod(SAX_VERSION1_METHOD, oneStringArg);
|
|
1164 |
|
|
1165 |
// If we succeeded, we have loaded interfaces from a
|
|
1166 |
// SAX version 1.0 somewhere; which won't work very
|
|
1167 |
// well for JAXP 1.1 or beyond!
|
|
1168 |
h.put(VERSION + "SAX-backlevel", "1.0");
|
|
1169 |
}
|
|
1170 |
catch (Exception e3)
|
|
1171 |
{
|
|
1172 |
// If we didn't find the SAX 2.0 class, look for a 1.0 one
|
|
1173 |
// Note that either 1.0 or no SAX are both errors
|
|
1174 |
h.put(ERROR + VERSION + "SAX-backlevel",
|
|
1175 |
"ERROR attempting to load SAX version 1 class: " + e3.toString());
|
|
1176 |
|
|
1177 |
}
|
|
1178 |
}
|
|
1179 |
}
|
|
1180 |
}
|
|
1181 |
|
|
1182 |
/**
|
|
1183 |
* Manual table of known .jar sizes.
|
|
1184 |
* Only includes shipped versions of certain projects.
|
|
1185 |
* key=jarsize, value=jarname ' from ' distro name
|
|
1186 |
* Note assumption: two jars cannot have the same size!
|
|
1187 |
*
|
|
1188 |
* @see #getApparentVersion(String, long)
|
|
1189 |
*/
|
|
1190 |
private static Hashtable jarVersions = new Hashtable();
|
|
1191 |
|
|
1192 |
/**
|
|
1193 |
* Static initializer for jarVersions table.
|
|
1194 |
* Doing this just once saves time and space.
|
|
1195 |
*
|
|
1196 |
* @see #getApparentVersion(String, long)
|
|
1197 |
*/
|
|
1198 |
static
|
|
1199 |
{
|
|
1200 |
// Note: hackish Hashtable, this could use improvement
|
|
1201 |
jarVersions.put(new Long(857192), "xalan.jar from xalan-j_1_1");
|
|
1202 |
jarVersions.put(new Long(440237), "xalan.jar from xalan-j_1_2");
|
|
1203 |
jarVersions.put(new Long(436094), "xalan.jar from xalan-j_1_2_1");
|
|
1204 |
jarVersions.put(new Long(426249), "xalan.jar from xalan-j_1_2_2");
|
|
1205 |
jarVersions.put(new Long(702536), "xalan.jar from xalan-j_2_0_0");
|
|
1206 |
jarVersions.put(new Long(720930), "xalan.jar from xalan-j_2_0_1");
|
|
1207 |
jarVersions.put(new Long(732330), "xalan.jar from xalan-j_2_1_0");
|
|
1208 |
jarVersions.put(new Long(872241), "xalan.jar from xalan-j_2_2_D10");
|
|
1209 |
jarVersions.put(new Long(882739), "xalan.jar from xalan-j_2_2_D11");
|
|
1210 |
jarVersions.put(new Long(923866), "xalan.jar from xalan-j_2_2_0");
|
|
1211 |
jarVersions.put(new Long(905872), "xalan.jar from xalan-j_2_3_D1");
|
|
1212 |
jarVersions.put(new Long(906122), "xalan.jar from xalan-j_2_3_0");
|
|
1213 |
jarVersions.put(new Long(906248), "xalan.jar from xalan-j_2_3_1");
|
|
1214 |
jarVersions.put(new Long(983377), "xalan.jar from xalan-j_2_4_D1");
|
|
1215 |
jarVersions.put(new Long(997276), "xalan.jar from xalan-j_2_4_0");
|
|
1216 |
jarVersions.put(new Long(1031036), "xalan.jar from xalan-j_2_4_1");
|
|
1217 |
// Stop recording xalan.jar sizes as of Xalan Java 2.5.0
|
|
1218 |
|
|
1219 |
jarVersions.put(new Long(596540), "xsltc.jar from xalan-j_2_2_0");
|
|
1220 |
jarVersions.put(new Long(590247), "xsltc.jar from xalan-j_2_3_D1");
|
|
1221 |
jarVersions.put(new Long(589914), "xsltc.jar from xalan-j_2_3_0");
|
|
1222 |
jarVersions.put(new Long(589915), "xsltc.jar from xalan-j_2_3_1");
|
|
1223 |
jarVersions.put(new Long(1306667), "xsltc.jar from xalan-j_2_4_D1");
|
|
1224 |
jarVersions.put(new Long(1328227), "xsltc.jar from xalan-j_2_4_0");
|
|
1225 |
jarVersions.put(new Long(1344009), "xsltc.jar from xalan-j_2_4_1");
|
|
1226 |
jarVersions.put(new Long(1348361), "xsltc.jar from xalan-j_2_5_D1");
|
|
1227 |
// Stop recording xsltc.jar sizes as of Xalan Java 2.5.0
|
|
1228 |
|
|
1229 |
jarVersions.put(new Long(1268634), "xsltc.jar-bundled from xalan-j_2_3_0");
|
|
1230 |
|
|
1231 |
jarVersions.put(new Long(100196), "xml-apis.jar from xalan-j_2_2_0 or xalan-j_2_3_D1");
|
|
1232 |
jarVersions.put(new Long(108484), "xml-apis.jar from xalan-j_2_3_0, or xalan-j_2_3_1 from xml-commons-1.0.b2");
|
|
1233 |
jarVersions.put(new Long(109049), "xml-apis.jar from xalan-j_2_4_0 from xml-commons RIVERCOURT1 branch");
|
|
1234 |
jarVersions.put(new Long(113749), "xml-apis.jar from xalan-j_2_4_1 from factoryfinder-build of xml-commons RIVERCOURT1");
|
|
1235 |
jarVersions.put(new Long(124704), "xml-apis.jar from tck-jaxp-1_2_0 branch of xml-commons");
|
|
1236 |
jarVersions.put(new Long(124724), "xml-apis.jar from tck-jaxp-1_2_0 branch of xml-commons, tag: xml-commons-external_1_2_01");
|
|
1237 |
jarVersions.put(new Long(194205), "xml-apis.jar from head branch of xml-commons, tag: xml-commons-external_1_3_02");
|
|
1238 |
|
|
1239 |
// If the below were more common I would update it to report
|
|
1240 |
// errors better; but this is so old hardly anyone has it
|
|
1241 |
jarVersions.put(new Long(424490), "xalan.jar from Xerces Tools releases - ERROR:DO NOT USE!");
|
|
1242 |
|
|
1243 |
jarVersions.put(new Long(1591855), "xerces.jar from xalan-j_1_1 from xerces-1...");
|
|
1244 |
jarVersions.put(new Long(1498679), "xerces.jar from xalan-j_1_2 from xerces-1_2_0.bin");
|
|
1245 |
jarVersions.put(new Long(1484896), "xerces.jar from xalan-j_1_2_1 from xerces-1_2_1.bin");
|
|
1246 |
jarVersions.put(new Long(804460), "xerces.jar from xalan-j_1_2_2 from xerces-1_2_2.bin");
|
|
1247 |
jarVersions.put(new Long(1499244), "xerces.jar from xalan-j_2_0_0 from xerces-1_2_3.bin");
|
|
1248 |
jarVersions.put(new Long(1605266), "xerces.jar from xalan-j_2_0_1 from xerces-1_3_0.bin");
|
|
1249 |
jarVersions.put(new Long(904030), "xerces.jar from xalan-j_2_1_0 from xerces-1_4.bin");
|
|
1250 |
jarVersions.put(new Long(904030), "xerces.jar from xerces-1_4_0.bin");
|
|
1251 |
jarVersions.put(new Long(1802885), "xerces.jar from xerces-1_4_2.bin");
|
|
1252 |
jarVersions.put(new Long(1734594), "xerces.jar from Xerces-J-bin.2.0.0.beta3");
|
|
1253 |
jarVersions.put(new Long(1808883), "xerces.jar from xalan-j_2_2_D10,D11,D12 or xerces-1_4_3.bin");
|
|
1254 |
jarVersions.put(new Long(1812019), "xerces.jar from xalan-j_2_2_0");
|
|
1255 |
jarVersions.put(new Long(1720292), "xercesImpl.jar from xalan-j_2_3_D1");
|
|
1256 |
jarVersions.put(new Long(1730053), "xercesImpl.jar from xalan-j_2_3_0 or xalan-j_2_3_1 from xerces-2_0_0");
|
|
1257 |
jarVersions.put(new Long(1728861), "xercesImpl.jar from xalan-j_2_4_D1 from xerces-2_0_1");
|
|
1258 |
jarVersions.put(new Long(972027), "xercesImpl.jar from xalan-j_2_4_0 from xerces-2_1");
|
|
1259 |
jarVersions.put(new Long(831587), "xercesImpl.jar from xalan-j_2_4_1 from xerces-2_2");
|
|
1260 |
jarVersions.put(new Long(891817), "xercesImpl.jar from xalan-j_2_5_D1 from xerces-2_3");
|
|
1261 |
jarVersions.put(new Long(895924), "xercesImpl.jar from xerces-2_4");
|
|
1262 |
jarVersions.put(new Long(1010806), "xercesImpl.jar from Xerces-J-bin.2.6.2");
|
|
1263 |
jarVersions.put(new Long(1203860), "xercesImpl.jar from Xerces-J-bin.2.7.1");
|
|
1264 |
|
|
1265 |
jarVersions.put(new Long(37485), "xalanj1compat.jar from xalan-j_2_0_0");
|
|
1266 |
jarVersions.put(new Long(38100), "xalanj1compat.jar from xalan-j_2_0_1");
|
|
1267 |
|
|
1268 |
jarVersions.put(new Long(18779), "xalanservlet.jar from xalan-j_2_0_0");
|
|
1269 |
jarVersions.put(new Long(21453), "xalanservlet.jar from xalan-j_2_0_1");
|
|
1270 |
jarVersions.put(new Long(24826), "xalanservlet.jar from xalan-j_2_3_1 or xalan-j_2_4_1");
|
|
1271 |
jarVersions.put(new Long(24831), "xalanservlet.jar from xalan-j_2_4_1");
|
|
1272 |
// Stop recording xalanservlet.jar sizes as of Xalan Java 2.5.0; now a .war file
|
|
1273 |
|
|
1274 |
// For those who've downloaded JAXP from sun
|
|
1275 |
jarVersions.put(new Long(5618), "jaxp.jar from jaxp1.0.1");
|
|
1276 |
jarVersions.put(new Long(136133), "parser.jar from jaxp1.0.1");
|
|
1277 |
jarVersions.put(new Long(28404), "jaxp.jar from jaxp-1.1");
|
|
1278 |
jarVersions.put(new Long(187162), "crimson.jar from jaxp-1.1");
|
|
1279 |
jarVersions.put(new Long(801714), "xalan.jar from jaxp-1.1");
|
|
1280 |
jarVersions.put(new Long(196399), "crimson.jar from crimson-1.1.1");
|
|
1281 |
jarVersions.put(new Long(33323), "jaxp.jar from crimson-1.1.1 or jakarta-ant-1.4.1b1");
|
|
1282 |
jarVersions.put(new Long(152717), "crimson.jar from crimson-1.1.2beta2");
|
|
1283 |
jarVersions.put(new Long(88143), "xml-apis.jar from crimson-1.1.2beta2");
|
|
1284 |
jarVersions.put(new Long(206384), "crimson.jar from crimson-1.1.3 or jakarta-ant-1.4.1b1");
|
|
1285 |
|
|
1286 |
// jakarta-ant: since many people use ant these days
|
|
1287 |
jarVersions.put(new Long(136198), "parser.jar from jakarta-ant-1.3 or 1.2");
|
|
1288 |
jarVersions.put(new Long(5537), "jaxp.jar from jakarta-ant-1.3 or 1.2");
|
|
1289 |
}
|
|
1290 |
|
|
1291 |
/** Simple PrintWriter we send output to; defaults to System.out. */
|
|
1292 |
protected PrintWriter outWriter = new PrintWriter(System.out, true);
|
|
1293 |
|
|
1294 |
/**
|
|
1295 |
* Bottleneck output: calls outWriter.println(s).
|
|
1296 |
* @param s String to print
|
|
1297 |
*/
|
|
1298 |
protected void logMsg(String s)
|
|
1299 |
{
|
|
1300 |
outWriter.println(s);
|
|
1301 |
}
|
|
1302 |
}
|