You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by cm...@apache.org on 2003/05/01 15:39:26 UTC

cvs commit: jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant CactifyTask.java WebXmlMergeTask.java

cmlenz      2003/05/01 06:39:26

  Modified:    integration/ant/src/java/org/apache/cactus/integration/ant/webxml
                        Tag: CACTUS_14_ANT_BRANCH WebXmlIo.java
               integration/ant/src/java/org/apache/cactus/integration/ant
                        Tag: CACTUS_14_ANT_BRANCH CactifyTask.java
                        WebXmlMergeTask.java
  Log:
  Entity resolving is back. The web-app DTDs are now included with the Ant integration jar, so no explicit <xmlcatalog> needs to be set up in the build file.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +77 -8     jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/webxml/Attic/WebXmlIo.java
  
  Index: WebXmlIo.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/webxml/Attic/WebXmlIo.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- WebXmlIo.java	30 Apr 2003 15:37:03 -0000	1.1.2.2
  +++ WebXmlIo.java	1 May 2003 13:39:26 -0000	1.1.2.3
  @@ -73,6 +73,8 @@
   import org.apache.xml.serialize.XMLSerializer;
   import org.w3c.dom.Document;
   import org.w3c.dom.DocumentType;
  +import org.xml.sax.EntityResolver;
  +import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
   
   /**
  @@ -86,8 +88,65 @@
   public class WebXmlIo
   {
       
  +    // Inner Classes -----------------------------------------------------------
  +
  +    /**
  +     * Implementation of the SAX EntityResolver interface that looks up the
  +     * web-app DTDs from the JAR. This resolver can also wrap around an existing
  +     * entity resolver, delegating to it when it couldn't resolve an entity
  +     * itself.
  +     */
  +    private static class WebXmlEntityResolver implements EntityResolver
  +    {
  +
  +        /**
  +         * The nested entity resolver.
  +         */
  +        private EntityResolver nestedResolver;
  +
  +        /**
  +         * Constructor.
  +         * 
  +         * @param theNestedResolver The resolver to delegate to, or
  +         *        <code>null</code>
  +         */
  +        public WebXmlEntityResolver(EntityResolver theNestedResolver)
  +        {
  +            this.nestedResolver = theNestedResolver;
  +        }
  +
  +        /**
  +         * @see org.xml.sax.EntityResolver#resolveEntity
  +         */
  +        public InputSource resolveEntity(String thePublicId, String theSystemId)
  +            throws SAXException, IOException
  +        {
  +            WebXmlVersion version = WebXmlVersion.valueOf(thePublicId);
  +            if (version != null)
  +            {
  +                String fileName = version.getSystemId().substring(
  +                    version.getSystemId().lastIndexOf('/'));
  +                InputStream in = this.getClass().getResourceAsStream(
  +                    "/org/apache/cactus/integration/ant/webxml/resources"
  +                    + fileName);
  +                if (in != null)
  +                {
  +                    return new InputSource(in);
  +                }
  +            }
  +            System.err.println("Resource for public ID " + thePublicId
  +                + " not found");
  +            if (nestedResolver != null)
  +            {
  +                nestedResolver.resolveEntity(thePublicId, theSystemId);
  +            }
  +            return null;
  +        }
  +
  +    }
  +
       // Public Methods ----------------------------------------------------------
  -    
  +
       /**
        * Creates a new empty deployment descriptor.
        * 
  @@ -116,13 +175,16 @@
        * Parses the deployment descriptor of a web-application archive (WAR).
        * 
        * @param theWar The web-app archive
  +     * @param theEntityResolver A SAX entity resolver, or <code>null</code> to
  +     *        use the default
        * @return The parsed descriptor
        * @throws SAXException If the descriptor could not be parsed
        * @throws ParserConfigurationException If the XML parser was not correctly
        *          configured
        * @throws IOException If an I/O error occurs
        */
  -    public static WebXml parseWebXml(JarFile theWar)
  +    public static WebXml parseWebXml(JarFile theWar,
  +    EntityResolver theEntityResolver)
           throws SAXException, ParserConfigurationException, IOException
       {
           InputStream in = null;
  @@ -130,7 +192,7 @@
           {
               ZipEntry webXmlEntry = theWar.getEntry("WEB-INF/web.xml");
               in = theWar.getInputStream(webXmlEntry);
  -            return parseWebXml(in);
  +            return parseWebXml(in, theEntityResolver);
           }
           finally
           {
  @@ -152,20 +214,23 @@
        * Parses a deployment descriptor stored in a regular file.
        * 
        * @param theFile The file to parse
  +     * @param theEntityResolver A SAX entity resolver, or <code>null</code> to
  +     *        use the default
        * @return The parsed descriptor
        * @throws SAXException If the file could not be parsed
        * @throws ParserConfigurationException If the XML parser was not correctly
        *          configured
        * @throws IOException If an I/O error occurs
        */
  -    public static WebXml parseWebXml(File theFile)
  +    public static WebXml parseWebXml(File theFile,
  +    EntityResolver theEntityResolver)
           throws SAXException, ParserConfigurationException, IOException
       {
           InputStream in = null;
           try
           {
               in = new FileInputStream(theFile);
  -            return parseWebXml(in);
  +            return parseWebXml(in, theEntityResolver);
           }
           finally
           {
  @@ -187,13 +252,16 @@
        * Parses a deployment descriptor provided as input stream.
        * 
        * @param theInput The input stream
  +     * @param theEntityResolver A SAX entity resolver, or <code>null</code> to
  +     *        use the default
        * @return The parsed descriptor
        * @throws SAXException If the input could not be parsed
        * @throws ParserConfigurationException If the XML parser was not correctly
        *          configured
        * @throws IOException If an I/O error occurs
        */
  -    public static WebXml parseWebXml(InputStream theInput)
  +    public static WebXml parseWebXml(InputStream theInput,
  +        EntityResolver theEntityResolver)
           throws SAXException, ParserConfigurationException, IOException
       {
           DocumentBuilderFactory factory =
  @@ -201,9 +269,10 @@
           factory.setValidating(false);
           factory.setNamespaceAware(false);
           DocumentBuilder builder = factory.newDocumentBuilder();
  +        builder.setEntityResolver(new WebXmlEntityResolver(null));
           return new WebXml(builder.parse(theInput));
       }
  -    
  +
       /**
        * Writes the specified document to a file.
        * 
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.6   +3 -3      jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/Attic/CactifyTask.java
  
  Index: CactifyTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/Attic/CactifyTask.java,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- CactifyTask.java	1 May 2003 12:09:31 -0000	1.1.2.5
  +++ CactifyTask.java	1 May 2003 13:39:26 -0000	1.1.2.6
  @@ -358,7 +358,7 @@
               try
               {
                   WebXml parsedMergeWebXml =
  -                    WebXmlIo.parseWebXml(this.mergeWebXml);
  +                    WebXmlIo.parseWebXml(this.mergeWebXml, null);
                   merger = new WebXmlMerger(theWebXml);
                   merger.setLog(new AntLog(this));
                   merger.merge(parsedMergeWebXml);
  @@ -412,7 +412,7 @@
           try
           {
               war = new JarFile(this.srcFile);
  -            webXml = WebXmlIo.parseWebXml(war);
  +            webXml = WebXmlIo.parseWebXml(war, null);
           }
           catch (SAXException e)
           {
  
  
  
  1.11.2.4  +8 -31     jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/WebXmlMergeTask.java
  
  Index: WebXmlMergeTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/WebXmlMergeTask.java,v
  retrieving revision 1.11.2.3
  retrieving revision 1.11.2.4
  diff -u -r1.11.2.3 -r1.11.2.4
  --- WebXmlMergeTask.java	30 Apr 2003 15:44:57 -0000	1.11.2.3
  +++ WebXmlMergeTask.java	1 May 2003 13:39:26 -0000	1.11.2.4
  @@ -59,7 +59,6 @@
   import java.io.File;
   import java.io.IOException;
   
  -import javax.xml.parsers.DocumentBuilderFactory;
   import javax.xml.parsers.ParserConfigurationException;
   
   import org.apache.cactus.integration.ant.util.AntLog;
  @@ -122,11 +121,6 @@
        */
       private XMLCatalog xmlCatalog = new XMLCatalog();
   
  -    /**
  -     * The factory for JAXP document builders.
  -     */
  -    private DocumentBuilderFactory factory;
  -
       // Public Methods ----------------------------------------------------------
       
       /**
  @@ -134,10 +128,6 @@
        */
       public void init() throws BuildException
       {
  -        this.factory = DocumentBuilderFactory.newInstance();
  -        this.factory.setValidating(false);
  -        this.factory.setNamespaceAware(false);
  -    
           this.xmlCatalog.setProject(project);
       }
   
  @@ -167,9 +157,13 @@
                    || (srcFile.lastModified() > destFile.lastModified())
                    || (mergeFile.lastModified() > destFile.lastModified()))
                   {
  -                    WebXml srcWebXml = WebXmlIo.parseWebXml(this.srcFile);
  -                    WebXml mergeWebXml = WebXmlIo.parseWebXml(this.mergeFile);
  -                    merge(srcWebXml, mergeWebXml);
  +                    WebXml srcWebXml =
  +                        WebXmlIo.parseWebXml(this.srcFile, this.xmlCatalog);
  +                    WebXml mergeWebXml =
  +                        WebXmlIo.parseWebXml(this.mergeFile, this.xmlCatalog);
  +                    WebXmlMerger merger = new WebXmlMerger(srcWebXml);
  +                    merger.setLog(new AntLog(this));
  +                    merger.merge(mergeWebXml);
                       WebXmlIo.writeWebXml(srcWebXml, this.destFile);
                   }
                   else
  @@ -274,21 +268,4 @@
           this.indent = isIndent;
       }
   
  -    // Private Methods ---------------------------------------------------------
  -    
  -    /**
  -     * Merges the merge descriptor with the original descriptor. 
  -     * 
  -     * @param theSrcWebXml The original descriptor
  -     * @param theMergeWebXml The descriptor to merge in
  -     * @throws BuildException If the operation fails
  -     */
  -    private void merge(WebXml theSrcWebXml, WebXml theMergeWebXml)
  -        throws BuildException
  -    {
  -        WebXmlMerger merger = new WebXmlMerger(theSrcWebXml);
  -        merger.setLog(new AntLog(this));
  -        merger.merge(theMergeWebXml);
  -    }
  -    
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org