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/types XMLCatalog.java
Date Sat, 20 Apr 2002 16:10:04 GMT
ehatcher    02/04/20 09:10:04

  Modified:    src/main/org/apache/tools/ant/types XMLCatalog.java
  Log:
  add support for classpath, and ensure that relative files are resolved properly.
  
  the classpath appending when nesting XMLCatalogs may need to be rearranged, not sure.
  
  Revision  Changes    Path
  1.9       +69 -13    jakarta-ant/src/main/org/apache/tools/ant/types/XMLCatalog.java
  
  Index: XMLCatalog.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/XMLCatalog.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XMLCatalog.java	19 Apr 2002 07:04:45 -0000	1.8
  +++ XMLCatalog.java	20 Apr 2002 16:10:04 -0000	1.9
  @@ -63,6 +63,7 @@
   import java.util.Vector;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
  +import org.apache.tools.ant.AntClassLoader;
   import org.xml.sax.EntityResolver;
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
  @@ -90,8 +91,9 @@
    * <p>Possible future extension could allow a catalog file instead of nested
    * elements, or use Norman Walsh's entity resolver from xml-commons</p>
    *
  - * @author  dIon Gillard
  - * @version $Id: XMLCatalog.java,v 1.8 2002/04/19 07:04:45 bodewig Exp $
  + * @author dIon Gillard
  + * @author Erik Hatcher
  + * @version $Id: XMLCatalog.java,v 1.9 2002/04/20 16:10:04 ehatcher Exp $
    */
   public class XMLCatalog extends DataType implements Cloneable, EntityResolver {
       /** File utilities instance */
  @@ -101,7 +103,9 @@
       
       /** holds dtd/entity objects until needed */
       private Vector elements = new Vector();
  -    
  +
  +    private Path classpath;
  +
       //-- Methods ---------------------------------------------------------------
       
       /**
  @@ -110,7 +114,14 @@
       private Vector getElements() {
           return elements;
       }
  -    
  +
  +    /**
  +     * @return the classpath
  +     */
  +    private Path getClasspath() {
  +        return classpath;
  +    }
  +
       /**
        * Set the list of DTDLocation object sin the catalog
        *
  @@ -128,7 +139,44 @@
       private void addElement(DTDLocation aDTD) {
           getElements().addElement(aDTD);
       }
  -    
  +
  +    /**
  +     * Allows nested classpath elements
  +     */
  +    public Path createClasspath() {
  +        if (isReference()) {
  +            throw noChildrenAllowed();
  +        }
  +        if (this.classpath == null) {
  +            this.classpath = new Path(getProject());
  +        }
  +        return this.classpath.createPath();
  +    }
  +
  +    /**
  +     * Allows simple classpath string
  +     */
  +    public void setClasspath(Path classpath) {
  +        if (isReference()) {
  +            throw tooManyAttributes();
  +        }
  +        if (this.classpath == null) {
  +            this.classpath = classpath;
  +        } else {
  +            this.classpath.append(classpath);
  +        }
  +    }
  +
  +    /**
  +     * Allows classpath reference
  +     */
  +    public void setClasspathRef(Reference r) {
  +        if (isReference()) {
  +            throw tooManyAttributes();
  +        }
  +        createClasspath().setRefid(r);
  +    }
  +
       /**
        * Creates the nested <code>&lt;dtd&gt;</code> element.
        *
  @@ -140,6 +188,7 @@
           if (isReference()) {
               throw noChildrenAllowed();
           }
  +
           getElements().addElement(dtd);
       }
       
  @@ -164,12 +213,17 @@
               throw noChildrenAllowed();
           }
   
  +        // Add all nested elements to our catalog
           Vector newElements = catalog.getElements();
           Vector ourElements = getElements();
           Enumeration enum = newElements.elements();
           while (enum.hasMoreElements()) {
               ourElements.addElement(enum.nextElement());
           }
  +
  +        // Append the classpath of the nested catalog
  +        Path nestedClasspath = catalog.getClasspath();
  +        createClasspath().append(nestedClasspath);
       }
   
       /**
  @@ -193,7 +247,7 @@
               XMLCatalog catalog = (XMLCatalog) o;
               setElements(catalog.getElements());
           } else {
  -            String msg = r.getRefId() + " doesn\'t refer to an XMLCatalog";
  +            String msg = r.getRefId() + " does not refer to an XMLCatalog";
               throw new BuildException(msg);
           }
   
  @@ -212,7 +266,7 @@
               log("Matching DTD found for publicId: '" + publicId +
                   "' location: '" + matchingDTD.getLocation() + "'",
                   Project.MSG_DEBUG);
  -            File dtdFile = new File(matchingDTD.getLocation());
  +            File dtdFile = project.resolveFile(matchingDTD.getLocation());
               if (dtdFile.exists() && dtdFile.canRead()) {
                   source = new InputSource(new FileInputStream(dtdFile));
                   URL dtdFileURL = fileUtils.getFileURL(dtdFile);
  @@ -220,13 +274,15 @@
                   log("matched a readable file", Project.MSG_DEBUG);
               } else {
                   // check if publicId is a resource
  -                // FIXME: ClassLoader: should this be context?
  -                ClassLoader loader = LoaderUtils.getContextClassLoader();
  -                if (loader == null) {
  -                    loader = getClass().getClassLoader();
  +
  +                AntClassLoader loader = null;
  +                if (classpath != null) {
  +                    loader = new AntClassLoader(project, classpath);
  +                } else {
  +                    loader = new AntClassLoader(project, Path.systemClasspath);
                   }
  -                
  -                InputStream is 
  +
  +                InputStream is
                       = loader.getResourceAsStream(matchingDTD.getLocation());
                   if (is != null) {
                       source = new InputSource(is);
  
  
  

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