tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Cruikshank <a...@epitonic.com>
Subject Re: Bugs in JspReader.java
Date Fri, 03 Dec 1999 18:47:18 GMT
At 05:10 AM 12/2/99 -0500, you wrote:

>Alex, Why do you suggest a new internal class instead of fixing mark?

In order to fix JspReader's state handling for include directives, I've 
modified Mark.java to include all of JspReader's state including it's 
include stack (see included file).  I've modified JspReader to reference 
current.mark.foo everytime it used to reference foo where foo is an 
internal state variable (ie. stream).  I also modified the popFile() and 
the two pushFile() methods to call the new pushStream() and popStream() in 
Mark.  I've included the diff at the bottom of this message.  It compiles 
and seems to work fine on my system (RedHat Linux 6.0 on PentiumIII 
450).  Does anyone want to make these changes?

Alex Cruikshank
Software Engineer
Epitonic.com
alex@eptionic.com


JspReader.java diff
122c122,123
<         if (current.baseDir == null || isAbsolute)
---
 >         if ((current == null) || (current.baseDir == null) || (isAbsolute))
 >         {
123a125
 >         }
125c127,129
<             pushFile(new File(current.baseDir + name), encoding);
---
 >         {
 >             pushFile(new File(current.baseDir + "/" + name), encoding);
 >         }
134c138
<       throws ParseException, FileNotFoundException
---
 >         throws ParseException, FileNotFoundException
137,142c141,148
<       if (encoding == null)
<           encoding = System.getProperty("file.encoding", "8859_1");
<       // Register the file, and read its content:
<       int fileid    = registerSourceFile(file.getAbsolutePath());
<       Reader reader = null;
<       try {
---
 >         if (encoding == null)
 >         encoding = System.getProperty("file.encoding", "8859_1");
 >
 >         // Register the file, and read its content:
 >         int fileid    = registerSourceFile(file.getAbsolutePath());
 >         Reader reader = null;
 >         try
 >         {
144,152c150,163
<                 reader = new InputStreamReader(new FileInputStream(file),
<                                                encoding);
<             else {
<               // Need to do this as the getResourceAsStream is relative
<               // to docBase and if we use it on Win32 then File uses \
<               // and not / which causes a problem.
<               String fileName = file.toString();
<               if (File.separatorChar == '\\')
<                   fileName = fileName.replace (File.separatorChar, '/');
---
 >             {
 >                 reader = new InputStreamReader(new 
FileInputStream(file), encoding);
 >             }
 >             else
 >             {
 >                 // Need to do this as the getResourceAsStream is relative
 >                 // to docBase and if we use it on Win32 then File uses \
 >                 // and not / which causes a problem.
 >                 String fileName = file.toString();
 >                 if (File.separatorChar == '\\')
 >                 {
 >                     fileName = fileName.replace (File.separatorChar, '/');
 >                 }
 >
154a166
 >                 {
155a168
 >                 }
157c170,171
<                 try {
---
 >                 try
 >                 {
159,160c173,176
<                 } catch (Exception ex) {
<                     throw new FileNotFoundException(fileName + ": "+ 
ex.getMessage());
---
 >                 }
 >                 catch (Exception ex)
 >                 {
 >                    throw new FileNotFoundException(fileName + ": "+ 
ex.getMessage());
164,187c180,197
<           CharArrayWriter caw   = new CharArrayWriter();
<           char            buf[] = new char[1024];
<           for (int i = 0 ; (i = reader.read(buf)) != -1 ; )
<               caw.write(buf, 0, i);
<           caw.close();
<               if ( current == null )
<               {
<                       current = new Mark( this, caw.toCharArray, fileid, 
file.getParent(), encoding );
<               }
<               else
<               {
<                       current.pushStream( caw.toCharArray, fileid, 
file.getParent(), encoding );
<               }
<           IncludeState state = new IncludeState();
<           this.stream = caw.toCharArray();
<               this.current = new Mark(this, fileid);
<           // Prepare a new include state:
<           if (includeStack == null) {
<               // Initial file, prepare for include files:
<               includeStack = new Stack();
<           } else {
<               includeStack.push(state);
<           }
<     } catch (FileNotFoundException fnfe) {
---
 >             CharArrayWriter caw   = new CharArrayWriter();
 >             char            buf[] = new char[1024];
 >             for (int i = 0 ; (i = reader.read(buf)) != -1 ; )
 >             {
 >                 caw.write(buf, 0, i);
 >             }
 >             caw.close();
 >             if ( current == null )
 >             {
 >                 current = new Mark( this, caw.toCharArray(), fileid, 
file.getParent(), encoding );
 >             }
 >             else
 >             {
 >                 current.pushStream( caw.toCharArray(), fileid, 
file.getParent(), encoding );
 >             }
 >         }
 >         catch (FileNotFoundException fnfe)
 >         {
189c199,201
<       } catch (Throwable ex) {
---
 >         }
 >         catch (Throwable ex)
 >         {
192,200c204,215
<           // Pop state being constructed:
<           popFile();
<           throw new 
ParseException(Constants.getString("jsp.error.file.cannot.read",
<                                                       new Object[] { file 
}));
<       } finally {
<           if ( reader != null ) {
<               try { reader.close(); } catch (Exception any) {}
<           }
<       }
---
 >             // Pop state being constructed:
 >             popFile();
 >             throw new 
ParseException(Constants.getString("jsp.error.file.cannot.read",
 >                     new Object[] { file }));
 >         }
 >         finally
 >         {
 >             if ( reader != null )
 >             {
 >                 try { reader.close(); } catch (Exception any) {}
 >             }
 >         }
203,207d217
<     public boolean popFile() {
<       // Is stack created ? (will happen if the Jsp file we'r looking at is
<       // missing.
<       if(includeStack == null)
<               return false;
209,215c219,227
<       // Any thing left ?
<       if ( includeStack.size() == 0 )
<           return false;
<       // Restore parser state:
<       size--;
<       IncludeState state = (IncludeState) includeStack.pop();
<       state.restore();
---
 >     public boolean popFile()
 >     {
 >         // Is stack created or empty? (will happen if the Jsp file we'r 
looking at is
 >         // missing.
 >         if ( current == null ) return false;
 >
 >       // Restore parser state: (left in here for legacy reasons,
 >         // should use mark.includeState.size() + 1 instead)
 >         size--;
217c229
<       return true;
---
 >         return current.popStream();
234c246
<       if (current.cursor >= stream.length)
---
 >       if (current.cursor >= current.stream.length)
238c250
<                 if ( current.cursor < stream.length) return true;
---
 >                 if ( current.cursor < current.stream.length) return true;
249c261
<       int ch = stream[current.cursor];
---
 >       int ch = current.stream[current.cursor];
274c286
<       return stream[current.cursor];
---
 >       return current.stream[current.cursor];

Mime
View raw message