vgritsenko 01/12/19 13:17:55 Modified: src/org/apache/cocoon/components/jsp Tag: cocoon_20_branch JSPEngineImpl.java JSPEngineImplNamedDispatcherInclude.java src/org/apache/cocoon/generation Tag: cocoon_20_branch JspGenerator.java Log: Fix bug #4239 and #4469: Use UTF-8 encoding between JspGenerator and JSPEngine Revision Changes Path No revision No revision 1.1.2.6 +17 -17 xml-cocoon2/src/org/apache/cocoon/components/jsp/JSPEngineImpl.java Index: JSPEngineImpl.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/jsp/JSPEngineImpl.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- JSPEngineImpl.java 2001/10/11 08:56:05 1.1.2.5 +++ JSPEngineImpl.java 2001/12/19 21:17:55 1.1.2.6 @@ -30,18 +30,20 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintWriter; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; import java.security.Principal; import java.util.Enumeration; import java.util.Locale; /** * Allows JSP to be used as a generator. Builds upon the JSP servlet - * functionality - overrides the output method and returns the byte(s). + * functionality - overrides the output method and returns the byte(s). * * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a> - * @version CVS $Revision: 1.1.2.5 $ $Date: 2001/10/11 08:56:05 $ + * @version CVS $Revision: 1.1.2.6 $ $Date: 2001/12/19 21:17:55 $ */ -public class JSPEngineImpl extends AbstractLoggable +public class JSPEngineImpl extends AbstractLoggable implements JSPEngine, Contextualizable, Composable, Configurable, ThreadSafe, Disposable { /** The Servlet Include Path */ @@ -91,9 +93,8 @@ * @exception Exception */ public byte[] executeJSP(String url, HttpServletRequest httpRequest, HttpServletResponse httpResponse, ServletContext context) - throws IOException, ServletException/*, SAXException*/, Exception { + throws IOException, ServletException, Exception { -// Parser parser = null; byte[] bytes = null; MyServletRequest request = new MyServletRequest(httpRequest, url); @@ -106,7 +107,6 @@ jsp.service(request, response); bytes = response.toByteArray(); -// ByteArrayInputStream input = new ByteArrayInputStream(bytes); // clean up jsp.destroy(); @@ -201,7 +201,7 @@ public String getRealPath(String s){ return request.getRealPath(s); } public java.lang.StringBuffer getRequestURL() { return null; } public java.util.Map getParameterMap() { return null; } - public void setCharacterEncoding(java.lang.String $1) { } + public void setCharacterEncoding(java.lang.String s) { } } /** @@ -267,24 +267,24 @@ public MyServletOutputStream() { this.output = new ByteArrayOutputStream(); - this.writer = new PrintWriter(output, true); + try { + this.writer = new PrintWriter(new OutputStreamWriter(output, "utf-8")); + } catch (UnsupportedEncodingException e) { + // This can't be true: JVM must support UTF-8 encoding. + this.writer = new PrintWriter(new OutputStreamWriter(output)); + } } public PrintWriter getWriter() { return this.writer; } - public void write(byte[] b) throws java.io.IOException { - output.write(b); + public void write(int b) throws IOException { + // This method is not used but have to be implemented + this.writer.write(b); } - public void write(byte[] b, int off, int len) throws java.io.IOException { - output.write(b,off,len); - } - public void write(int b) throws java.io.IOException { - output.write(b); - } public byte[] toByteArray() { this.writer.flush(); byte[] bytes = output.toByteArray(); return bytes; } - } + } } 1.2.2.4 +11 -11 xml-cocoon2/src/org/apache/cocoon/components/jsp/JSPEngineImplNamedDispatcherInclude.java Index: JSPEngineImplNamedDispatcherInclude.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/jsp/JSPEngineImplNamedDispatcherInclude.java,v retrieving revision 1.2.2.3 retrieving revision 1.2.2.4 diff -u -r1.2.2.3 -r1.2.2.4 --- JSPEngineImplNamedDispatcherInclude.java 2001/10/11 08:56:05 1.2.2.3 +++ JSPEngineImplNamedDispatcherInclude.java 2001/12/19 21:17:55 1.2.2.4 @@ -41,7 +41,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a> * @author <a href="mailto:[EMAIL PROTECTED]">Bernhard Huber</a> - * @version CVS $Revision: 1.2.2.3 $ $Date: 2001/10/11 08:56:05 $ + * @version CVS $Revision: 1.2.2.4 $ $Date: 2001/12/19 21:17:55 $ */ public class JSPEngineImplNamedDispatcherInclude extends AbstractLoggable implements JSPEngine, Contextualizable, Composable, Configurable, ThreadSafe, Disposable { @@ -193,7 +193,7 @@ public String getRealPath(String s){ return request.getRealPath(s); } public java.lang.StringBuffer getRequestURL() { return null; } public java.util.Map getParameterMap() { return null; } - public void setCharacterEncoding(java.lang.String $1) { } + public void setCharacterEncoding(java.lang.String s) { } } /** @@ -259,25 +259,25 @@ public MyServletOutputStream() { this.output = new ByteArrayOutputStream(); - this.writer = new PrintWriter(output, true); + try { + this.writer = new PrintWriter(new OutputStreamWriter(output, "utf-8")); + } catch (UnsupportedEncodingException e) { + // This can't be true: JVM must support UTF-8 encoding. + this.writer = new PrintWriter(new OutputStreamWriter(output)); + } } public PrintWriter getWriter() { return this.writer; } - public void write(byte[] b) throws java.io.IOException { - output.write(b); - } - public void write(byte[] b, int off, int len) throws java.io.IOException { - output.write(b,off,len); - } public void write(int b) throws java.io.IOException { - output.write(b); + // This method is not used but have to be implemented + this.writer.write(b); } public byte[] toByteArray() { this.writer.flush(); byte[] bytes = output.toByteArray(); return bytes; } - } + } } No revision No revision 1.6.2.13 +6 -3 xml-cocoon2/src/org/apache/cocoon/generation/JspGenerator.java Index: JspGenerator.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/generation/JspGenerator.java,v retrieving revision 1.6.2.12 retrieving revision 1.6.2.13 diff -u -r1.6.2.12 -r1.6.2.13 --- JspGenerator.java 2001/10/11 08:56:12 1.6.2.12 +++ JspGenerator.java 2001/12/19 21:17:55 1.6.2.13 @@ -32,7 +32,7 @@ * results into SAX events. * * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a> - * @version CVS $Revision: 1.6.2.12 $ $Date: 2001/10/11 08:56:12 $ + * @version CVS $Revision: 1.6.2.13 $ $Date: 2001/12/19 21:17:55 $ */ public class JspGenerator extends ServletGenerator implements Recyclable, Configurable { @@ -72,12 +72,15 @@ engine = (JSPEngine)this.manager.lookup(JSPEngine.ROLE); byte[] bytes = engine.executeJSP(url, httpRequest, httpResponse, httpContext); - ByteArrayInputStream input = new ByteArrayInputStream(bytes); + // explicitly specify bytestream encoding + InputSource input = new InputSource(new ByteArrayInputStream(bytes)); + input.setEncoding("utf-8"); + // pipe the results into the parser parser = (Parser)this.manager.lookup(Parser.ROLE); parser.setConsumer(this.xmlConsumer); - parser.parse(new InputSource(input)); + parser.parse(input); } catch (ServletException e) { getLogger().debug("ServletException in JspGenerator.generate()", e); getLogger().debug("Embedded ServletException JspGenerator.generate()", e.getRootCause());
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]