billbarker    01/11/28 19:23:26

  Modified:    src/facade22/org/apache/tomcat/facade WebXmlReader.java
  Log:
  Improve the handling of invalid web.xml files.
  
  With this fix, the web.xml parsing of an invalid file always generates the same 
error every time Tomcat is started.
  
  Submitted by: David Schreibman [EMAIL PROTECTED]
  
  Revision  Changes    Path
  1.16      +12 -3     
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/WebXmlReader.java
  
  Index: WebXmlReader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/WebXmlReader.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- WebXmlReader.java 2001/11/29 03:06:05     1.15
  +++ WebXmlReader.java 2001/11/29 03:23:26     1.16
  @@ -98,7 +98,7 @@
       static class WebXmlErrorHandler implements ErrorHandler{
        Context ctx;
        XmlMapper xm;
  -     boolean ok;
  +     boolean ok=true;
        WebXmlErrorHandler( XmlMapper xm,Context ctx ) {
            this.ctx=ctx;
            this.xm=xm;
  @@ -106,22 +106,28 @@
   
        public void warning (SAXParseException exception)
            throws SAXException {
  +         ok=false;
            ctx.log("web.xml: Warning " + exception );
            ctx.log(xm.positionToString());
        }
        public void error (SAXParseException exception)
            throws SAXException
        {
  +         ok=false;
            ctx.log("web.xml: Error " + exception );
            ctx.log(xm.positionToString());
        }
        public void fatalError (SAXParseException exception)
            throws SAXException
        {
  +         ok=false;
            ctx.log("web.xml: Fatal error " + exception );
            ctx.log(xm.positionToString());
            throw new SAXException( "Fatal error " + exception );
        }
  +     public boolean isOk() {
  +         return ok;
  +     }
       }
       
       void processWebXmlFile( Context ctx, String file) {
  @@ -133,13 +139,15 @@
            }
            if( ctx.getDebug() > 0 ) ctx.log("Reading " + file );
            XmlMapper xh=new XmlMapper();
  +         WebXmlErrorHandler xeh=null;
            File v=new File( ctx.getWorkDir(), "webxmlval.txt" );
            if( validate ) {
                if( ! v.exists() || 
                    v.lastModified() < f.lastModified() ) {
                    ctx.log("Validating web.xml");
                    xh.setValidating(true);
  -                 xh.setErrorHandler( new WebXmlErrorHandler( xh, ctx ) );
  +                 xeh=new WebXmlErrorHandler( xh, ctx ); 
  +                 xh.setErrorHandler( xeh );
                }
            }
   
  @@ -229,7 +237,8 @@
   
            Object ctx1=xh.readXml(f, ctx);
   
  -         if( validate ) {
  +         if( validate && xeh != null && xeh.isOk() ) {
  +             // don't create the validation mark if an error was detected
                try {
                    FileOutputStream fos=new FileOutputStream( v );
                    fos.write( 1 );
  
  
  

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

Reply via email to