示例#1
0
  /**
   * Return a Node of basic debugging information from the EnvironmentCheck utility about the Java
   * environment.
   *
   * <p>Simply calls the {@link org.apache.xalan.xslt.EnvironmentCheck} utility to grab info about
   * the Java environment and CLASSPATH, etc., and then returns the resulting Node. Stylesheets can
   * then maniuplate this data or simply xsl:copy-of the Node. Note that we first attempt to load
   * the more advanced org.apache.env.Which utility by reflection; only if that fails to we still
   * use the internal version. Which is available from <a
   * href="http://xml.apache.org/commons/">http://xml.apache.org/commons/</a>.
   *
   * <p>We throw a WrappedRuntimeException in the unlikely case that reading information from the
   * environment throws us an exception. (Is this really the best thing to do?)
   *
   * @param myContext an <code>ExpressionContext</code> passed in by the extension mechanism. This
   *     must be an XPathContext.
   * @return a Node as described above.
   */
  public static Node checkEnvironment(ExpressionContext myContext) {

    Document factoryDocument;
    try {
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      factoryDocument = db.newDocument();
    } catch (ParserConfigurationException pce) {
      throw new org.apache.xml.utils.WrappedRuntimeException(pce);
    }

    Node resultNode = null;
    try {
      // First use reflection to try to load Which, which is a
      //  better version of EnvironmentCheck
      resultNode = checkEnvironmentUsingWhich(myContext, factoryDocument);

      if (null != resultNode) return resultNode;

      // If reflection failed, fallback to our internal EnvironmentCheck
      EnvironmentCheck envChecker = new EnvironmentCheck();
      Hashtable h = envChecker.getEnvironmentHash();
      resultNode = factoryDocument.createElement("checkEnvironmentExtension");
      envChecker.appendEnvironmentReport(resultNode, factoryDocument, h);
      envChecker = null;
    } catch (Exception e) {
      throw new org.apache.xml.utils.WrappedRuntimeException(e);
    }

    return resultNode;
  }