tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler JspDocumentParser.java ParserController.java
Date Mon, 04 Oct 2004 20:10:14 GMT
markt       2004/10/04 13:10:14

  Modified:    jasper2/src/share/org/apache/jasper/compiler Tag:
                        tomcat_4_branch JspDocumentParser.java
                        ParserController.java
  Log:
  Fix bug 19778. Ensure JSPs in XML form using UTF-8 encoding
  (or any other) are correctly handled.
   - Based on a patch provided by 'marcello'
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.4.2.8   +4 -4      jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java
  
  Index: JspDocumentParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java,v
  retrieving revision 1.4.2.7
  retrieving revision 1.4.2.8
  diff -u -r1.4.2.7 -r1.4.2.8
  --- JspDocumentParser.java	25 Aug 2004 20:53:30 -0000	1.4.2.7
  +++ JspDocumentParser.java	4 Oct 2004 20:10:14 -0000	1.4.2.8
  @@ -76,13 +76,13 @@
        */
       public JspDocumentParser(ParserController pc,
                                String path,
  -                             InputStreamReader reader) {
  +                             InputStream stream) {
           this.parserController = pc;
           this.ctxt = pc.getJspCompilationContext();
           this.taglibs = pc.getCompiler().getPageInfo().getTagLibraries();
           this.err = pc.getCompiler().getErrorDispatcher();
           this.path = path;
  -        this.inputSource = new InputSource(reader);
  +        this.inputSource = new InputSource(stream);
       }
   
       /*
  @@ -92,9 +92,9 @@
        */
       public static Node.Nodes parse(ParserController pc,
                                      String path,
  -                                   InputStreamReader reader,
  +                                   InputStream stream,
                                      Node parent) throws JasperException {
  -        JspDocumentParser handler = new JspDocumentParser(pc, path, reader);
  +        JspDocumentParser handler = new JspDocumentParser(pc, path, stream);
           handler.current = parent;
           Node.Nodes pageNodes = null;
   
  
  
  
  1.4.2.5   +25 -12    jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java
  
  Index: ParserController.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/ParserController.java,v
  retrieving revision 1.4.2.4
  retrieving revision 1.4.2.5
  diff -u -r1.4.2.4 -r1.4.2.5
  --- ParserController.java	25 Aug 2004 20:53:32 -0000	1.4.2.4
  +++ ParserController.java	4 Oct 2004 20:10:14 -0000	1.4.2.5
  @@ -124,6 +124,7 @@
           Node.Nodes parsedPage = null;
           String absFileName = resolveFileName(inFileName);
           String encoding = topFileEncoding;
  +        InputStream stream = null;
           InputStreamReader reader = null;
           try {
               // Figure out what type of JSP document we are dealing with
  @@ -146,11 +147,12 @@
   
               // dispatch to the proper parser
               
  -            reader = getReader(absFileName, encoding);
               if (isXml) {
  +                stream = getStream(absFileName);
                   parsedPage = JspDocumentParser.parse(this, absFileName,
  -                                                     reader, parent);
  +                                                     stream, parent);
               } else {
  +                reader = getReader(absFileName, encoding);
                   JspReader r = new JspReader(ctxt, absFileName, encoding,
                                               reader,
                                               compiler.getErrorDispatcher());
  @@ -164,6 +166,13 @@
                   } catch (Exception any) {
                   }
               }
  +            
  +            if (stream != null) {
  +                try {
  +                    stream.close();
  +                } catch (Exception any) {
  +                }
  +            }
           }
   
           return parsedPage;
  @@ -201,8 +210,8 @@
           newEncoding = null;
   
           // Figure out the encoding of the page
  -        // FIXME: We assume xml parser will take care of
  -        // encoding for page in XML syntax. Correct?
  +        // xml parser will take care of encoding for
  +        // page in XML syntax since we pass it a stream
           if (!isXml) {
               jspReader.reset(startMark);
               while (jspReader.skipUntil("<%@") != null) {
  @@ -253,18 +262,22 @@
           return fileName;
       }
   
  -    private InputStreamReader getReader(String file, String encoding)
  -        throws FileNotFoundException, JasperException
  +    private InputStream getStream(String file)
  +        throws FileNotFoundException
       {
           InputStream in;
  -        InputStreamReader reader;
  +        in = ctxt.getResourceAsStream(file);
  +        if (in == null) {
  +            throw new FileNotFoundException(file);
  +        }
  +        return in;
  +    }
   
  +    private InputStreamReader getReader(String file, String encoding)
  +        throws FileNotFoundException, JasperException
  +    {
           try {
  -            in = ctxt.getResourceAsStream(file);
  -            if (in == null) {
  -                throw new FileNotFoundException(file);
  -            }
  -            return new InputStreamReader(in, encoding);
  +            return new InputStreamReader(getStream(file), encoding);
           } catch (UnsupportedEncodingException ex) {
               throw new JasperException(
                   Constants.getString("jsp.error.unsupported.encoding",
  
  
  

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


Mime
View raw message