ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional XMLValidateTask.java
Date Sat, 20 Apr 2002 16:14:32 GMT
ehatcher    02/04/20 09:14:32

  Modified:    src/main/org/apache/tools/ant/taskdefs/optional
                        XMLValidateTask.java
  Log:
  modified to internally use an XMLCatalog rather than the LocalResolver.
  
  Note: one potential API break, I removed public Vector dtdLocationsr, but it was added after
1.4.1 release, so would only be a problem if classes written for 1.5alpha relied on it which
is unlikely, and too bad for them!  :)
  
  Revision  Changes    Path
  1.16      +18 -103   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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- XMLValidateTask.java	20 Apr 2002 13:57:28 -0000	1.15
  +++ XMLValidateTask.java	20 Apr 2002 16:14:32 -0000	1.16
  @@ -72,6 +72,8 @@
   import org.apache.tools.ant.types.FileSet;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.Reference;
  +import org.apache.tools.ant.types.XMLCatalog;
  +import org.apache.tools.ant.types.DTDLocation;
   import org.xml.sax.XMLReader;
   import org.xml.sax.EntityResolver;
   import org.xml.sax.Parser;
  @@ -123,10 +125,7 @@
           = new ValidatorErrorHandler(); // to report sax parsing errors
       protected Hashtable features = new Hashtable();
   
  -    /**
  -     * The list of configured DTD locations
  -     */
  -    public Vector dtdLocations = new Vector();
  +    private XMLCatalog xmlCatalog = new XMLCatalog();
   
       /**
        * Specify how parser error are to be handled.
  @@ -214,31 +213,36 @@
       }
   
       /**
  +     *
  +     */
  +    public void addConfiguredXMLCatalog(XMLCatalog catalog) {
  +        xmlCatalog.addConfiguredXMLCatalog(catalog);
  +    }
  +
  +    /**
        * specifify a set of file to be checked
        */
       public void addFileset(FileSet set) {
           filesets.addElement(set);
       }
   
  +    public void init() throws BuildException {
  +        super.init();
  +        xmlCatalog.setProject(project);
  +    }
  +
       /**
        * Create a DTD location record. This stores the location of a DTD. The DTD is identified
  -     * by its public Id. The location may either be a file location or a resource location.
  +     * by its public Id.
        */
       public DTDLocation createDTD() {
           DTDLocation dtdLocation = new DTDLocation();
  -        dtdLocations.addElement(dtdLocation);
  -
  +        xmlCatalog.addDTD(dtdLocation);
           return dtdLocation;
       }
   
       protected EntityResolver getEntityResolver() {
  -        LocalResolver resolver = new LocalResolver();
  -
  -        for (Enumeration i = dtdLocations.elements(); i.hasMoreElements();) {
  -            DTDLocation location = (DTDLocation) i.nextElement();
  -            resolver.registerDTD(location);
  -        }
  -        return resolver;
  +        return xmlCatalog;
       }
   
       public void execute() throws BuildException {
  @@ -470,95 +474,6 @@
                   }
               }
               return e.getMessage();
  -        }
  -    }
  -
  -    public static class DTDLocation 
  -        extends org.apache.tools.ant.types.DTDLocation {
  -    }
  -
  -    private class LocalResolver
  -        implements EntityResolver {
  -        private Hashtable fileDTDs = new Hashtable();
  -        private Hashtable resourceDTDs = new Hashtable();
  -        private Hashtable urlDTDs = new Hashtable();
  -
  -        public LocalResolver() {}
  -
  -        public void registerDTD(String publicId, String location) {
  -            if (location == null) {
  -                return;
  -            }
  -
  -            File fileDTD = project.resolveFile(location);
  -            if (fileDTD.exists()) {
  -                if (publicId != null) {
  -                    fileDTDs.put(publicId, fileDTD);
  -                    log("Mapped publicId " + publicId + " to file " + fileDTD, 
  -                        Project.MSG_VERBOSE);
  -                }
  -                return;
  -            }
  -
  -            if (LocalResolver.this.getClass().getResource(location) != null) {
  -                if (publicId != null) {
  -                    resourceDTDs.put(publicId, location);
  -                    log("Mapped publicId " + publicId + " to resource " 
  -                        + location, Project.MSG_VERBOSE);
  -                }
  -            }
  -
  -            try {
  -                if (publicId != null) {
  -                    URL urldtd = new URL(location);
  -                    urlDTDs.put(publicId, urldtd);
  -                }
  -            } catch (MalformedURLException e) {
  -                //ignored
  -            }
  -        }
  -
  -        public InputSource resolveEntity(String publicId, String systemId)
  -            throws SAXException {
  -            File dtdFile = (File) fileDTDs.get(publicId);
  -            if (dtdFile != null) {
  -                try {
  -                    log("Resolved " + publicId + " to local file " + dtdFile, Project.MSG_VERBOSE);
  -                    return new InputSource(new FileInputStream(dtdFile));
  -                } catch (FileNotFoundException ex) {
  -                    // ignore
  -                }
  -            }
  -
  -            String dtdResourceName = (String) resourceDTDs.get(publicId);
  -            if (dtdResourceName != null) {
  -                InputStream is = this.getClass().getResourceAsStream(dtdResourceName);
  -                if (is != null) {
  -                    log("Resolved " + publicId + " to local resource " 
  -                        + dtdResourceName, Project.MSG_VERBOSE);
  -                    return new InputSource(is);
  -                }
  -            }
  -
  -            URL dtdUrl = (URL) urlDTDs.get(publicId);
  -            if (dtdUrl != null) {
  -                try {
  -                    InputStream is = dtdUrl.openStream();
  -                    log("Resolved " + publicId + " to url " + dtdUrl, Project.MSG_VERBOSE);
  -                    return new InputSource(is);
  -                } catch (IOException ioe) {
  -                    //ignore
  -                }
  -            }
  -
  -            log("Could not resolve ( publicId: " + publicId + ", systemId: " + systemId
+ ") to a local entity",
  -                Project.MSG_INFO);
  -
  -            return null;
  -        }
  -
  -        public void registerDTD(DTDLocation location) {
  -            registerDTD(location.getPublicId(), location.getLocation());
           }
       }
   }
  
  
  

--
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