ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional XMLValidateTask.java
Date Thu, 10 May 2001 11:44:08 GMT
bodewig     01/05/10 04:44:08

  Modified:    src/main/org/apache/tools/ant/taskdefs/optional
                        XMLValidateTask.java
  Log:
  Improve error reporting in <xmlvalidate> and tell the XML where the
  document is located.
  
  Removed tabs, this makes this patch look a lot bigger than it is.
  
  Submitted by:	Jesse Glick <Jesse.Glick@netbeans.com>
  
  Revision  Changes    Path
  1.2       +23 -3     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
  
  Index: XMLValidateTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLValidateTask.java	2001/04/10 04:47:00	1.1
  +++ XMLValidateTask.java	2001/05/10 11:44:06	1.2
  @@ -56,6 +56,8 @@
   import java.io.File;
   import java.io.FileReader;
   import java.io.IOException;
  +import java.net.MalformedURLException;
  +import java.net.URL;
   import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.Vector;
  @@ -346,7 +348,14 @@
           try {
               log("Validating " + afile.getName() + "... ", Project.MSG_VERBOSE);
               errorHandler.init(afile);
  -            xmlReader.parse(new InputSource(new FileReader(afile)));
  +            InputSource is = new InputSource(new FileReader(afile));
  +            String uri = "file:" + afile.getAbsolutePath().replace('\\', '/');
  +            for (int index = uri.indexOf('#'); index != -1;
  +                 index = uri.indexOf('#')) {
  +                uri = uri.substring(0, index) + "%23" + uri.substring(index+1);
  +            }
  +            is.setSystemId(uri);
  +            xmlReader.parse(is);
           } catch (SAXException ex) {
               if (failOnError)
                   throw new BuildException("Could'nt validate document " + afile);
  @@ -411,8 +420,19 @@
           }
   
           private String getMessage(SAXParseException e) {
  -
  -            return currentFile + ":" + e.getLineNumber() + ": " + e.getMessage();
  +            String sysID = e.getSystemId();
  +            if (sysID != null) {
  +                try {
  +                    int line = e.getLineNumber();
  +                    int col = e.getColumnNumber();
  +                    return new URL(sysID).getFile() +
  +                        (line == -1 ? "" : (":" + line +
  +                                            (col == -1 ? "" : (":" + col)))) +
  +                        ": " + e.getMessage();
  +                } catch (MalformedURLException mfue) {
  +                }
  +            }
  +            return e.getMessage();
           }
       }
   }
  
  
  

Mime
View raw message