org.apache.xalan.xslt
Class EnvironmentCheck

java.lang.Object
  extended byorg.apache.xalan.xslt.EnvironmentCheck

public class EnvironmentCheck
extends Object

Utility class to report simple information about the environment. Simplistic reporting about certain classes found in your JVM may help answer some FAQs for simple problems.

Usage-command line: java org.apache.xalan.xslt.EnvironmentCheck [-out outFile]

Usage-from program: boolean environmentOK = (new EnvironmentCheck()).checkEnvironment(yourPrintWriter);

Usage-from stylesheet:

    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
        xmlns:xalan="http://xml.apache.org/xalan"
        exclude-result-prefixes="xalan">
    <xsl:output indent="yes"/>
    <xsl:template match="/">
      <xsl:copy-of select="xalan:checkEnvironment()"/>
    </xsl:template>
    </xsl:stylesheet>
 

Xalan users reporting problems are encouraged to use this class to see if there are potential problems with their actual Java environment before reporting a bug. Note that you should both check from the JVM/JRE's command line as well as temporarily calling checkEnvironment() directly from your code, since the classpath may differ (especially for servlets, etc).

Also see http://xml.apache.org/xalan-j/faq.html

Note: This class is pretty simplistic: it does a fairly simple unordered search of the classpath; it only uses Class.forName() to load things, not actually querying the classloader; so the results are not necessarily definitive nor will it find all problems related to environment setup. Also, you should avoid calling this in deployed production code, both because it is quite slow and because it forces classes to get loaded.

Note: This class explicitly has very limited compile-time dependencies to enable easy compilation and usage even when Xalan, DOM/SAX/JAXP, etc. are not present.

Note: for an improved version of this utility, please see the xml-commons' project Which utility which does the same kind of thing but in a much simpler manner.

Author:
Shane_Curcuru@us.ibm.com

Field Summary
static String CLASS_NOTPRESENT
          Marker that a class or .jar was not found.
static String CLASS_PRESENT
          Marker that a class or .jar was found.
static String ERROR
          Prefixed to hash keys that signify serious problems.
static String ERROR_FOUND
          Value for any error found.
static String FOUNDCLASSES
          Prefixed to hash keys that signify .jars found in classpath.
 String[] jarNames
          Listing of common .jar files that include Xalan-related classes.
protected static Hashtable jarVersions
          Manual table of known .jar sizes.
protected  PrintWriter outWriter
          Simple PrintWriter we send output to; defaults to System.out.
static String VERSION
          Prefixed to hash keys that signify version numbers.
static String WARNING
          Added to descriptions that signify potential problems.
 
Constructor Summary
EnvironmentCheck()
           
 
Method Summary
 void appendEnvironmentReport(org.w3c.dom.Node container, org.w3c.dom.Document factory, Hashtable h)
          Stylesheet extension entrypoint: Dump a basic Xalan environment report from getEnvironmentHash() to a Node.
protected  boolean appendFoundJars(org.w3c.dom.Node container, org.w3c.dom.Document factory, Vector v, String desc)
          Print out report of .jars found in a classpath.
protected  void checkAntVersion(Hashtable h)
          Report product version information from Ant.
protected  void checkDOMVersion(Hashtable h)
          Report version info from DOM interfaces.
 boolean checkEnvironment(PrintWriter pw)
          Programmatic entrypoint: Report on basic Java environment and CLASSPATH settings that affect Xalan.
protected  void checkJAXPVersion(Hashtable h)
          Report version information about JAXP interfaces.
protected  void checkParserVersion(Hashtable h)
          Report product version information from common parsers.
protected  Vector checkPathForJars(String cp, String[] jars)
          Cheap-o listing of specified .jars found in the classpath.
protected  void checkProcessorVersion(Hashtable h)
          Report product version information from Xalan-J.
protected  void checkSAXVersion(Hashtable h)
          Report version info from SAX interfaces.
protected  void checkSystemProperties(Hashtable h)
          Fillin hash with info about SystemProperties.
protected static Class classForName(String className)
          Worker method to load a class.
protected static ClassLoader findClassLoader()
          Worker method to figure out which ClassLoader to use.
protected  String getApparentVersion(String jarName, long jarSize)
          Cheap-o method to determine the product version of a .jar.
 Hashtable getEnvironmentHash()
          Fill a hash with basic environment settings that affect Xalan.
protected  boolean logFoundJars(Vector v, String desc)
          Print out report of .jars found in a classpath.
protected  void logMsg(String s)
          Bottleneck output: calls outWriter.println(s).
static void main(String[] args)
          Command line runnability: checks for [-out outFilename] arg.
protected  boolean writeEnvironmentReport(Hashtable h)
          Dump a basic Xalan environment report to outWriter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR

public static final String ERROR
Prefixed to hash keys that signify serious problems.

See Also:
Constant Field Values

WARNING

public static final String WARNING
Added to descriptions that signify potential problems.

See Also:
Constant Field Values

ERROR_FOUND

public static final String ERROR_FOUND
Value for any error found.

See Also:
Constant Field Values

VERSION

public static final String VERSION
Prefixed to hash keys that signify version numbers.

See Also:
Constant Field Values

FOUNDCLASSES

public static final String FOUNDCLASSES
Prefixed to hash keys that signify .jars found in classpath.

See Also:
Constant Field Values

CLASS_PRESENT

public static final String CLASS_PRESENT
Marker that a class or .jar was found.

See Also:
Constant Field Values

CLASS_NOTPRESENT

public static final String CLASS_NOTPRESENT
Marker that a class or .jar was not found.

See Also:
Constant Field Values

jarNames

public String[] jarNames
Listing of common .jar files that include Xalan-related classes.


jarVersions

protected static Hashtable jarVersions
Manual table of known .jar sizes. Only includes shipped versions of certain projects. key=jarsize, value=jarname ' from ' distro name Note assumption: two jars cannot have the same size!

See Also:
getApparentVersion(String, long)

outWriter

protected PrintWriter outWriter
Simple PrintWriter we send output to; defaults to System.out.

Constructor Detail

EnvironmentCheck

public EnvironmentCheck()
Method Detail

main

public static void main(String[] args)
Command line runnability: checks for [-out outFilename] arg.

Command line entrypoint; Sets output and calls checkEnvironment(PrintWriter).

Parameters:
args - command line args

checkEnvironment

public boolean checkEnvironment(PrintWriter pw)
Programmatic entrypoint: Report on basic Java environment and CLASSPATH settings that affect Xalan.

Note that this class is not advanced enough to tell you everything about the environment that affects Xalan, and sometimes reports errors that will not actually affect Xalan's behavior. Currently, it very simplistically checks the JVM's environment for some basic properties and logs them out; it will report a problem if it finds a setting or .jar file that is likely to cause problems.

Advanced users can peruse the code herein to help them investigate potential environment problems found; other users may simply send the output from this tool along with any bugs they submit to help us in the debugging process.

Parameters:
pw - PrintWriter to send output to; can be sent to a file that will look similar to a Properties file; defaults to System.out if null
Returns:
true if your environment appears to have no major problems; false if potential environment problems found
See Also:
getEnvironmentHash()

getEnvironmentHash

public Hashtable getEnvironmentHash()
Fill a hash with basic environment settings that affect Xalan.

Worker method called from various places.

Various system and CLASSPATH, etc. properties are put into the hash as keys with a brief description of the current state of that item as the value. Any serious problems will be put in with a key that is prefixed with 'ERROR.' so it stands out in any resulting report; also a key with just that constant will be set as well for any error.

Note that some legitimate cases are flaged as potential errors - namely when a developer recompiles xalan.jar on their own - and even a non-error state doesn't guaruntee that everything in the environment is correct. But this will help point out the most common classpath and system property problems that we've seen.

Returns:
Hashtable full of useful environment info about Xalan and related system properties, etc.

writeEnvironmentReport

protected boolean writeEnvironmentReport(Hashtable h)
Dump a basic Xalan environment report to outWriter.

This dumps a simple header and then each of the entries in the Hashtable to our PrintWriter; it does special processing for entries that are .jars found in the classpath.

Parameters:
h - Hashtable of items to report on; presumably filled in by our various check*() methods
Returns:
true if your environment appears to have no major problems; false if potential environment problems found
See Also:
for an equivalent that appends to a Node instead

logFoundJars

protected boolean logFoundJars(Vector v,
                               String desc)
Print out report of .jars found in a classpath. Takes the information encoded from a checkPathForJars() call and dumps it out to our PrintWriter.

Parameters:
v - Vector of Hashtables of .jar file info
desc - description to print out in header
Returns:
false if OK, true if any .jars were reported as having errors
See Also:
checkPathForJars(String, String[])

appendEnvironmentReport

public void appendEnvironmentReport(org.w3c.dom.Node container,
                                    org.w3c.dom.Document factory,
                                    Hashtable h)
Stylesheet extension entrypoint: Dump a basic Xalan environment report from getEnvironmentHash() to a Node.

Copy of writeEnvironmentReport that creates a Node suitable for other processing instead of a properties-like text output.

Parameters:
container - Node to append our report to
factory - Document providing createElement, etc. services
h - Hash presumably from getEnvironmentHash()
See Also:
for an equivalent that writes to a PrintWriter instead

appendFoundJars

protected boolean appendFoundJars(org.w3c.dom.Node container,
                                  org.w3c.dom.Document factory,
                                  Vector v,
                                  String desc)
Print out report of .jars found in a classpath. Takes the information encoded from a checkPathForJars() call and dumps it out to our PrintWriter.

Parameters:
container - Node to append our report to
factory - Document providing createElement, etc. services
v - Vector of Hashtables of .jar file info
desc - description to print out in header
Returns:
false if OK, true if any .jars were reported as having errors
See Also:
checkPathForJars(String, String[])

checkSystemProperties

protected void checkSystemProperties(Hashtable h)
Fillin hash with info about SystemProperties. Logs java.class.path and other likely paths; then attempts to search those paths for .jar files with Xalan-related classes. //@todo NOTE: We don't actually search java.ext.dirs for // *.jar files therein! This should be updated

Parameters:
h - Hashtable to put information in
See Also:
jarNames, checkPathForJars(String, String[])

checkPathForJars

protected Vector checkPathForJars(String cp,
                                  String[] jars)
Cheap-o listing of specified .jars found in the classpath. cp should be separated by the usual File.pathSeparator. We then do a simplistic search of the path for any requested .jar filenames, and return a listing of their names and where (apparently) they came from.

Parameters:
cp - classpath to search
jars - array of .jar base filenames to look for
Returns:
Vector of Hashtables filled with info about found .jars
See Also:
jarNames, logFoundJars(Vector, String), appendFoundJars(Node, Document, Vector, String ), getApparentVersion(String, long)

getApparentVersion

protected String getApparentVersion(String jarName,
                                    long jarSize)
Cheap-o method to determine the product version of a .jar. Currently does a lookup into a local table of some recent shipped Xalan builds to determine where the .jar probably came from. Note that if you recompile Xalan or Xerces yourself this will likely report a potential error, since we can't certify builds other than the ones we ship. Only reports against selected posted Xalan-J builds. //@todo actually look up version info in manifests

Parameters:
jarName - base filename of the .jarfile
jarSize - size of the .jarfile
Returns:
String describing where the .jar file probably came from

checkJAXPVersion

protected void checkJAXPVersion(Hashtable h)
Report version information about JAXP interfaces. Currently distinguishes between JAXP 1.0.1 and JAXP 1.1, and not found; only tests the interfaces, and does not check for reference implementation versions.

Parameters:
h - Hashtable to put information in

checkProcessorVersion

protected void checkProcessorVersion(Hashtable h)
Report product version information from Xalan-J. Looks for version info in xalan.jar from Xalan-J products.

Parameters:
h - Hashtable to put information in

checkParserVersion

protected void checkParserVersion(Hashtable h)
Report product version information from common parsers. Looks for version info in xerces.jar/xercesImpl.jar/crimson.jar. //@todo actually look up version info in crimson manifest

Parameters:
h - Hashtable to put information in

checkAntVersion

protected void checkAntVersion(Hashtable h)
Report product version information from Ant.

Parameters:
h - Hashtable to put information in

checkDOMVersion

protected void checkDOMVersion(Hashtable h)
Report version info from DOM interfaces. Currently distinguishes between pre-DOM level 2, the DOM level 2 working draft, the DOM level 2 final draft, and not found.

Parameters:
h - Hashtable to put information in

checkSAXVersion

protected void checkSAXVersion(Hashtable h)
Report version info from SAX interfaces. Currently distinguishes between SAX 2, SAX 2.0beta2, SAX1, and not found.

Parameters:
h - Hashtable to put information in

classForName

protected static Class classForName(String className)
                             throws ClassNotFoundException
Worker method to load a class. Factor out loading classes for future use and JDK differences. Copied from javax.xml.*.FactoryFinder

Parameters:
className - name of class to load from an appropriate classLoader
Returns:
the class asked for
Throws:
ClassNotFoundException

findClassLoader

protected static ClassLoader findClassLoader()
                                      throws ClassNotFoundException
Worker method to figure out which ClassLoader to use. For JDK 1.2 and later use the context ClassLoader. Copied from javax.xml.*.FactoryFinder

Returns:
the appropriate ClassLoader
Throws:
ClassNotFoundException

logMsg

protected void logMsg(String s)
Bottleneck output: calls outWriter.println(s).

Parameters:
s - String to print