pierred 00/12/22 11:33:08 Modified: src/share/org/apache/jasper/compiler Tag: tomcat_32 JspParseEventListener.java JspReader.java Log: Fix for Bug #55. (tomcat_32) ----- Synopsis: Default for included files is 8859_1, with no option to set otherwise. Report Description: The default for reading an included file is ISO_8859_1. We can, of course, set pageConent to read UTF-8 (which is what we need it to be to support international code). Unfortunately, when there are two or more levels of encoding (or the pageContent type ins't set), the encoding that the JspReader gets set to a hard-coded "ISO_8859_1", and doesn't allow this to be set to anything else via the runtime system properties. In: org.apache.jasper.compiler.JspReader JspReader.java line 158, encoding ALWAYS defaults to 8859_1, and the file.encoding, when set from the System properties. This is an easy fix, to set encoding to: encoding = System.getPropert("file.encoding","8859_1") ; The result, typically, is that the file will flake out and convert all of the non-UTF-8 characters to US-ASCII, @%, etc. ----- I'm not sure I fully understand what's described there, so here is what I believe should be done. The "encoding" for a JSP file is currently handled as follows: 1. In Compiler.java, we create a JspReader for the top-level ("including") jsp file using the 8859_1 encoding. 2. Using that JspReader, we check if there is a page directive with 'contentType' specified. If there is, then a new JspReader for the page is created with the encoding set to the "charset" specified in the contentType value of the page directive; otherwise we stick with the default 8859_1 encoding. 3. When a page is included, JspReader.pushFile() is called, and the encoding passed as argument appears to always be null (since no encoding attribute can be specified in the "include" directive, reading 'encoding' off of the attributes appears to be a bug in JspParseEventListener). Because it is null, it always defaults to 8859_1. If I understand well the intent of the bug report, we'd need the following modifications: - In step 2, if contentType is not specified in the "including" page, set the encoding to be: encoding = System.getProperty("file.encoding", "8859_1"); This means that the default encoding of all JSP files at a site could be defined globally using system property "file.encoding". I don't think this is spec-compliant, and would be reluctant to make that change. --> Change not done Comments from Hans Bergsten "I agree that using "file.encoding" as the ultimate default is not spec compliant. I suggest you stick to the current behavior, with "8859_1" if contentType doesn't specify a charset." - In step 3, use the encoding of the "including" page. This would fix what I believe is a bug in the current implementation. --> Change done Submitted by: [EMAIL PROTECTED] Revision Changes Path No revision No revision 1.17.2.3 +4 -6 jakarta-tomcat/src/share/org/apache/jasper/compiler/JspParseEventListener.java Index: JspParseEventListener.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v retrieving revision 1.17.2.2 retrieving revision 1.17.2.3 diff -u -r1.17.2.2 -r1.17.2.3 --- JspParseEventListener.java 2000/12/21 23:25:27 1.17.2.2 +++ JspParseEventListener.java 2000/12/22 19:33:08 1.17.2.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v 1.17.2.2 2000/12/21 23:25:27 pierred Exp $ - * $Revision: 1.17.2.2 $ - * $Date: 2000/12/21 23:25:27 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v 1.17.2.3 2000/12/22 19:33:08 pierred Exp $ + * $Revision: 1.17.2.3 $ + * $Date: 2000/12/22 19:33:08 $ * * ==================================================================== * @@ -717,15 +717,13 @@ if (directive.equals("include")) { String file = (String) attrs.get("file"); - String encoding = (String) attrs.get("encoding"); - if (file == null) throw new CompileException(start, Constants.getString("jsp.error.include.missing.file")); // jsp.error.include.bad.file needs taking care of here?? try { - reader.pushFile(file, encoding); + reader.pushFile(file); } catch (FileNotFoundException fnfe) { throw new CompileException(start, Constants.getString("jsp.error.include.bad.file")); 1.16.2.6 +21 -1 jakarta-tomcat/src/share/org/apache/jasper/compiler/JspReader.java Index: JspReader.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/JspReader.java,v retrieving revision 1.16.2.5 retrieving revision 1.16.2.6 diff -u -r1.16.2.5 -r1.16.2.6 --- JspReader.java 2000/11/16 22:10:35 1.16.2.5 +++ JspReader.java 2000/12/22 19:33:08 1.16.2.6 @@ -95,6 +95,13 @@ LogHelper loghelper = new LogHelper("JASPER_LOG", "JspReader"); + /* + * Default encoding used. The JspReader is created with the + * "top file" encoding. This is then the encoding used for the + * included files (same translation unit). + */ + private String encoding = null; + public String getFile(int fileid) { return (String) sourceFiles.elementAt(fileid); } @@ -132,6 +139,17 @@ * Push a new file onto the stack. * The name of the file is resolved to a fully qualified filename. * @param name The name of the file. + */ + public void pushFile(String name) + throws ParseException, FileNotFoundException + { + pushFile(name, this.encoding); + } + + /** + * Push a new file onto the stack. + * The name of the file is resolved to a fully qualified filename. + * @param name The name of the file. * @param encoding The optional encoding for the file. */ public void pushFile(String name, String encoding) @@ -160,7 +178,7 @@ { // Default encoding if needed: if (encoding == null) { - encoding = "8859_1"; + encoding = this.encoding; // XXX - longer term, this should really be: // System.getProperty("file.encoding", "8859_1"); // but this doesn't work right now, so we stick with ASCII @@ -259,6 +277,8 @@ throws ParseException, FileNotFoundException { this.context = ctx; + this.encoding = encoding; + if (this.encoding == null) this.encoding = "8859_1"; pushFile(file, encoding); }