tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From man...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/core ResponseImpl.java
Date Thu, 03 Feb 2000 02:13:14 GMT
mandar      00/02/02 18:13:14

  Modified:    src/share/org/apache/jasper/compiler Compiler.java
               src/share/org/apache/tomcat/core ResponseImpl.java
  Log:
  1) To support multiple encodings (and not just the default),
     we scan the JSP file for a contentType directive. If one
     is found then we initialize the JspReader with the
     encoding present in the directive.
  
     This is inefficient as it needs a two-pass parser, but
     solves the bigger problem of multiple encodings (Japanese
     and others).
  
  2) While fixing this problem, I noticed that the "Content-Type"
     , "Content-Length" and "Content-Language" HTTP headers
     were not set.
  
  Revision  Changes    Path
  1.9       +59 -3     jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java
  
  Index: Compiler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Compiler.java	2000/01/24 05:54:50	1.8
  +++ Compiler.java	2000/02/03 02:13:12	1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v
1.8 2000/01/24 05:54:50 shemnon Exp $
  - * $Revision: 1.8 $
  - * $Date: 2000/01/24 05:54:50 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v
1.9 2000/02/03 02:13:12 mandar Exp $
  + * $Revision: 1.9 $
  + * $Date: 2000/02/03 02:13:12 $
    *
    * ====================================================================
    * 
  @@ -60,6 +60,7 @@
    */ 
   package org.apache.jasper.compiler;
   
  +import java.util.Hashtable;
   import java.io.FileNotFoundException;
   import java.io.File;
   import java.io.PrintWriter;
  @@ -69,6 +70,7 @@
   import org.apache.jasper.JspCompilationContext;
   import org.apache.jasper.Constants;
   import org.apache.jasper.JasperException;
  +import org.apache.jasper.compiler.ParseException;
   
   /**
    * If you want to customize JSP compilation aspects, this class is
  @@ -79,6 +81,7 @@
    * change. 
    *
    * @author Anil K. Vijendran
  + * @author Mandar Raje
    */
   public abstract class Compiler {
       protected JavaCompiler javac;
  @@ -132,6 +135,21 @@
           String jspEncoding = "8859_1";          // default per JSP spec
           String javaEncoding = "UTF8";           // perhaps debatable?
   
  +	// This seems to be a reasonable point to scan the JSP file
  +	// for a 'contentType' directive. If it found then the set
  +	// the value of 'jspEncoding to reflect the value specified.
  +	// Note: if (true) is convenience programming. It can be
  +	// taken out once we have a more efficient method.
  +
  +	if (true) {
  +	    JspReader tmpReader = JspReader.createJspReader(
  +							    ctxt.getJspFile(),
  +							    ctxt,
  +							    jspEncoding);
  +	    String newEncode = changeEncodingIfNecessary(tmpReader);
  +	    if (newEncode != null) jspEncoding = newEncode;
  +	}
  +
           JspReader reader = JspReader.createJspReader(
               ctxt.getJspFile(),
               ctxt,
  @@ -256,4 +274,42 @@
       public void setMangler(Mangler mangler) {
           this.mangler = mangler;
       }
  +
  +    /**
  +     * Change the encoding for the reader if specified.
  +     */
  +    public String changeEncodingIfNecessary(JspReader tmpReader) {
  +
  +	// A lot of code replicated from Parser.java
  +	// Main aim is to "get-it-to-work".
  +	while (tmpReader.skipUntil("<%@") != null) {
  +
  +	    tmpReader.skipSpaces();
  +
  +	    // check if it is a page directive.
  +	    if (tmpReader.matches("page")) {
  +
  +		tmpReader.advance(4);
  +		tmpReader.skipSpaces();
  +		
  +		try {
  +		    Hashtable attrs = tmpReader.parseTagAttributes();
  +		    String ct = (String) attrs.get("contentType");
  +		    if (ct != null) {
  +			int loc = ct.indexOf("charset=");
  +			if (loc > 0) {
  +			    String encoding = ct.substring(loc + 8);
  +			    return encoding;
  +			}
  +		    }
  +		} catch (ParseException ex) {
  +		    // Ignore the exception here, it will be caught later.
  +		    return null;
  +		}
  +	    }
  +	}
  +	return null;
  +    }
   }
  +
  +
  
  
  
  1.12      +7 -3      jakarta-tomcat/src/share/org/apache/tomcat/core/ResponseImpl.java
  
  Index: ResponseImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ResponseImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ResponseImpl.java	2000/02/01 21:39:39	1.11
  +++ ResponseImpl.java	2000/02/03 02:13:13	1.12
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ResponseImpl.java,v
1.11 2000/02/01 21:39:39 costin Exp $
  - * $Revision: 1.11 $
  - * $Date: 2000/02/01 21:39:39 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ResponseImpl.java,v
1.12 2000/02/03 02:13:13 mandar Exp $
  + * $Revision: 1.12 $
  + * $Date: 2000/02/03 02:13:13 $
    *
    * ====================================================================
    *
  @@ -327,6 +327,8 @@
           // Use the setContentType() method so encoding is set properly
           String newType = constructLocalizedContentType(contentType, locale);
           setContentType(newType);
  +
  +	addHeader("Content-Language", contentLanguage);
       }
   
       /** Utility method for parsing the mime type and setting
  @@ -358,6 +360,7 @@
           if (encoding != null) {
   	    characterEncoding = encoding;
           }
  +	addHeader("Content-Type", contentType);
       }
   
       public String getContentType() {
  @@ -366,6 +369,7 @@
       
       public void setContentLength(int contentLength) {
   	this.contentLength = contentLength;
  +	addHeader("Content-Length", (new Integer(contentLength)).toString());
       }
   
       public int getContentLength() {
  
  
  

Mime
View raw message