You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jv...@locus.apache.org on 2000/11/04 03:41:37 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/servlet VelocityServlet.java
jvanzyl 00/11/03 18:41:37
Modified: src/java/org/apache/velocity/servlet VelocityServlet.java
Log:
- update servlet to use JspWriter.
Revision Changes Path
1.12 +12 -25 jakarta-velocity/src/java/org/apache/velocity/servlet/VelocityServlet.java
Index: VelocityServlet.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/servlet/VelocityServlet.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- VelocityServlet.java 2000/11/03 23:26:50 1.11
+++ VelocityServlet.java 2000/11/04 02:41:36 1.12
@@ -56,6 +56,9 @@
import java.io.IOException;
import java.io.PrintWriter;
+import java.io.Writer;
+import java.io.BufferedWriter;
+import java.io.OutputStreamWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@@ -93,7 +96,7 @@
*
* @author Dave Bryson
* @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
- * $Id: VelocityServlet.java,v 1.11 2000/11/03 23:26:50 jon Exp $
+ * $Id: VelocityServlet.java,v 1.12 2000/11/04 02:41:36 jvanzyl Exp $
*/
public abstract class VelocityServlet extends HttpServlet
{
@@ -202,8 +205,9 @@
throws ServletException, IOException
{
ServletOutputStream output = response.getOutputStream();
- CharToByteBufferWriter buffer = null;
String contentType = null;
+ Writer vw = null;
+
try
{
// create a new context
@@ -230,22 +234,10 @@
if ( template == null )
throw new Exception ("Cannot find the template!" );
- // create the output buffer
- InternedCharToByteBuffer ictbb = new InternedCharToByteBuffer(
- new DefaultCharToByteBuffer(new DefaultByteBuffer(), encoding));
- buffer = new CharToByteBufferWriter (ictbb);
-
- // merge the context with the template and output in the buffer
- template.merge( context, buffer );
-
- // set the content length
- long length = ictbb.getByteCount();
- if (length <= Integer.MAX_VALUE)
- {
- response.setContentLength((int)length);
- }
+ //Writer vw = new BufferedWriter(new OutputStreamWriter(output));
+ vw = new JspWriterImpl(response);
+ template.merge( context, vw);
- ictbb.writeTo(output);
}
catch (Exception e)
{
@@ -256,15 +248,10 @@
{
try
{
- // flush and close
- if (buffer != null)
- {
- buffer.close();
- }
- if (output != null)
+ if (vw != null)
{
- output.flush();
- output.close();
+ vw.flush();
+ vw.close();
}
}
catch (Exception e)