Re: [xwiki-devs] [xwiki-notifications] r22420 - in platform/core/trunk/xwiki-containers: xwiki-container-api/src/main/java/org/xwiki/container xwiki-container-portlet/src/main/java/org/xwiki/container/portlet xwiki-container-servlet/src/main/java/org/xwiki/container/servlet
On Aug 8, 2009, at 12:42 PM, sdumitriu (SVN) wrote:
Author: sdumitriu Date: 2009-08-08 12:42:34 +0200 (Sat, 08 Aug 2009) New Revision: 22420
Modified: platform/core/trunk/xwiki-containers/xwiki-container-api/src/main/ java/org/xwiki/container/Response.java platform/core/trunk/xwiki-containers/xwiki-container-portlet/src/ main/java/org/xwiki/container/portlet/PortletResponse.java platform/core/trunk/xwiki-containers/xwiki-container-servlet/src/ main/java/org/xwiki/container/servlet/ServletResponse.java Log: XWIKI-4134: Add methods for writing content to the Response component Done.
Modified: platform/core/trunk/xwiki-containers/xwiki-container-api/ src/main/java/org/xwiki/container/Response.java =================================================================== --- platform/core/trunk/xwiki-containers/xwiki-container-api/src/ main/java/org/xwiki/container/Response.java 2009-08-08 00:04:58 UTC (rev 22419) +++ platform/core/trunk/xwiki-containers/xwiki-container-api/src/ main/java/org/xwiki/container/Response.java 2009-08-08 10:42:34 UTC (rev 22420) @@ -20,6 +20,32 @@ */ package org.xwiki.container;
+import java.io.IOException; +import java.io.OutputStream; + public interface Response { + /** + * Returns an OutputStream suitable for writing binary data in the response. + * + * @return the binary OutputStream for the response, or {@code null} if the response does not allow writing data + * @throws IOException if an output exception occurred + */ + OutputStream getOutputStream() throws IOException; + + /** + * Sets the length of the content body in the response. If this length is not relevant to the type of connection, it + * will simply be ignored. + * + * @param length an integer specifying the length of the content being returned to the client + */ + void setContentLength(int length); + + /** + * Sets the content type of the response being sent to the client, as a MIME type string. For example, {@code + * text/html}. If the MIME type is not relevant to the type of connection, it will simply be ignored. + * + * @param mimeType the MIME type for this response, according to the RFC 2045. + */ + void setContentType(String mimeType); }
Modified: platform/core/trunk/xwiki-containers/xwiki-container- portlet/src/main/java/org/xwiki/container/portlet/PortletResponse.java =================================================================== --- platform/core/trunk/xwiki-containers/xwiki-container-portlet/src/ main/java/org/xwiki/container/portlet/PortletResponse.java 2009-08-08 00:04:58 UTC (rev 22419) +++ platform/core/trunk/xwiki-containers/xwiki-container-portlet/src/ main/java/org/xwiki/container/portlet/PortletResponse.java 2009-08-08 10:42:34 UTC (rev 22420) @@ -20,6 +20,11 @@ */ package org.xwiki.container.portlet;
+import java.io.IOException; +import java.io.OutputStream; + +import javax.portlet.RenderResponse; + import org.xwiki.container.Response;
public class PortletResponse implements Response @@ -35,4 +40,33 @@ { return this.portletResponse; } + + /** + * {@inheritDoc} + */ + public OutputStream getOutputStream() throws IOException + { + if (this.portletResponse instanceof RenderResponse) { + return ((RenderResponse) this.portletResponse).getPortletOutputStream(); + } + return null; + } + + /** + * {@inheritDoc} + */ + public void setContentLength(int length) + { + // No content length for portlets, do nothing + } + + /** + * {@inheritDoc} + */ + public void setContentType(String mimeType) + { + if (this.portletResponse instanceof RenderResponse) { + ((RenderResponse) this.portletResponse).setContentType(mimeType); + } + } }
Modified: platform/core/trunk/xwiki-containers/xwiki-container- servlet/src/main/java/org/xwiki/container/servlet/ServletResponse.java =================================================================== --- platform/core/trunk/xwiki-containers/xwiki-container-servlet/src/ main/java/org/xwiki/container/servlet/ServletResponse.java 2009-08-08 00:04:58 UTC (rev 22419) +++ platform/core/trunk/xwiki-containers/xwiki-container-servlet/src/ main/java/org/xwiki/container/servlet/ServletResponse.java 2009-08-08 10:42:34 UTC (rev 22420) @@ -20,10 +20,13 @@ */ package org.xwiki.container.servlet;
-import org.xwiki.container.Response; +import java.io.IOException; +import java.io.OutputStream;
import javax.servlet.http.HttpServletResponse;
+import org.xwiki.container.Response; + public class ServletResponse implements Response { private HttpServletResponse httpServletResponse; @@ -37,4 +40,32 @@ { return this.httpServletResponse; } + + /** + * {@inheritDoc} + */ + public OutputStream getOutputStream() throws IOException + { + try { + return this.httpServletResponse.getOutputStream(); + } catch (IllegalStateException ex) { + return null;
Why don"'t you throw an IOException instead of returning null? Thanks -Vincent
+ } + } + + /** + * {@inheritDoc} + */ + public void setContentLength(int length) + { + this.httpServletResponse.setContentLength(length); + } + + /** + * {@inheritDoc} + */ + public void setContentType(String mimeType) + { + this.httpServletResponse.setContentType(mimeType); + } }
participants (1)
-
Vincent Massol