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/14 13:08:43 UTC

cvs commit: jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/deployment ApplicationXmlIo.java

cmlenz      2003/05/14 04:08:43

  Modified:    integration/ant/src/java/org/apache/cactus/integration/ant/deployment
                        ApplicationXmlIo.java
  Log:
  Implement entity resolving for application.xml
  
  Revision  Changes    Path
  1.2       +42 -1     jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/deployment/ApplicationXmlIo.java
  
  Index: ApplicationXmlIo.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/deployment/ApplicationXmlIo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ApplicationXmlIo.java	14 May 2003 10:43:52 -0000	1.1
  +++ ApplicationXmlIo.java	14 May 2003 11:08:43 -0000	1.2
  @@ -68,6 +68,7 @@
   
   import org.apache.cactus.integration.ant.util.ResourceUtils;
   import org.xml.sax.EntityResolver;
  +import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
   
   /**
  @@ -82,6 +83,42 @@
   public class ApplicationXmlIo
   {
       
  +    // Inner Classes -----------------------------------------------------------
  +
  +    /**
  +     * Implementation of the SAX EntityResolver interface that looks up the
  +     * application DTDs from the JAR.
  +     */
  +    private static class ApplicationXmlEntityResolver implements EntityResolver
  +    {
  +
  +        /**
  +         * @see org.xml.sax.EntityResolver#resolveEntity
  +         */
  +        public InputSource resolveEntity(String thePublicId, String theSystemId)
  +            throws SAXException, IOException
  +        {
  +            ApplicationXmlVersion version =
  +                ApplicationXmlVersion.valueOf(thePublicId);
  +            if (version != null)
  +            {
  +                String fileName = version.getSystemId().substring(
  +                    version.getSystemId().lastIndexOf('/'));
  +                InputStream in = this.getClass().getResourceAsStream(
  +                    "/org/apache/cactus/integration/ant/deployment/resources"
  +                    + fileName);
  +                if (in != null)
  +                {
  +                    return new InputSource(in);
  +                }
  +            }
  +            System.err.println("Resource for public ID " + thePublicId
  +                + " not found");
  +            return null;
  +        }
  +
  +    }
  +
       // Public Methods ----------------------------------------------------------
   
       /**
  @@ -186,6 +223,10 @@
           if (theEntityResolver != null)
           {
               builder.setEntityResolver(theEntityResolver);
  +        }
  +        else
  +        {
  +            builder.setEntityResolver(new ApplicationXmlEntityResolver());
           }
           return new ApplicationXml(builder.parse(theInput));
       }
  
  
  

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