cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cross...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp JSPEngineImpl.java
Date Fri, 30 May 2003 15:12:19 GMT
crossley    2003/05/30 08:12:19

  Modified:    src/blocks/jsp/java/org/apache/cocoon/components/jsp
                        JSPEngineImpl.java
  Log:
  Various improvements to the generated JSP page.
  Response charset should be specified with Content-Type.
  PR: 14327
  Submitted By: miyabe.AT.jzf.co.jp (MIYABE Tatsuhiko)
  
  Revision  Changes    Path
  1.3       +39 -8     cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineImpl.java
  
  Index: JSPEngineImpl.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JSPEngineImpl.java	7 May 2003 20:50:05 -0000	1.2
  +++ JSPEngineImpl.java	30 May 2003 15:12:19 -0000	1.3
  @@ -69,12 +69,14 @@
   import java.security.Principal;
   import java.util.Enumeration;
   import java.util.Locale;
  +import java.util.StringTokenizer;
   
   /**
    * Allows JSP to be used as a generator.  Builds upon the JSP servlet
    * functionality - overrides the output method and returns the byte(s).
    *
    * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
  + * @author <a href="mailto:miyabe@jzf.co.jp">MIYABE Tatsuhiko</a>
    * @version CVS $Id$
    */
   public class JSPEngineImpl extends AbstractLogEnabled
  @@ -219,26 +221,50 @@
        */
       class MyServletResponse implements HttpServletResponse {
           HttpServletResponse response;
  -        MyServletOutputStream output;
  +        MyServletOutputStream output = null;
  +        String encoding = "iso-8859-1";
   
           public MyServletResponse(HttpServletResponse response){
               this.response = response;
  -            this.output = new MyServletOutputStream();
           }
           public void flushBuffer() throws IOException { }
           public int getBufferSize() { return 1024; }
           public String getCharacterEncoding() { return this.response.getCharacterEncoding();}
           public Locale getLocale(){ return this.response.getLocale();}
           public PrintWriter getWriter() {
  +            if (this.output == null) {
  +                System.out.println(this.encoding);
  +                this.output = new MyServletOutputStream(this.encoding);
  +            }
               return this.output.getWriter();
           }
           public boolean isCommitted() { return false; }
           public void reset() {}
           public void setBufferSize(int size) {}
           public void setContentLength(int len) {}
  -        public void setContentType(java.lang.String type) {}
  +        public void setContentType(java.lang.String type) {
  +            StringTokenizer st = new StringTokenizer(type, ";,");
  +            st.nextToken();
  +            while (st.hasMoreTokens())  {
  +                String param = st.nextToken();
  +                int equal = param.indexOf("=");
  +                if (equal != -1) {
  +                    String name = param.substring(0, equal);
  +                    if (name.trim().equalsIgnoreCase("charset")) {
  +                        this.encoding = param.substring(equal + 1).trim();
  +                        break;
  +                    }
  +                    continue;
  +                }
  +                break;
  +            }
  +        }
           public void setLocale(java.util.Locale loc) {}
           public ServletOutputStream getOutputStream() {
  +            if (this.output == null) {
  +                System.out.println(this.encoding);
  +                this.output = new MyServletOutputStream(this.encoding);
  +            }
               return this.output;
           }
           public void addCookie(Cookie cookie){ response.addCookie(cookie); }
  @@ -267,7 +293,12 @@
           public void resetBuffer(){}
   
           public byte[] toByteArray() {
  -            return output.toByteArray();
  +            if (this.output != null) {
  +                return output.toByteArray();
  +            }
  +            else {
  +                return new byte[0];
  +            }
           }
       }
   
  @@ -278,12 +309,12 @@
           ByteArrayOutputStream output;
           PrintWriter writer;
   
  -        public MyServletOutputStream() {
  +        public MyServletOutputStream(String encoding) {
               this.output = new ByteArrayOutputStream();
               try {
  -                this.writer = new PrintWriter(new OutputStreamWriter(output, "utf-8"));
  +                this.writer = new PrintWriter(new OutputStreamWriter(output, encoding));
               } catch (UnsupportedEncodingException e) {
  -                // This can't be true: JVM must support UTF-8 encoding.
  +                // This can't be true: JVM must support the encoding.
                   this.writer = new PrintWriter(new OutputStreamWriter(output));
               }
           }
  
  
  

Mime
View raw message