craigmcc    02/04/22 12:04:01

  Modified:    catalina/src/share/org/apache/catalina/startup Catalina.java
                        ContextConfig.java
  Log:
  When parsing server.xml and web.xml files, use an InputSource rather than an
  InputStream so that we can set a system identifier.  Among other things, this
  allows developers to split up their input files with the use of external
  entities like this:
  
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/dtd/web-app_2_3.dtd";
    [
    <!ENTITY webinc PUBLIC "webinc" "webinc.xml">
    ]
    >
    <web-app>
      &webinc;
    </web-app>
  
  Tested this with web.xml files in both unpacked directories and a packaged
  WAR file, and it seems to work.
  
  NOTE:  This patch doesn't address trying to parse tag library descriptors
  that have external entities included in them.  The same approach would probably
  work, but will require a couple of API changes to some private methods in
  o.a.c.ContextConfig and the corresponding code in Jasper.
  
  Based on a patch provided by Attila Szegedi <szegedia at freemail.hu> for
  Bugzilla #8024.
  
  Revision  Changes    Path
  1.47      +18 -6     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java
  
  Index: Catalina.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- Catalina.java     15 Apr 2002 09:34:06 -0000      1.46
  +++ Catalina.java     22 Apr 2002 19:04:01 -0000      1.47
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java,v
 1.46 2002/04/15 09:34:06 remm Exp $
  - * $Revision: 1.46 $
  - * $Date: 2002/04/15 09:34:06 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java,v
 1.47 2002/04/22 19:04:01 craigmcc Exp $
  + * $Revision: 1.47 $
  + * $Date: 2002/04/22 19:04:01 $
    *
    * ====================================================================
    *
  @@ -66,6 +66,7 @@
   
   
   import java.io.File;
  +import java.io.FileInputStream;
   import java.io.IOException;
   import java.io.OutputStream;
   import java.lang.reflect.InvocationTargetException;
  @@ -82,6 +83,7 @@
   import org.apache.commons.digester.Digester;
   import org.apache.commons.digester.Rule;
   import org.xml.sax.Attributes;
  +import org.xml.sax.InputSource;
   
   
   /**
  @@ -97,7 +99,7 @@
    * </u>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.46 $ $Date: 2002/04/15 09:34:06 $
  + * @version $Revision: 1.47 $ $Date: 2002/04/22 19:04:01 $
    */
   
   public class Catalina {
  @@ -438,8 +440,13 @@
           Digester digester = createStartDigester();
           File file = configFile();
           try {
  +            InputSource is =
  +                new InputSource("file://" + file.getAbsolutePath());
  +            FileInputStream fis = new FileInputStream(file);
  +            is.setByteStream(fis);
               digester.push(this);
  -            digester.parse(file);
  +            digester.parse(is);
  +            fis.close();
           } catch (Exception e) {
               System.out.println("Catalina.start: " + e);
               e.printStackTrace(System.out);
  @@ -548,8 +555,13 @@
           Digester digester = createStopDigester();
           File file = configFile();
           try {
  +            InputSource is =
  +                new InputSource("file://" + file.getAbsolutePath());
  +            FileInputStream fis = new FileInputStream(file);
  +            is.setByteStream(fis);
               digester.push(this);
  -            digester.parse(file);
  +            digester.parse(is);
  +            fis.close();
           } catch (Exception e) {
               System.out.println("Catalina.stop: " + e);
               e.printStackTrace(System.out);
  
  
  
  1.62      +23 -8     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextConfig.java
  
  Index: ContextConfig.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextConfig.java,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- ContextConfig.java        4 Apr 2002 20:30:34 -0000       1.61
  +++ ContextConfig.java        22 Apr 2002 19:04:01 -0000      1.62
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextConfig.java,v
 1.61 2002/04/04 20:30:34 craigmcc Exp $
  - * $Revision: 1.61 $
  - * $Date: 2002/04/04 20:30:34 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/ContextConfig.java,v
 1.62 2002/04/22 19:04:01 craigmcc Exp $
  + * $Revision: 1.62 $
  + * $Date: 2002/04/22 19:04:01 $
    *
    * ====================================================================
    *
  @@ -123,6 +123,7 @@
   import org.apache.catalina.util.StringManager;
   import org.apache.catalina.valves.ValveBase;
   import org.apache.commons.digester.Digester;
  +import org.xml.sax.InputSource;
   import org.xml.sax.SAXParseException;
   
   
  @@ -131,7 +132,7 @@
    * of that Context, and the associated defined servlets.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.61 $ $Date: 2002/04/04 20:30:34 $
  + * @version $Revision: 1.62 $ $Date: 2002/04/22 19:04:01 $
    */
   
   public final class ContextConfig
  @@ -267,13 +268,17 @@
           // Process the application web.xml file
           synchronized (webDigester) {
               try {
  +                URL url =
  +                    servletContext.getResource(Constants.ApplicationWebXml);
  +                InputSource is = new InputSource(url.toExternalForm());
  +                is.setByteStream(stream);
                   webDigester.setDebug(getDebug());
                   if (context instanceof StandardContext) {
                       ((StandardContext) context).setReplaceWelcomeFiles(true);
                   }
                   webDigester.clear();
                   webDigester.push(context);
  -                webDigester.parse(stream);
  +                webDigester.parse(is);
               } catch (SAXParseException e) {
                   log(sm.getString("contextConfig.applicationParse"), e);
                   log(sm.getString("contextConfig.applicationPosition",
  @@ -285,7 +290,9 @@
                   ok = false;
               } finally {
                   try {
  -                    stream.close();
  +                    if (stream != null) {
  +                        stream.close();
  +                    }
                   } catch (IOException e) {
                       log(sm.getString("contextConfig.applicationClose"), e);
                   }
  @@ -487,6 +494,8 @@
           FileInputStream stream = null;
           try {
               stream = new FileInputStream(file.getCanonicalPath());
  +            stream.close();
  +            stream = null;
           } catch (FileNotFoundException e) {
               log(sm.getString("contextConfig.defaultMissing"));
               return;
  @@ -498,12 +507,16 @@
           // Process the default web.xml file
           synchronized (webDigester) {
               try {
  +                InputSource is =
  +                    new InputSource("file://" + file.getAbsolutePath());
  +                stream = new FileInputStream(file);
  +                is.setByteStream(stream);
                   webDigester.setDebug(getDebug());
                   if (context instanceof StandardContext)
                       ((StandardContext) context).setReplaceWelcomeFiles(true);
                   webDigester.clear();
                   webDigester.push(context);
  -                webDigester.parse(stream);
  +                webDigester.parse(is);
               } catch (SAXParseException e) {
                   log(sm.getString("contextConfig.defaultParse"), e);
                   log(sm.getString("contextConfig.defaultPosition",
  @@ -515,7 +528,9 @@
                   ok = false;
               } finally {
                   try {
  -                    stream.close();
  +                    if (stream != null) {
  +                        stream.close();
  +                    }
                   } catch (IOException e) {
                       log(sm.getString("contextConfig.defaultClose"), e);
                   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to