Ejemplo n.º 1
0
  /**
   * Command line runnability: checks for [-out outFilename] arg.
   *
   * <p>Command line entrypoint; Sets output and calls {@link #checkEnvironment(PrintWriter)}.
   *
   * @param args command line args
   */
  public static void main(String[] args) {
    // Default to System.out, autoflushing
    PrintWriter sendOutputTo = new PrintWriter(System.out, true);

    // Read our simplistic input args, if supplied
    for (int i = 0; i < args.length; i++) {
      if ("-out".equalsIgnoreCase(args[i])) {
        i++;

        if (i < args.length) {
          try {
            sendOutputTo = new PrintWriter(new FileWriter(args[i], true));
          } catch (Exception e) {
            System.err.println("# WARNING: -out " + args[i] + " threw " + e.toString());
          }
        } else {
          System.err.println(
              "# WARNING: -out argument should have a filename, output sent to console");
        }
      }
    }

    EnvironmentCheck app = new EnvironmentCheck();
    app.checkEnvironment(sendOutputTo);
  }
Ejemplo n.º 2
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;
  }