⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 environmentcheck.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            for (Enumeration keys = h.keys();            keys.hasMoreElements();          /* no increment portion */          )      {        Object key = keys.nextElement();        String keyStr = (String) key;        try        {          // Special processing for classes found..          if (keyStr.startsWith(FOUNDCLASSES))          {            Vector v = (Vector) h.get(keyStr);            // errors |= logFoundJars(v, keyStr);            errors |= appendFoundJars(hashNode, factory, v, keyStr);          }          // ..normal processing for all other entries          else           {            // Note: we could just check for the ERROR key by itself,             //    since we now set that, but since we have to go             //    through the whole hash anyway, do it this way,            //    which is safer for maintenance            if (keyStr.startsWith(ERROR))            {              errors = true;            }            Element node = factory.createElement("item");            node.setAttribute("key", keyStr);            node.appendChild(factory.createTextNode((String)h.get(keyStr)));            hashNode.appendChild(node);          }        }        catch (Exception e)        {          errors = true;          Element node = factory.createElement("item");          node.setAttribute("key", keyStr);          node.appendChild(factory.createTextNode(ERROR + " Reading " + key + " threw: " + e.toString()));          hashNode.appendChild(node);        }      } // end of for...      Element statusNode = factory.createElement("status");      statusNode.setAttribute("result", (errors ? "ERROR" : "OK" ));      envCheckNode.appendChild(statusNode);    }    catch (Exception e2)    {      System.err.println("appendEnvironmentReport threw: " + e2.toString());      e2.printStackTrace();    }  }      /**   * Print out report of .jars found in a classpath.    *   * Takes the information encoded from a checkPathForJars()    * call and dumps it out to our PrintWriter.   *   * @param container Node to append our report to   * @param factory Document providing createElement, etc. services   * @param v Vector of Hashtables of .jar file info   * @param desc description to print out in header   *   * @return false if OK, true if any .jars were reported    * as having errors   * @see #checkPathForJars(String, String[])   */  protected boolean appendFoundJars(Node container, Document factory,         Vector v, String desc)  {    if ((null == v) || (v.size() < 1))      return false;    boolean errors = false;    for (int i = 0; i < v.size(); i++)    {      Hashtable subhash = (Hashtable) v.elementAt(i);      for (Enumeration keys = subhash.keys();            keys.hasMoreElements();           /* no increment portion */          )      {        Object key = keys.nextElement();        try        {          String keyStr = (String) key;          if (keyStr.startsWith(ERROR))          {            errors = true;          }          Element node = factory.createElement("foundJar");          node.setAttribute("name", keyStr.substring(0, keyStr.indexOf("-")));          node.setAttribute("desc", keyStr.substring(keyStr.indexOf("-") + 1));          node.appendChild(factory.createTextNode((String)subhash.get(keyStr)));          container.appendChild(node);        }        catch (Exception e)        {          errors = true;          Element node = factory.createElement("foundJar");          node.appendChild(factory.createTextNode(ERROR + " Reading " + key + " threw: " + e.toString()));          container.appendChild(node);        }      }    }    return errors;  }  /**   * Fillin hash with info about SystemProperties.     *   * Logs java.class.path and other likely paths; then attempts    * to search those paths for .jar files with Xalan-related classes.   *   * //@todo NOTE: We don't actually search java.ext.dirs for    * //  *.jar files therein! This should be updated   *   * @param h Hashtable to put information in   * @see #jarNames   * @see #checkPathForJars(String, String[])   */  protected void checkSystemProperties(Hashtable h)  {    if (null == h)      h = new Hashtable();    // Grab java version for later use    try    {      String javaVersion = System.getProperty("java.version");      h.put("java.version", javaVersion);    }    catch (SecurityException se)    {      // For applet context, etc.      h.put(        "java.version",        "WARNING: SecurityException thrown accessing system version properties");    }    // Printout jar files on classpath(s) that may affect operation    //  Do this in order    try    {      // This is present in all JVM's      String cp = System.getProperty("java.class.path");      h.put("java.class.path", cp);      Vector classpathJars = checkPathForJars(cp, jarNames);      if (null != classpathJars)        h.put(FOUNDCLASSES + "java.class.path", classpathJars);      // Also check for JDK 1.2+ type classpaths      String othercp = System.getProperty("sun.boot.class.path");      if (null != othercp)      {        h.put("sun.boot.class.path", othercp);        classpathJars = checkPathForJars(othercp, jarNames);        if (null != classpathJars)          h.put(FOUNDCLASSES + "sun.boot.class.path", classpathJars);      }      //@todo NOTE: We don't actually search java.ext.dirs for       //  *.jar files therein! This should be updated      othercp = System.getProperty("java.ext.dirs");      if (null != othercp)      {        h.put("java.ext.dirs", othercp);        classpathJars = checkPathForJars(othercp, jarNames);        if (null != classpathJars)          h.put(FOUNDCLASSES + "java.ext.dirs", classpathJars);      }      //@todo also check other System properties' paths?      //  v2 = checkPathForJars(System.getProperty("sun.boot.library.path"), jarNames);   // ?? may not be needed      //  v3 = checkPathForJars(System.getProperty("java.library.path"), jarNames);   // ?? may not be needed    }    catch (SecurityException se2)    {      // For applet context, etc.      h.put(        "java.class.path",        "WARNING: SecurityException thrown accessing system classpath properties");    }  }  /**   * Cheap-o listing of specified .jars found in the classpath.    *   * cp should be separated by the usual File.pathSeparator.  We    * then do a simplistic search of the path for any requested    * .jar filenames, and return a listing of their names and    * where (apparently) they came from.   *   * @param cp classpath to search   * @param jars array of .jar base filenames to look for   *   * @return Vector of Hashtables filled with info about found .jars   * @see #jarNames   * @see #logFoundJars(Vector, String)   * @see #appendFoundJars(Node, Document, Vector, String )   * @see #getApparentVersion(String, long)   */  protected Vector checkPathForJars(String cp, String[] jars)  {    if ((null == cp) || (null == jars) || (0 == cp.length())            || (0 == jars.length))      return null;    Vector v = new Vector();    StringTokenizer st = new StringTokenizer(cp, File.pathSeparator);    while (st.hasMoreTokens())    {      // Look at each classpath entry for each of our requested jarNames      String filename = st.nextToken();      for (int i = 0; i < jars.length; i++)      {        if (filename.indexOf(jars[i]) > -1)        {          File f = new File(filename);          if (f.exists())          {            // If any requested jarName exists, report on             //  the details of that .jar file            try            {              Hashtable h = new Hashtable(2);              // Note "-" char is looked for in appendFoundJars              h.put(jars[i] + "-path", f.getAbsolutePath());                           // We won't bother reporting on the xalan.jar apparent version              // since this requires knowing the jar size of the xalan.jar              // before we build it.               // For other jars, eg. xml-apis.jar and xercesImpl.jar, we               // report the apparent version of the file we've found              if (!("xalan.jar".equalsIgnoreCase(jars[i]))) {                              h.put(jars[i] + "-apparent.version",                    getApparentVersion(jars[i], f.length()));              }              v.addElement(h);            }            catch (Exception e)            {              /* no-op, don't add it  */            }          }          else          {            Hashtable h = new Hashtable(2);            // Note "-" char is looked for in appendFoundJars            h.put(jars[i] + "-path", WARNING + " Classpath entry: "                   + filename + " does not exist");            h.put(jars[i] + "-apparent.version", CLASS_NOTPRESENT);            v.addElement(h);          }        }      }    }    return v;  }  /**   * Cheap-o method to determine the product version of a .jar.      *   * Currently does a lookup into a local table of some recent    * shipped Xalan builds to determine where the .jar probably    * came from.  Note that if you recompile Xalan or Xerces    * yourself this will likely report a potential error, since    * we can't certify builds other than the ones we ship.   * Only reports against selected posted Xalan-J builds.   *   * //@todo actually look up version info in manifests   *   * @param jarName base filename of the .jarfile   * @param jarSize size of the .jarfile   *   * @return String describing where the .jar file probably    * came from   */  protected String getApparentVersion(String jarName, long jarSize)  {    // If we found a matching size and it's for our     //  jar, then return it's description    // Lookup in static jarVersions Hashtable    String foundSize = (String) jarVersions.get(new Long(jarSize));    if ((null != foundSize) && (foundSize.startsWith(jarName)))    {      return foundSize;    }    else    {      if ("xerces.jar".equalsIgnoreCase(jarName)              || "xercesImpl.jar".equalsIgnoreCase(jarName))//              || "xalan.jar".equalsIgnoreCase(jarName))      {        // For xalan.jar and xerces.jar/xercesImpl.jar, which we ship together:        // The jar is not from a shipped copy of xalan-j, so         //  it's up to the user to ensure that it's compatible        return jarName + " " + WARNING + CLASS_PRESENT;      }      else      {        // Otherwise, it's just a jar we don't have the version info calculated for        return jarName + " " + CLASS_PRESENT;      }    }  }  /**   * Report version information about JAXP interfaces.   *   * 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);      }    }  }  /**   * Report product version information from Xalan-J.   *   * 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 =        "com.sun.org.apache.xalan.internal.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);    }

⌨️ 快捷键说明

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