You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2001/12/19 22:14:57 UTC
cvs commit: xml-cocoon2/src/org/apache/cocoon/generation JspGenerator.java
vgritsenko 01/12/19 13:14:57
Modified: src/org/apache/cocoon/components/jsp JSPEngineImpl.java
JSPEngineImplNamedDispatcherInclude.java
src/org/apache/cocoon/generation JspGenerator.java
Log:
Fix bug #4239 and #4469: Use UTF-8 encoding between JspGenerator and JSPEngine
Revision Changes Path
1.9 +15 -15 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JSPEngineImpl.java 2001/11/25 18:52:18 1.8
+++ JSPEngineImpl.java 2001/12/19 21:14:57 1.9
@@ -30,6 +30,8 @@
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;
@@ -39,7 +41,7 @@
* functionality - overrides the output method and returns the byte(s).
*
* @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
- * @version CVS $Revision: 1.8 $ $Date: 2001/11/25 18:52:18 $
+ * @version CVS $Revision: 1.9 $ $Date: 2001/12/19 21:14:57 $
*/
public class JSPEngineImpl extends AbstractLoggable
implements JSPEngine, Contextualizable, Composable, Configurable, ThreadSafe, Disposable {
@@ -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.5 +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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JSPEngineImplNamedDispatcherInclude.java 2001/10/11 07:28:17 1.4
+++ JSPEngineImplNamedDispatcherInclude.java 2001/12/19 21:14:57 1.5
@@ -41,7 +41,7 @@
*
* @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
* @author <a href="mailto:bh22351@i-one.at">Bernhard Huber</a>
- * @version CVS $Revision: 1.4 $ $Date: 2001/10/11 07:28:17 $
+ * @version CVS $Revision: 1.5 $ $Date: 2001/12/19 21:14:57 $
*/
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;
}
- }
+ }
}
1.19 +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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- JspGenerator.java 2001/10/11 07:28:21 1.18
+++ JspGenerator.java 2001/12/19 21:14:57 1.19
@@ -32,7 +32,7 @@
* results into SAX events.
*
* @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
- * @version CVS $Revision: 1.18 $ $Date: 2001/10/11 07:28:21 $
+ * @version CVS $Revision: 1.19 $ $Date: 2001/12/19 21:14:57 $
*/
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: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org