Author: thomas.heute(a)jboss.com
Date: 2008-12-15 12:01:45 -0500 (Mon, 15 Dec 2008)
New Revision: 12384
Modified:
branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/basic/HeaderContentPortlet.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/command/response/StreamContentResponse.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerResponseFactory.java
Log:
JBPORTAL-2242: pass Content-Disposition property to client
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java 2008-12-15
14:19:24 UTC (rev 12383)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java 2008-12-15
17:01:45 UTC (rev 12384)
@@ -129,11 +129,11 @@
if (scr.getInputStream() != null)
{
- return HTTPResponse.sendBinary(scr.getContentType(), scr.getLastModified(),
scr.getInputStream());
+ return HTTPResponse.sendBinary(scr.getContentType(), scr.getLastModified(),
scr.getProperties(), scr.getInputStream());
}
else
{
- return HTTPResponse.sendBinary(scr.getContentType(), scr.getLastModified(),
scr.getReader());
+ return HTTPResponse.sendBinary(scr.getContentType(), scr.getLastModified(),
scr.getProperties(), scr.getReader());
}
}
else if (controllerResponse instanceof SecurityErrorResponse)
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/command/response/StreamContentResponse.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/command/response/StreamContentResponse.java 2008-12-15
14:19:24 UTC (rev 12383)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/command/response/StreamContentResponse.java 2008-12-15
17:01:45 UTC (rev 12384)
@@ -22,10 +22,13 @@
******************************************************************************/
package org.jboss.portal.core.controller.command.response;
+import org.jboss.portal.common.util.MultiValuedPropertyMap;
import org.jboss.portal.core.controller.ControllerResponse;
+import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Reader;
+import java.util.Map;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -47,6 +50,9 @@
/** . */
private final InputStream inputStream;
+
+ /** . */
+ private MultiValuedPropertyMap<String> properties;
/** . */
private final Reader reader;
@@ -87,6 +93,22 @@
this.reader = reader;
}
+ public StreamContentResponse(String contentType,
+ MultiValuedPropertyMap<String> properties,
+ ByteArrayInputStream inputStream) {
+
+ this(contentType, -1, inputStream);
+ this.properties = properties;
+ }
+
+ public StreamContentResponse(String contentType,
+ MultiValuedPropertyMap<String> properties,
+ Reader reader) {
+ this(contentType, -1, reader);
+ this.properties = properties;
+ }
+
+
public String getContentType()
{
return contentType;
@@ -106,4 +128,9 @@
{
return reader;
}
+
+ public MultiValuedPropertyMap<String> getProperties()
+ {
+ return properties;
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2008-12-15
14:19:24 UTC (rev 12383)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2008-12-15
17:01:45 UTC (rev 12384)
@@ -23,6 +23,7 @@
package org.jboss.portal.core.controller.handler;
import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.common.util.MultiValuedPropertyMap;
import org.jboss.portal.server.ServerInvocationContext;
import javax.servlet.ServletException;
@@ -32,6 +33,7 @@
import java.io.InputStream;
import java.io.Reader;
import java.io.Writer;
+import java.util.Map;
/**
* Response that sends a response to the http layer.
@@ -56,7 +58,7 @@
};
}
- public static HTTPResponse sendBinary(final String contentType, final long
lastModified, final InputStream in)
+ public static HTTPResponse sendBinary(final String contentType, final long
lastModified, final MultiValuedPropertyMap<String> properties, final InputStream
in)
{
return new HTTPResponse()
{
@@ -72,6 +74,17 @@
{
resp.addDateHeader("Last-Modified", lastModified);
}
+
+ if (properties != null)
+ {
+ for (String key: properties.keySet())
+ {
+ if (properties.getValue(key) != null)
+ {
+ resp.addHeader(key, properties.getValue(key));
+ }
+ }
+ }
//
ServletOutputStream sout = null;
@@ -89,7 +102,7 @@
};
}
- public static HTTPResponse sendBinary(final String contentType, final long
lastModified, final Reader reader)
+ public static HTTPResponse sendBinary(final String contentType, final long
lastModified, final MultiValuedPropertyMap<String> properties, final Reader reader)
{
return new HTTPResponse()
{
@@ -106,6 +119,17 @@
resp.addDateHeader("Last-Modified", lastModified);
}
+ if (properties != null)
+ {
+ for (String key: properties.keySet())
+ {
+ if (properties.getValue(key) != null)
+ {
+ resp.addHeader(key, properties.getValue(key));
+ }
+ }
+ }
+
//
Writer writer = null;
try
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerResponseFactory.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerResponseFactory.java 2008-12-15
14:19:24 UTC (rev 12383)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerResponseFactory.java 2008-12-15
17:01:45 UTC (rev 12384)
@@ -174,11 +174,11 @@
//
if (contentResponse.getType() == ContentResponse.TYPE_BYTES)
{
- return new StreamContentResponse(contentType, -1, new
ByteArrayInputStream(contentResponse.getBytes()));
+ return new StreamContentResponse(contentType,
contentResponse.getProperties().getTransportHeaders(), new
ByteArrayInputStream(contentResponse.getBytes()));
}
else
{
- return new StreamContentResponse(contentType, -1, new
StringReader(contentResponse.getChars()));
+ return new StreamContentResponse(contentType,
contentResponse.getProperties().getTransportHeaders(), new
StringReader(contentResponse.getChars()));
}
}
}
Modified:
branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/basic/HeaderContentPortlet.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/basic/HeaderContentPortlet.java 2008-12-15
14:19:24 UTC (rev 12383)
+++
branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/basic/HeaderContentPortlet.java 2008-12-15
17:01:45 UTC (rev 12384)
@@ -24,9 +24,16 @@
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
+import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import javax.portlet.ResourceURL;
+import javax.portlet.WindowState;
+
import java.io.IOException;
+import java.io.PrintWriter;
import java.io.Writer;
/*
@@ -45,9 +52,35 @@
res.setContentType("text/html");
Writer writer = res.getWriter();
+ ResourceURL url = res.createResourceURL();
+ writer.write("<div><a href=\"" + url.toString() +
"\">Resource URL</a></div>");
writer.write("<div id='Introducing-HeaderContent'/>");
writer.write("<div class=\"portlet-section-body\"><p
id='rewrite-js'><button id=\"Introducing-HeaderContentInput\"
class=\"portlet-form-button\" type='button'
onClick='injectJS()'>Call injected
javascript</button></p></div>");
+
+
writer.flush();
writer.close();
}
+
+ @Override
+ public void serveResource(ResourceRequest resourceRequest, ResourceResponse
resourceResponse) throws PortletException, IOException
+ {
+ resourceResponse.setProperty("Expires", "0");
+ resourceResponse.setProperty("Content-Disposition", "attachment;
filename=vcard.vcf ");
+ resourceResponse.setContentType("text/x-vcard");
+ PrintWriter writer = resourceResponse.getWriter();
+
+ writer.print("BEGIN:VCARD\n");
+ writer.print("VERSION:3.0\n");
+ writer.print("FN:Thomas Heute\n");
+ writer.print("N:Heute;Thomas;;;\n");
+ writer.print("EMAIL;TYPE=INTERNET;TYPE=WORK:theute@redhat.com\n");
+ writer.print("TITLE:JBoss Portal Project Lead\n");
+ writer.print("ORG:Red Hat\n");
+ writer.print("END:VCARD\n");
+
+ writer.flush();
+ writer.close();
+ }
+
}