You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by dd...@apache.org on 2005/02/10 03:02:31 UTC
svn commit: r153141 - in
portals/pluto/trunk/container/src/java/org/apache/pluto:
core/impl/PortletResponseImpl.java util/PrintWriterServletOutputStream.java
Author: ddewolf
Date: Wed Feb 9 18:02:30 2005
New Revision: 153141
URL: http://svn.apache.org/viewcvs?view=rev&rev=153141
Log:
Resolving PLUTO-100
-- Handle Character Encoding in PrintWriterServletOutputStream.java
-- Deprecate the constructor that does not take the encoding.
Modified:
portals/pluto/trunk/container/src/java/org/apache/pluto/core/impl/PortletResponseImpl.java
portals/pluto/trunk/container/src/java/org/apache/pluto/util/PrintWriterServletOutputStream.java
Modified: portals/pluto/trunk/container/src/java/org/apache/pluto/core/impl/PortletResponseImpl.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/container/src/java/org/apache/pluto/core/impl/PortletResponseImpl.java?view=diff&r1=153140&r2=153141
==============================================================================
--- portals/pluto/trunk/container/src/java/org/apache/pluto/core/impl/PortletResponseImpl.java (original)
+++ portals/pluto/trunk/container/src/java/org/apache/pluto/core/impl/PortletResponseImpl.java Wed Feb 9 18:02:30 2005
@@ -260,7 +260,10 @@
if (wrappedWriter == null)
{
- wrappedWriter = new PrintWriterServletOutputStream(_getHttpServletResponse().getWriter());
+ wrappedWriter = new PrintWriterServletOutputStream(
+ _getHttpServletResponse().getWriter(),
+ _getHttpServletResponse().getCharacterEncoding()
+ );
}
usingStream = true;
Modified: portals/pluto/trunk/container/src/java/org/apache/pluto/util/PrintWriterServletOutputStream.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/container/src/java/org/apache/pluto/util/PrintWriterServletOutputStream.java?view=diff&r1=153140&r2=153141
==============================================================================
--- portals/pluto/trunk/container/src/java/org/apache/pluto/util/PrintWriterServletOutputStream.java (original)
+++ portals/pluto/trunk/container/src/java/org/apache/pluto/util/PrintWriterServletOutputStream.java Wed Feb 9 18:02:30 2005
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
import javax.servlet.ServletOutputStream;
@@ -40,16 +41,41 @@
PrintWriter mPrintWriter;
/**
+ * The character encoding of the response.
+ */
+ private String characterEncoding;
+
+ /**
+ * @deprecated since 1.0RC3; use PrintWriterServletOutputStream
+ * <p>
* Construct a ServletOutputStream that coordinates output using a base
* ServletOutputStream and a PrintWriter that is wrapped on top of that
* OutputStream.
+ * </p>
*/
public PrintWriterServletOutputStream(PrintWriter pO)
{
- super();
- mPrintWriter = pO;
+ this(pO, null);
+ }
+
+ public PrintWriterServletOutputStream(PrintWriter pw, String encoding)
+ {
+ super();
+ mPrintWriter = pw;
+ characterEncoding = encoding;
}
+
+ /**
+ * Writes a single byte to the output stream
+ * This implementation writes the byte to the
+ * underlying PrintWriter.
+ */
+ public void write(int pVal) throws IOException
+ {
+ mPrintWriter.write(pVal);
+ }
+
/**
* Writes an array of bytes
*
@@ -58,22 +84,13 @@
*/
public void write(byte[] pBuf) throws IOException
{
- char[] cbuf = new char[pBuf.length];
- for (int i = 0; i < cbuf.length; i++)
- cbuf[i] = (char)(pBuf[i] & 0xff);
- mPrintWriter.write(cbuf, 0, pBuf.length);
- }
-
- /**
- * Writes a single byte to the output stream
- */
- public void write(int pVal) throws IOException
- {
- mPrintWriter.write(pVal);
+ this.write(pBuf, 0, pBuf.length);
}
/**
* Writes a subarray of bytes
+ * This implementation redirects it's input into the
+ * underlying PrintWriter.
*
* @param pBuf the array to be written
* @param pOffset the offset into the array
@@ -82,15 +99,26 @@
*/
public void write(byte[] pBuf, int pOffset, int pLength) throws IOException
{
- char[] cbuf = new char[pLength];
- for (int i = 0; i < pLength; i++)
- cbuf[i] = (char)(pBuf[i + pOffset] & 0xff);
- mPrintWriter.write(cbuf, 0, pLength);
+ String strValue = null;
+ if(characterEncoding != null && !"".equals(characterEncoding)) {
+ try {
+ strValue = new String(pBuf, pOffset, pLength, characterEncoding);
+ }
+ catch(UnsupportedEncodingException uee) {
+ // ignore and allow the null to handle.
+ }
+ }
+
+ if(strValue == null) {
+ strValue = new String(pBuf, pOffset, pLength);
+ }
+
+ mPrintWriter.write(strValue);
}
/**
* Flushes the stream, writing any buffered output bytes
- *
+ *
* @exception IOException if an I/O error occurred
*/
public void flush() throws IOException