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 Response.java
Date Thu, 03 Feb 2000 02:57:45 GMT
mandar      00/02/02 18:57:45

  Modified:    src/share/org/apache/jasper/compiler Tag: latest_TOMCAT_30
                        Compiler.java JspReader.java
               src/share/org/apache/tomcat/core Tag: latest_TOMCAT_30
                        Response.java
  Log:
  Supporting other encodings and setting the headers.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.3.2.1   +75 -6     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.3
  retrieving revision 1.3.2.1
  diff -u -r1.3 -r1.3.2.1
  --- Compiler.java	1999/11/03 23:43:02	1.3
  +++ Compiler.java	2000/02/03 02:57:44	1.3.2.1
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v
1.3 1999/11/03 23:43:02 costin Exp $
  - * $Revision: 1.3 $
  - * $Date: 1999/11/03 23:43:02 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java,v
1.3.2.1 2000/02/03 02:57:44 mandar Exp $
  + * $Revision: 1.3.2.1 $
  + * $Date: 2000/02/03 02:57:44 $
    *
    * ====================================================================
    * 
  @@ -66,6 +66,8 @@
   import java.io.ByteArrayOutputStream;
   import java.io.FileOutputStream;
   
  +import java.util.Hashtable;
  +
   import org.apache.jasper.JspEngineContext;
   import org.apache.jasper.Constants;
   import org.apache.jasper.JasperException;
  @@ -119,13 +121,42 @@
                             new Object[] { classFileName },
                             Constants.MED_VERBOSITY);
   
  -        JspReader reader = JspReader.createJspReader(ctxt.getJspFile(), ctxt.getServletContext());
  +        
  +        // Need the encoding specified in the JSP 'page' directive for
  +        //  - reading the JSP page
  +        //  - writing the JSP servlet source
  +        //  - compiling the generated servlets (pass -encoding to javac).
  +        // XXX - There are really three encodings of interest.
  +
  +        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.
  +
  +	// specifies whether the JSP contains a non-default encoding to
  +	// save this agony (two-phase parsing).
  +	
  +	if (true) {
  +	    JspReader tmpReader = JspReader.createJspReader(
  +							    ctxt.getJspFile(),
  +							    ctxt.getServletContext(),
  +							    jspEncoding);
  +	    String newEncode = changeEncodingIfNecessary(tmpReader);
  +	    if (newEncode != null) jspEncoding = newEncode;
  +							 
  +	}	
  +
  +        JspReader reader = JspReader.createJspReader(ctxt.getJspFile(),
  +						     ctxt.getServletContext(),
  +						     jspEncoding);
   
           ServletWriter writer = 
               (new ServletWriter
                   (new PrintWriter
  -                    (new EscapeUnicodeWriter
  -                        (new FileOutputStream(javaFileName)))));
  +                    (new java.io.OutputStreamWriter
  +                        (new FileOutputStream(javaFileName), javaEncoding))));
   
           ctxt.setReader(reader);
           ctxt.setWriter(writer);
  @@ -259,4 +290,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.5.2.1   +6 -5      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.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- JspReader.java	1999/12/15 01:15:50	1.5
  +++ JspReader.java	2000/02/03 02:57:44	1.5.2.1
  @@ -184,7 +184,7 @@
                       throw new FileNotFoundException(fileName);
                   
                   try {
  -                    reader = new InputStreamReader(in);
  +                    reader = new InputStreamReader(in, encoding);
                   } catch (Exception ex) {
                       throw new FileNotFoundException(fileName + ": "+ ex.getMessage());
                   }
  @@ -239,17 +239,18 @@
   	return true;
       }
   	
  -    protected JspReader(String file, ServletContext ctx) 
  +    protected JspReader(String file, ServletContext ctx, String encoding) 
   	throws ParseException, FileNotFoundException
       {
           this.context = ctx;
  -	pushFile(file, null);
  +	pushFile(file, encoding);
       }
   
  -    public static JspReader createJspReader(String file, ServletContext ctx) 
  +    public static JspReader createJspReader(String file, ServletContext ctx,
  +					    String encoding) 
   	throws ParseException, FileNotFoundException
       {
  -	return new JspReader(file, ctx);
  +	return new JspReader(file, ctx, encoding);
       }
   
       public boolean hasMoreInput() {
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.4.2.1   +7 -3      jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java
  
  Index: Response.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- Response.java	1999/12/14 00:15:36	1.4
  +++ Response.java	2000/02/03 02:57:45	1.4.2.1
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.4
1999/12/14 00:15:36 costin Exp $
  - * $Revision: 1.4 $
  - * $Date: 1999/12/14 00:15:36 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.4.2.1
2000/02/03 02:57:45 mandar Exp $
  + * $Revision: 1.4.2.1 $
  + * $Date: 2000/02/03 02:57:45 $
    *
    * ====================================================================
    *
  @@ -427,6 +427,8 @@
           // Use the setContentType() method so encoding is set properly
           String newType = constructLocalizedContentType(contentType, locale);
           setContentType(newType);
  +
  +	addHeader("Content-Language", contentLanguage);
       }
   
       String constructLocalizedContentType(String type, Locale loc) {
  @@ -455,10 +457,12 @@
           if (encoding != null) {
   	    characterEncoding = encoding;
           }
  +	addHeader("Content-Type", contentType);
       }
   
       public void setContentLength(int contentLength) {
   	this.contentLength = contentLength;
  +	addHeader("Content-Length", (new Integer(contentLength)).toString());
       }
       
       public int getStatus() {
  
  
  

Mime
View raw message