ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant Diagnostics.java
Date Sun, 01 Dec 2002 04:38:44 GMT
stevel      2002/11/30 20:38:44

  Modified:    src/main/org/apache/tools/ant Diagnostics.java
  Log:
  because I had a pressing need to be find out which parser I was using on java1.4, and new
all the code was a cut and paste away
  
  Revision  Changes    Path
  1.6       +99 -0     jakarta-ant/src/main/org/apache/tools/ant/Diagnostics.java
  
  Index: Diagnostics.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Diagnostics.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Diagnostics.java	4 Nov 2002 17:37:05 -0000	1.5
  +++ Diagnostics.java	1 Dec 2002 04:38:44 -0000	1.6
  @@ -53,6 +53,9 @@
    */
   package org.apache.tools.ant;
   
  +
  +import javax.xml.parsers.SAXParserFactory;
  +import javax.xml.parsers.SAXParser;
   import java.io.File;
   import java.io.FilenameFilter;
   import java.io.PrintStream;
  @@ -175,6 +178,79 @@
       }
   
       /**
  +     * what parser are we using.
  +     * @return the classname of the parser
  +     */
  +    private static String getXmlParserName() {
  +        SAXParser saxParser= getSAXParser();
  +        if (saxParser == null) {
  +            return "Could not create an XML Parser";
  +        }
  +
  +        // check to what is in the classname
  +        String saxParserName = saxParser.getClass().getName();
  +        return saxParserName;
  +    }
  +
  +    /**
  +     * Create a JAXP SAXParser
  +     * @return parser or null for trouble
  +     */
  +    private static SAXParser getSAXParser() {
  +        SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
  +        if (saxParserFactory == null) {
  +            return null;
  +        }
  +        SAXParser saxParser=null;
  +        try {
  +            saxParser = saxParserFactory.newSAXParser();
  +        } catch (Exception e) {
  +        }
  +        return saxParser;
  +    }
  +
  +    /**
  +     * get the location of the parser
  +     * @return path or null for trouble in tracking it down
  +     */
  +
  +    private static String getXMLParserLocation() {
  +        SAXParser saxParser = getSAXParser();
  +        if (saxParser == null) {
  +            return null;
  +        }
  +        String location=getClassLocation(saxParser.getClass());
  +        return location;
  +    }
  +
  +    /**
  +     * get the location of a class. Stolen from axis/webapps/happyaxis.jsp
  +     * @param clazz
  +     * @return the jar file or path where a class was found, or null
  +     */
  +
  +    private static String getClassLocation( Class clazz) {
  +        try {
  +            java.net.URL url = clazz.getProtectionDomain().getCodeSource().getLocation();
  +            String location = url.toString();
  +            if (location.startsWith("jar")) {
  +                url = ((java.net.JarURLConnection) url.openConnection()).getJarFileURL();
  +                location = url.toString();
  +            }
  +
  +            if (location.startsWith("file")) {
  +                java.io.File file = new java.io.File(url.getFile());
  +                return file.getAbsolutePath();
  +            } else {
  +                return url.toString();
  +            }
  +        } catch (Throwable t) {
  +        }
  +        return null;
  +    }
  +
  +
  +    /**
        * Print a report to the given stream.
        * @param out the stream to print the report to.
        */
  @@ -214,6 +290,13 @@
           out.println("-------------------------------------------");
           doReportWhich(out);
   
  +
  +        out.println();
  +        out.println("-------------------------------------------");
  +        out.println(" XML Parser information");
  +        out.println("-------------------------------------------");
  +        doReportParserInfo(out);
  +
           out.println();
           out.println("-------------------------------------------");
           out.println(" System properties");
  @@ -320,4 +403,20 @@
           }
       }
   
  +    /**
  +     * tell the user about the XML parser
  +     * @param out
  +     */
  +    private static void doReportParserInfo(PrintStream out) {
  +        String parserName=getXmlParserName();
  +        String parserLocation=getXMLParserLocation();
  +        if(parserName==null) {
  +            parserName="unknown";
  +        }
  +        if(parserLocation==null) {
  +            parserLocation="unknown";
  +        }
  +        out.println("XML Parser : " + parserName);
  +        out.println("XML Parser Location: " + parserLocation);
  +    }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message