Exemple #1
0
  /**
   * Private worker method to attempt to use org.apache.env.Which.
   *
   * @param myContext an <code>ExpressionContext</code> passed in by the extension mechanism. This
   *     must be an XPathContext.
   * @param factoryDocument providing createElement services, etc.
   * @return a Node with environment info; null if any error
   */
  private static Node checkEnvironmentUsingWhich(
      ExpressionContext myContext, Document factoryDocument) {
    final String WHICH_CLASSNAME = "org.apache.env.Which";
    final String WHICH_METHODNAME = "which";
    final Class WHICH_METHOD_ARGS[] = {
      java.util.Hashtable.class, java.lang.String.class, java.lang.String.class
    };
    try {
      // Use reflection to try to find xml-commons utility 'Which'
      Class clazz =
          ObjectFactory.findProviderClass(WHICH_CLASSNAME, ObjectFactory.findClassLoader(), true);
      if (null == clazz) return null;

      // Fully qualify names since this is the only method they're used in
      java.lang.reflect.Method method = clazz.getMethod(WHICH_METHODNAME, WHICH_METHOD_ARGS);
      Hashtable report = new Hashtable();

      // Call the method with our Hashtable, common options, and ignore return value
      Object[] methodArgs = {report, "XmlCommons;Xalan;Xerces;Crimson;Ant", ""};
      Object returnValue = method.invoke(null, methodArgs);

      // Create a parent to hold the report and append hash to it
      Node resultNode = factoryDocument.createElement("checkEnvironmentExtension");
      org.apache.xml.utils.Hashtree2Node.appendHashToNode(
          report, "whichReport", resultNode, factoryDocument);

      return resultNode;
    } catch (Throwable t) {
      // Simply return null; no need to report error
      return null;
    }
  }