dims 01/05/01 09:47:29
Modified: src/org/apache/cocoon/generation Tag: xml-cocoon2
JspGenerator.java
Log:
JspGenerator Fixes for Tomcat 4.0 latest Nightly build. Make sure you
add jasper-compiler.jar and servlet.jar into xml-cocoon\lib before you build.
Revision Changes Path
No revision
No revision
1.1.2.4 +26 -13
xml-cocoon/src/org/apache/cocoon/generation/Attic/JspGenerator.java
Index: JspGenerator.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/JspGenerator.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- JspGenerator.java 2001/05/01 14:41:34 1.1.2.3
+++ JspGenerator.java 2001/05/01 16:47:28 1.1.2.4
@@ -49,7 +49,7 @@
* results into SAX events.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
- * @version CVS $Revision: 1.1.2.3 $ $Date: 2001/05/01 14:41:34 $
+ * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/05/01 16:47:28 $
*/
public class JspGenerator extends ServletGenerator implements Poolable {
@@ -71,18 +71,17 @@
Parser parser = null;
try {
- ByteArrayOutputStream output = new ByteArrayOutputStream();
MyServletRequest request = new MyServletRequest(httpRequest,
this.source);
- MyServletResponse response = new MyServletResponse(httpResponse,
output);
+ MyServletResponse response = new MyServletResponse(httpResponse);
// start JSPServlet.
Class clazz =
Class.forName("org.apache.jasper.servlet.JspServlet");
HttpServlet jsp = (HttpServlet) clazz.newInstance();
jsp.init(new
config((ServletContext)this.objectModel.get(HttpEnvironment.HTTP_SERVLET_CONTEXT)));
jsp.service(request, response);
- output.close();
- ByteArrayInputStream input = new
ByteArrayInputStream(output.toByteArray());
+ byte[] bytes = response.toByteArray();
+ ByteArrayInputStream input = new ByteArrayInputStream(bytes);
// pipe the results into the parser
parser = (Parser)this.manager.lookup(Roles.PARSER);
@@ -192,19 +191,19 @@
* Stub implementation of HttpServletResponse
*/
class MyServletResponse implements HttpServletResponse {
- ServletOutputStream output;
HttpServletResponse response;
+ MyServletOutputStream output;
- public MyServletResponse(HttpServletResponse response, OutputStream
output){
+ public MyServletResponse(HttpServletResponse response){
this.response = response;
- this.output = new MyServletOutputStream(output);
+ this.output = new MyServletOutputStream();
}
- public void flushBuffer() throws IOException { this.output.flush(); }
+ 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() {
- return new PrintWriter(this.output);
+ return this.output.getWriter();
}
public boolean isCommitted() { return false; }
public void reset() {}
@@ -237,16 +236,25 @@
public void setStatus(int i, String s){response.setStatus(i, s); }
public void resetBuffer(){}
+ public byte[] toByteArray() {
+ return output.toByteArray();
+ }
}
/**
* Stub implementation of ServletOutputStream
*/
class MyServletOutputStream extends ServletOutputStream {
- OutputStream output;
- public MyServletOutputStream(OutputStream output) {
- this.output = output;
+ ByteArrayOutputStream output;
+ PrintWriter writer;
+
+ public MyServletOutputStream() {
+ this.output = new ByteArrayOutputStream();
+ this.writer = new PrintWriter(output, true);
}
+ public PrintWriter getWriter() {
+ return this.writer;
+ }
public void write(byte[] b) throws java.io.IOException {
output.write(b);
}
@@ -255,6 +263,11 @@
}
public void write(int b) throws java.io.IOException {
output.write(b);
+ }
+ public byte[] toByteArray() {
+ this.writer.flush();
+ byte[] bytes = output.toByteArray();
+ return bytes;
}
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]