Author: nbelaevski
Date: 2010-12-28 15:02:52 -0500 (Tue, 28 Dec 2010)
New Revision: 20832
Modified:
trunk/examples/core-demo/src/main/webapp/mediaOutput.xhtml
trunk/ui/core/ui/src/main/java/org/richfaces/component/AbstractMediaOutput.java
trunk/ui/core/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java
Log:
https://issues.jboss.org/browse/RF-8330
Modified: trunk/examples/core-demo/src/main/webapp/mediaOutput.xhtml
===================================================================
--- trunk/examples/core-demo/src/main/webapp/mediaOutput.xhtml 2010-12-28 19:51:29 UTC
(rev 20831)
+++ trunk/examples/core-demo/src/main/webapp/mediaOutput.xhtml 2010-12-28 20:02:52 UTC
(rev 20832)
@@ -13,7 +13,7 @@
element="img" /><br />
<h:form>
<a4j:mediaOutput createContent="#{mediaOutputBean.createContent}"
value="richfaces-twitter.jpg"
- element="img" >
+ element="img" cacheable="true"
fileName="richfaces-twitter.jpg">
<f:ajax event="dblclick"
listener="#{commandBean.listener}" />
</a4j:mediaOutput><br />
</h:form>
Modified: trunk/ui/core/ui/src/main/java/org/richfaces/component/AbstractMediaOutput.java
===================================================================
---
trunk/ui/core/ui/src/main/java/org/richfaces/component/AbstractMediaOutput.java 2010-12-28
19:51:29 UTC (rev 20831)
+++
trunk/ui/core/ui/src/main/java/org/richfaces/component/AbstractMediaOutput.java 2010-12-28
20:02:52 UTC (rev 20832)
@@ -164,6 +164,9 @@
@Attribute
public abstract String getVspace();
+ @Attribute
+ public abstract String getFileName();
+
@Attribute(events = @EventName("blur"))
public abstract String getOnblur();
Modified: trunk/ui/core/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java
===================================================================
---
trunk/ui/core/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java 2010-12-28
19:51:29 UTC (rev 20831)
+++
trunk/ui/core/ui/src/main/java/org/richfaces/resource/MediaOutputResource.java 2010-12-28
20:02:52 UTC (rev 20832)
@@ -26,6 +26,8 @@
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
@@ -36,6 +38,8 @@
import org.richfaces.component.AbstractMediaOutput;
+import com.google.common.base.Strings;
+
/**
* @author Nick Belaevski
* @since 4.0
@@ -60,6 +64,8 @@
private ValueExpression timeToLiveExpression;
private Object userData;
+ private String fileName;
+
public void encode(FacesContext facesContext) throws IOException {
OutputStream outStream =
facesContext.getExternalContext().getResponseOutputStream();
contentProducer.invoke(facesContext.getELContext(), new Object[] {outStream,
userData});
@@ -74,13 +80,14 @@
}
public Object saveState(FacesContext context) {
- Object[] state = new Object[4];
+ Object[] state = new Object[5];
// parent fields state saving
state[0] = isCacheable(context) ? Boolean.TRUE : Boolean.FALSE;
state[1] = getContentType();
state[2] = UIComponentBase.saveAttachedState(context, userData);
state[3] = UIComponentBase.saveAttachedState(context, contentProducer);
+ state[4] = fileName;
return state;
}
@@ -92,6 +99,7 @@
setContentType((String) state[1]);
userData = UIComponentBase.restoreAttachedState(context, state[2]);
contentProducer = (MethodExpression)
UIComponentBase.restoreAttachedState(context, state[3]);
+ fileName = (String) state[4];
}
/**
@@ -109,6 +117,7 @@
this.lastModifiedExpression =
uiMediaOutput.getValueExpression("lastModfied");
this.expiresExpression = uiMediaOutput.getValueExpression("expires");
this.timeToLiveExpression =
uiMediaOutput.getValueExpression("timeToLive");
+ this.fileName = uiMediaOutput.getFileName();
}
public boolean isCacheable(FacesContext context) {
@@ -139,4 +148,14 @@
this.contentType = contentType;
}
+ @Override
+ public Map<String, String> getResponseHeaders() {
+ Map<String, String> headers = new HashMap<String, String>(2);
+
+ if (!Strings.isNullOrEmpty(fileName)) {
+ headers.put("Content-Disposition", "inline;
filename=\"" + fileName + "\"");
+ }
+
+ return headers;
+ }
}