environmentcheck.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,376 行 · 第 1/4 页

JAVA
1,376
字号
   * 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 = classForName(DOM_LEVEL2_CLASS);      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 = classForName(DOM_LEVEL2WD_CLASS);        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 = classForName(DOM_LEVEL2FD_CLASS);          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  }  /**   * Report version info from SAX interfaces.    *   * 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 = classForName(SAX_VERSION2BETA_CLASSNF);      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 = classForName(SAX_VERSION2_CLASS);        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 = classForName(SAX_VERSION1_CLASS);          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());                    }      }    }  }  /**    * Worker method to load a class.     * Factor out loading classes for future use and JDK differences.     * Copied from javax.xml.*.FactoryFinder   * @param className name of class to load from    * an appropriate classLoader   * @return the class asked for   */  protected static Class classForName(String className)        throws ClassNotFoundException  {    ClassLoader classLoader = findClassLoader();    if (classLoader == null)     {      return Class.forName(className);    }     else     {      return classLoader.loadClass(className);    }  }    /**   * Worker method to figure out which ClassLoader to use.     * For JDK 1.2 and later use the context ClassLoader.    * Copied from javax.xml.*.FactoryFinder   * @return the appropriate ClassLoader   */  protected static ClassLoader findClassLoader()        throws ClassNotFoundException  {    ClassLoader classLoader = null;    Method m = null;    try     {      m = Thread.class.getMethod("getContextClassLoader", null);    }     catch (NoSuchMethodException e)     {      // Assume that we are running JDK 1.1, use the current ClassLoader      return EnvironmentCheck.class.getClassLoader();    }    try     {      return (ClassLoader) m.invoke(Thread.currentThread(), null);    }     catch (Exception e)     {      throw new RuntimeException(e.toString());    }  }  /**    * 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 #getApparentVersion(String, long)   */  protected static Hashtable jarVersions = new Hashtable();  /**    * Static initializer for jarVersions table.     * Doing this just once saves time and space.   *   * @see #getApparentVersion(String, long)   */  static   {    // Note: hackish Hashtable, this could use improvement    jarVersions.put(new Long(857192), "xalan.jar from xalan-j_1_1");    jarVersions.put(new Long(440237), "xalan.jar from xalan-j_1_2");    jarVersions.put(new Long(436094), "xalan.jar from xalan-j_1_2_1");    jarVersions.put(new Long(426249), "xalan.jar from xalan-j_1_2_2");    jarVersions.put(new Long(702536), "xalan.jar from xalan-j_2_0_0");    jarVersions.put(new Long(720930), "xalan.jar from xalan-j_2_0_1");    jarVersions.put(new Long(732330), "xalan.jar from xalan-j_2_1_0");    jarVersions.put(new Long(872241), "xalan.jar from xalan-j_2_2_D10");    jarVersions.put(new Long(882739), "xalan.jar from xalan-j_2_2_D11");    jarVersions.put(new Long(923866), "xalan.jar from xalan-j_2_2_0");    jarVersions.put(new Long(905872), "xalan.jar from xalan-j_2_3_D1");    jarVersions.put(new Long(906122), "xalan.jar from xalan-j_2_3_0");    jarVersions.put(new Long(906248), "xalan.jar from xalan-j_2_3_1");    jarVersions.put(new Long(983377), "xalan.jar from xalan-j_2_4_D1");        jarVersions.put(new Long(997276), "xalan.jar from xalan-j_2_4_0");        jarVersions.put(new Long(857171), "xalan.jar from lotusxsl-j_1_0_1");    jarVersions.put(new Long(802165), "xalan.jar from lotusxsl-j_2_0_0");    jarVersions.put(new Long(857692), "xalan.jar from lotusxsl-j_2_2");    jarVersions.put(new Long(906359), "xalan.jar from lotusxsl-j_2_3_1");    jarVersions.put(new Long(857692), "xalan.jar from lotusxsl-j_2_3_2");    jarVersions.put(new Long(1201514), "xalan.jar from lotusxsl-j_2_3_3");    jarVersions.put(new Long(1201599), "xalan.jar from lotusxsl-j_2_3_4");    jarVersions.put(new Long(1201641), "xalan.jar from lotusxsl-j_2_3_5");        jarVersions.put(new Long(596540), "xsltc.jar from xalan-j_2_2_0");    jarVersions.put(new Long(590247), "xsltc.jar from xalan-j_2_3_D1");    jarVersions.put(new Long(589914), "xsltc.jar from xalan-j_2_3_0");    jarVersions.put(new Long(589915), "xsltc.jar from xalan-j_2_3_1");    jarVersions.put(new Long(1306667), "xsltc.jar from xalan-j_2_4_D1");         jarVersions.put(new Long(1328227), "xsltc.jar from xalan-j_2_4_0");    jarVersions.put(new Long(1268634), "xsltc.jar-bundled from xalan-j_2_3_0");    jarVersions.put(new Long(100196), "xml-apis.jar from xalan-j_2_2_0 or xalan-j_2_3_D1");    jarVersions.put(new Long(108484), "xml-apis.jar from xalan-j_2_3_0, or xalan-j_2_3_1 from xml-commons-1.0.b2");    jarVersions.put(new Long(109049), "xml-apis.jar from xalan-j_2_4_0 from xml-commons RIVERCOURT1 branch");    jarVersions.put(new Long(109049), "xml-apis.jar from xalan-j_2_4_0, lotusxsl-j_2_3_2 or lotusxsl-j_2_3_3 from xml-commons RIVERCOURT1");    jarVersions.put(new Long(113749), "xml-apis.jar from xalan-j_2_4_1, lotusxsl-j_2_3_4 or lotusxsl-j_2_3_5 from factoryfinder-build of xml-commons RIVERCOURT1");    // If the below were more common I would update it to report     //  errors better; but this is so old hardly anyone has it    jarVersions.put(new Long(424490), "xalan.jar from Xerces Tools releases - ERROR:DO NOT USE!");    jarVersions.put(new Long(1591855), "xerces.jar from xalan-j_1_1 from xerces-1...");    jarVersions.put(new Long(1498679), "xerces.jar from xalan-j_1_2 from xerces-1_2_0.bin");    jarVersions.put(new Long(1484896), "xerces.jar from xalan-j_1_2_1 from xerces-1_2_1.bin");    jarVersions.put(new Long(804460),  "xerces.jar from xalan-j_1_2_2 from xerces-1_2_2.bin");    jarVersions.put(new Long(1499244), "xerces.jar from xalan-j_2_0_0 from xerces-1_2_3.bin");    jarVersions.put(new Long(1605266), "xerces.jar from xalan-j_2_0_1 from xerces-1_3_0.bin");    jarVersions.put(new Long(904030), "xerces.jar from xalan-j_2_1_0 from xerces-1_4.bin");    jarVersions.put(new Long(1190776), "xerces.jar from lotusxsl_1_0_1 apparently-from xerces-1_0_3.bin");    jarVersions.put(new Long(1489400), "xerces.jar from lotusxsl-j_2_0_0 from XML4J-3_1_1");    jarVersions.put(new Long(1787796), "xerces.jar from lotusxsl-j_2_2 or xerces-1_4_1.bin");    jarVersions.put(new Long(904030), "xerces.jar from xerces-1_4_0.bin");    jarVersions.put(new Long(1802885), "xerces.jar from xerces-1_4_2.bin");    jarVersions.put(new Long(1734594), "xerces.jar from Xerces-J-bin.2.0.0.beta3");    jarVersions.put(new Long(1808883), "xerces.jar from xalan-j_2_2_D10,D11,D12 or xerces-1_4_3.bin");    jarVersions.put(new Long(1803877), "xerces.jar from XML4J-3_2_1");    jarVersions.put(new Long(1812019), "xerces.jar from xalan-j_2_2_0");    jarVersions.put(new Long(1720292), "xercesImpl.jar from xalan-j_2_3_D1");    jarVersions.put(new Long(1730053), "xercesImpl.jar from xalan-j_2_3_0 or xalan-j_2_3_1 from xerces-2_0_0");    jarVersions.put(new Long(1728861), "xercesImpl.jar from xalan-j_2_4_D1 from xerces-2_0_1");        jarVersions.put(new Long(972027), "xercesImpl.jar from xalan-j_2_4_0 from xerces-2_1");    jarVersions.put(new Long(831587), "xercesImpl.jar from xalan-j_2_4_1 from xerces-2_2");        jarVersions.put(new Long(1729063), "xercesImpl.jar from lotusxsl-j_2_3_1 from XML4J-4_0_0");    jarVersions.put(new Long(1738551), "xercesImpl.jar from lotusxsl-j_2_3_2 from XML4J-4_0_2");    jarVersions.put(new Long(3243826), "xercesImpl.jar from lotusxsl-j_2_3_3 from XML4J-4_0_5");    jarVersions.put(new Long(1171789), "xercesImpl.jar from lotusxsl-j_2_3_4 from XML4J-4_0_6");    jarVersions.put(new Long(1174955), "xercesImpl.jar from lotusxsl-j_2_3_5 from XML4J-4_0_8");    jarVersions.put(new Long(1173922), "xercesImpl.jar from lotusxsl-j_2_3_6 from XML4J-4_0_9");    jarVersions.put(new Long(831828), "xercesImpl.jar from lotusxsl-j_2_4_0 from XML4J-4_1_1");    jarVersions.put(new Long(37485), "xalanj1compat.jar from xalan-j_2_0_0");    jarVersions.put(new Long(38100), "xalanj1compat.jar from xalan-j_2_0_1");    jarVersions.put(new Long(18779), "xalanservlet.jar from xalan-j_2_0_0");    jarVersions.put(new Long(21453), "xalanservlet.jar from xalan-j_2_0_1");    jarVersions.put(new Long(24826), "xalanservlet.jar from xalan-j_2_3_1 or xalan-j_2_4_1 or lotusxsl-j_2_3_1 to lotusxsl-j-2_3_5");        jarVersions.put(new Long(24831), "xalanservlet.jar from xalan-j_2_4_1");    // For those who've downloaded JAXP from sun    jarVersions.put(new Long(5618), "jaxp.jar from jaxp1.0.1");    jarVersions.put(new Long(136133), "parser.jar from jaxp1.0.1");    jarVersions.put(new Long(28404), "jaxp.jar from jaxp-1.1");    jarVersions.put(new Long(187162), "crimson.jar from jaxp-1.1");    jarVersions.put(new Long(801714), "xalan.jar from jaxp-1.1");    jarVersions.put(new Long(196399), "crimson.jar from crimson-1.1.1");    jarVersions.put(new Long(33323), "jaxp.jar from crimson-1.1.1 or jakarta-ant-1.4.1b1");    jarVersions.put(new Long(152717), "crimson.jar from crimson-1.1.2beta2");    jarVersions.put(new Long(88143), "xml-apis.jar from crimson-1.1.2beta2");    jarVersions.put(new Long(206384), "crimson.jar from crimson-1.1.3 or jakarta-ant-1.4.1b1");    // jakarta-ant: since many people use ant these days    jarVersions.put(new Long(136198), "parser.jar from jakarta-ant-1.3 or 1.2");    jarVersions.put(new Long(5537), "jaxp.jar from jakarta-ant-1.3 or 1.2");    // Various LotusXSL versions, which are based on Xalan code     //  (LotusXSL was donated by Lotus to Apache to become Xalan)    jarVersions.put(new Long(120274), "lotusxsl.jar from lotusxsl-0_16_4");    jarVersions.put(new Long(120293), "lotusxsl.jar from lotusxsl-0_16_5");    jarVersions.put(new Long(283777), "lotusxsl.jar from lotusxsl-0_17_2");    jarVersions.put(new Long(305577), "lotusxsl.jar from lotusxsl-0_17_3");    jarVersions.put(new Long(304500), "lotusxsl.jar from lotusxsl-0_17_4");    jarVersions.put(new Long(714959), "lotusxsl.jar from lotusxsl-0_18_1");    jarVersions.put(new Long(717674), "lotusxsl.jar from lotusxsl-0_18_2");    jarVersions.put(new Long(752343), "lotusxsl.jar from lotusxsl-0_18_3");    jarVersions.put(new Long(907101), "lotusxsl.jar from lotusxsl-0_18_4");  }  /** Simple PrintWriter we send output to; defaults to System.out.  */  protected PrintWriter outWriter = new PrintWriter(System.out, true);  /**   * Bottleneck output: calls outWriter.println(s).     * @param s String to print   */  protected void logMsg(String s)  {    outWriter.println(s);  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?