Example #1
0
  /**
   * Report version information about JAXP interfaces.
   *
   * <p>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.
   *
   * @param h Hashtable to put information in
   */
  protected void checkJAXPVersion(Hashtable h) {

    if (null == h) h = new Hashtable();

    final Class noArgs[] = new Class[0];
    Class clazz = null;

    try {
      final String JAXP1_CLASS = "javax.xml.parsers.DocumentBuilder";
      final String JAXP11_METHOD = "getDOMImplementation";

      clazz = ObjectFactory.findProviderClass(JAXP1_CLASS, ObjectFactory.findClassLoader(), true);

      Method method = clazz.getMethod(JAXP11_METHOD, noArgs);

      // If we succeeded, we at least have JAXP 1.1 available
      h.put(VERSION + "JAXP", "1.1 or higher");
    } catch (Exception e) {
      if (null != clazz) {

        // We must have found the class itself, just not the
        //  method, so we (probably) have JAXP 1.0.1
        h.put(ERROR + VERSION + "JAXP", "1.0.1");
        h.put(ERROR, ERROR_FOUND);
      } else {
        // We couldn't even find the class, and don't have
        //  any JAXP support at all, or only have the
        //  transform half of it
        h.put(ERROR + VERSION + "JAXP", CLASS_NOTPRESENT);
        h.put(ERROR, ERROR_FOUND);
      }
    }
  }
Example #2
0
  /**
   * Report product version information from Ant.
   *
   * @param h Hashtable to put information in
   */
  protected void checkAntVersion(Hashtable h) {

    if (null == h) h = new Hashtable();

    try {
      final String ANT_VERSION_CLASS = "org.apache.tools.ant.Main";
      final String ANT_VERSION_METHOD = "getAntVersion"; // noArgs
      final Class noArgs[] = new Class[0];

      Class clazz =
          ObjectFactory.findProviderClass(ANT_VERSION_CLASS, ObjectFactory.findClassLoader(), true);

      Method method = clazz.getMethod(ANT_VERSION_METHOD, noArgs);
      Object returnValue = method.invoke(null, new Object[0]);

      h.put(VERSION + "ant", (String) returnValue);
    } catch (Exception e) {
      h.put(VERSION + "ant", CLASS_NOTPRESENT);
    }
  }
Example #3
0
  /**
   * Report version info from DOM interfaces.
   *
   * <p>Currently distinguishes between pre-DOM level 2, the DOM level 2 working draft, the DOM
   * level 2 final draft, and not found.
   *
   * @param h Hashtable to put information in
   */
  protected void checkDOMVersion(Hashtable h) {

    if (null == h) h = new Hashtable();

    final String DOM_LEVEL2_CLASS = "org.w3c.dom.Document";
    final String DOM_LEVEL2_METHOD = "createElementNS"; // String, String
    final String DOM_LEVEL2WD_CLASS = "org.w3c.dom.Node";
    final String DOM_LEVEL2WD_METHOD = "supported"; // String, String
    final String DOM_LEVEL2FD_CLASS = "org.w3c.dom.Node";
    final String DOM_LEVEL2FD_METHOD = "isSupported"; // String, String
    final Class twoStringArgs[] = {java.lang.String.class, java.lang.String.class};

    try {
      Class clazz =
          ObjectFactory.findProviderClass(DOM_LEVEL2_CLASS, ObjectFactory.findClassLoader(), true);

      Method method = clazz.getMethod(DOM_LEVEL2_METHOD, twoStringArgs);

      // If we succeeded, we have loaded interfaces from a
      //  level 2 DOM somewhere
      h.put(VERSION + "DOM", "2.0");

      try {
        // Check for the working draft version, which is
        //  commonly found, but won't work anymore
        clazz =
            ObjectFactory.findProviderClass(
                DOM_LEVEL2WD_CLASS, ObjectFactory.findClassLoader(), true);

        method = clazz.getMethod(DOM_LEVEL2WD_METHOD, twoStringArgs);

        h.put(ERROR + VERSION + "DOM.draftlevel", "2.0wd");
        h.put(ERROR, ERROR_FOUND);
      } catch (Exception e2) {
        try {
          // Check for the final draft version as well
          clazz =
              ObjectFactory.findProviderClass(
                  DOM_LEVEL2FD_CLASS, ObjectFactory.findClassLoader(), true);

          method = clazz.getMethod(DOM_LEVEL2FD_METHOD, twoStringArgs);

          h.put(VERSION + "DOM.draftlevel", "2.0fd");
        } catch (Exception e3) {
          h.put(ERROR + VERSION + "DOM.draftlevel", "2.0unknown");
          h.put(ERROR, ERROR_FOUND);
        }
      }
    } catch (Exception e) {
      h.put(ERROR + VERSION + "DOM", "ERROR attempting to load DOM level 2 class: " + e.toString());
      h.put(ERROR, ERROR_FOUND);
    }

    // @todo load an actual DOM implmementation and query it as well
    // @todo load an actual DOM implmementation and check if
    //  isNamespaceAware() == true, which is needed to parse
    //  xsl stylesheet files into a DOM
  }
Example #4
0
  /**
   * Report product version information from common parsers.
   *
   * <p>Looks for version info in xerces.jar/xercesImpl.jar/crimson.jar.
   *
   * <p>//@todo actually look up version info in crimson manifest
   *
   * @param h Hashtable to put information in
   */
  protected void checkParserVersion(Hashtable h) {

    if (null == h) h = new Hashtable();

    try {
      final String XERCES1_VERSION_CLASS = "org.apache.xerces.framework.Version";

      Class clazz =
          ObjectFactory.findProviderClass(
              XERCES1_VERSION_CLASS, ObjectFactory.findClassLoader(), true);

      // Found Xerces-J 1.x, grab it's version fields
      Field f = clazz.getField("fVersion");
      String parserVersion = (String) f.get(null);

      h.put(VERSION + "xerces1", parserVersion);
    } catch (Exception e) {
      h.put(VERSION + "xerces1", CLASS_NOTPRESENT);
    }

    // Look for xerces1 and xerces2 parsers separately
    try {
      final String XERCES2_VERSION_CLASS = "org.apache.xerces.impl.Version";

      Class clazz =
          ObjectFactory.findProviderClass(
              XERCES2_VERSION_CLASS, ObjectFactory.findClassLoader(), true);

      // Found Xerces-J 2.x, grab it's version fields
      Field f = clazz.getField("fVersion");
      String parserVersion = (String) f.get(null);

      h.put(VERSION + "xerces2", parserVersion);
    } catch (Exception e) {
      h.put(VERSION + "xerces2", CLASS_NOTPRESENT);
    }

    try {
      final String CRIMSON_CLASS = "org.apache.crimson.parser.Parser2";

      Class clazz =
          ObjectFactory.findProviderClass(CRIMSON_CLASS, ObjectFactory.findClassLoader(), true);

      // @todo determine specific crimson version
      h.put(VERSION + "crimson", CLASS_PRESENT);
    } catch (Exception e) {
      h.put(VERSION + "crimson", CLASS_NOTPRESENT);
    }
  }
Example #5
0
  /**
   * Report version info from SAX interfaces.
   *
   * <p>Currently distinguishes between SAX 2, SAX 2.0beta2, SAX1, and not found.
   *
   * @param h Hashtable to put information in
   */
  protected void checkSAXVersion(Hashtable h) {

    if (null == h) h = new Hashtable();

    final String SAX_VERSION1_CLASS = "org.xml.sax.Parser";
    final String SAX_VERSION1_METHOD = "parse"; // String
    final String SAX_VERSION2_CLASS = "org.xml.sax.XMLReader";
    final String SAX_VERSION2_METHOD = "parse"; // String
    final String SAX_VERSION2BETA_CLASSNF = "org.xml.sax.helpers.AttributesImpl";
    final String SAX_VERSION2BETA_METHODNF = "setAttributes"; // Attributes
    final Class oneStringArg[] = {java.lang.String.class};
    // Note this introduces a minor compile dependency on SAX...
    final Class attributesArg[] = {org.xml.sax.Attributes.class};

    try {
      // This method was only added in the final SAX 2.0 release;
      //  see changes.html "Changes from SAX 2.0beta2 to SAX 2.0prerelease"
      Class clazz =
          ObjectFactory.findProviderClass(
              SAX_VERSION2BETA_CLASSNF, ObjectFactory.findClassLoader(), true);

      Method method = clazz.getMethod(SAX_VERSION2BETA_METHODNF, attributesArg);

      // If we succeeded, we have loaded interfaces from a
      //  real, final SAX version 2.0 somewhere
      h.put(VERSION + "SAX", "2.0");
    } catch (Exception e) {
      // If we didn't find the SAX 2.0 class, look for a 2.0beta2
      h.put(
          ERROR + VERSION + "SAX", "ERROR attempting to load SAX version 2 class: " + e.toString());
      h.put(ERROR, ERROR_FOUND);

      try {
        Class clazz =
            ObjectFactory.findProviderClass(
                SAX_VERSION2_CLASS, ObjectFactory.findClassLoader(), true);

        Method method = clazz.getMethod(SAX_VERSION2_METHOD, oneStringArg);

        // If we succeeded, we have loaded interfaces from a
        //  SAX version 2.0beta2 or earlier; these might work but
        //  you should really have the final SAX 2.0
        h.put(VERSION + "SAX-backlevel", "2.0beta2-or-earlier");
      } catch (Exception e2) {
        // If we didn't find the SAX 2.0beta2 class, look for a 1.0 one
        h.put(
            ERROR + VERSION + "SAX",
            "ERROR attempting to load SAX version 2 class: " + e.toString());
        h.put(ERROR, ERROR_FOUND);

        try {
          Class clazz =
              ObjectFactory.findProviderClass(
                  SAX_VERSION1_CLASS, ObjectFactory.findClassLoader(), true);

          Method method = clazz.getMethod(SAX_VERSION1_METHOD, oneStringArg);

          // If we succeeded, we have loaded interfaces from a
          //  SAX version 1.0 somewhere; which won't work very
          //  well for JAXP 1.1 or beyond!
          h.put(VERSION + "SAX-backlevel", "1.0");
        } catch (Exception e3) {
          // If we didn't find the SAX 2.0 class, look for a 1.0 one
          // Note that either 1.0 or no SAX are both errors
          h.put(
              ERROR + VERSION + "SAX-backlevel",
              "ERROR attempting to load SAX version 1 class: " + e3.toString());
        }
      }
    }
  }
Example #6
0
  /**
   * Report product version information from Xalan-J.
   *
   * <p>Looks for version info in xalan.jar from Xalan-J products.
   *
   * @param h Hashtable to put information in
   */
  protected void checkProcessorVersion(Hashtable h) {

    if (null == h) h = new Hashtable();

    try {
      final String XALAN1_VERSION_CLASS = "org.apache.xalan.xslt.XSLProcessorVersion";

      Class clazz =
          ObjectFactory.findProviderClass(
              XALAN1_VERSION_CLASS, ObjectFactory.findClassLoader(), true);

      // Found Xalan-J 1.x, grab it's version fields
      StringBuffer buf = new StringBuffer();
      Field f = clazz.getField("PRODUCT");

      buf.append(f.get(null));
      buf.append(';');

      f = clazz.getField("LANGUAGE");

      buf.append(f.get(null));
      buf.append(';');

      f = clazz.getField("S_VERSION");

      buf.append(f.get(null));
      buf.append(';');
      h.put(VERSION + "xalan1", buf.toString());
    } catch (Exception e1) {
      h.put(VERSION + "xalan1", CLASS_NOTPRESENT);
    }

    try {
      // NOTE: This is the old Xalan 2.0, 2.1, 2.2 version class,
      //    is being replaced by class below
      final String XALAN2_VERSION_CLASS = "org.apache.xalan.processor.XSLProcessorVersion";

      Class clazz =
          ObjectFactory.findProviderClass(
              XALAN2_VERSION_CLASS, ObjectFactory.findClassLoader(), true);

      // Found Xalan-J 2.x, grab it's version fields
      StringBuffer buf = new StringBuffer();
      Field f = clazz.getField("S_VERSION");
      buf.append(f.get(null));

      h.put(VERSION + "xalan2x", buf.toString());
    } catch (Exception e2) {
      h.put(VERSION + "xalan2x", CLASS_NOTPRESENT);
    }
    try {
      // NOTE: This is the new Xalan 2.2+ version class
      final String XALAN2_2_VERSION_CLASS = "org.apache.xalan.Version";
      final String XALAN2_2_VERSION_METHOD = "getVersion";
      final Class noArgs[] = new Class[0];

      Class clazz =
          ObjectFactory.findProviderClass(
              XALAN2_2_VERSION_CLASS, ObjectFactory.findClassLoader(), true);

      Method method = clazz.getMethod(XALAN2_2_VERSION_METHOD, noArgs);
      Object returnValue = method.invoke(null, new Object[0]);

      h.put(VERSION + "xalan2_2", (String) returnValue);
    } catch (Exception e2) {
      h.put(VERSION + "xalan2_2", CLASS_NOTPRESENT);
    }
  }