Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
License Agreement. Rich Faces - Natural Ajax for Java Server Faces (JSF) Copyright (C) 2007 Exadel, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 package org.richfaces.resource;
 import java.util.Date;
 import java.util.Map;
 import  javax.faces.component.StateHolder;
 import  javax.faces.component.UIComponent;
 import  javax.faces.component.UIComponentBase;
 import  javax.faces.context.FacesContext;

Nick Belaevski
 public class MediaOutputResource extends AbstractUserResource implements StateHolder, CacheableResource {
     private String contentType;
     private boolean cacheable;
     private MethodExpression contentProducer;
      * TODO: add handling for expressions:
      * 1. State saving 2. Evaluation
     private Object userData;
     private String fileName;
     public void encode(FacesContext facesContextthrows IOException {
         OutputStream outStream = facesContext.getExternalContext().getResponseOutputStream();
         .invoke(facesContext.getELContext(), new Object[] { outStream });
     public boolean isTransient() {
         return false;
     public void setTransient(boolean newTransientValue) {
         throw new UnsupportedOperationException();
     public Object saveState(FacesContext context) {
         Object[] state = new Object[5];
         // parent fields state saving
         state[0] = isCacheable(context) ? . : .;
         state[1] = getContentType();
         state[2] = UIComponentBase.saveAttachedState(context);
         state[3] = UIComponentBase.saveAttachedState(context);
         state[4] = ;
         return state;
     public void restoreState(FacesContext contextObject stateObject) {
         Object[] state = (Object[]) stateObject;
          = UIComponentBase.restoreAttachedState(contextstate[2]);
          = (MethodExpression) UIComponentBase.restoreAttachedState(contextstate[3]);
          = (Stringstate[4];


    // TODO use ResourceComponent or exchange object as argument?
    public void initialize() {
        AbstractMediaOutput uiMediaOutput = (AbstractMediaOutput) UIComponent.getCurrentComponent(FacesContext
        this. = uiMediaOutput.getValue();
        this. = uiMediaOutput.getCreateContent();
        this. = uiMediaOutput.getValueExpression("lastModfied");
        this. = uiMediaOutput.getValueExpression("expires");
        this. = uiMediaOutput.getValueExpression("timeToLive");
        this. = uiMediaOutput.getFileName();
    public boolean isCacheable(FacesContext context) {
        return ;
    public void setCacheable(boolean cacheable) {
        this. = cacheable;
    public Date getExpires(FacesContext context) {
        return null;
    public int getTimeToLive(FacesContext context) {
        return -1;
    public String getEntityTag(FacesContext context) {
        return null;
    public String getContentType() {
        return ;
    public void setContentType(String contentType) {
        this. = contentType;
    public Map<StringStringgetResponseHeaders() {
        Map<StringStringheaders = new HashMap<StringString>(2);
        if (!Strings.isNullOrEmpty()) {
            headers.put("Content-Disposition""inline; filename=\"" +  + "\"");
        return headers;
New to GrepCode? Check out our FAQ X