001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * <a href="mailto:[email protected]">Anahide Tchertchian</a> 018 * 019 * $Id: UIOutputFileCommandLink.java 20116 2007-06-06 09:13:31Z sfermigier $ 020 */ 021 022package org.nuxeo.ecm.platform.ui.web.component.file; 023 024import javax.el.MethodExpression; 025import javax.faces.component.UIComponent; 026import javax.faces.component.html.HtmlCommandLink; 027import javax.faces.context.FacesContext; 028 029import org.nuxeo.ecm.platform.ui.web.binding.DownloadMethodExpression; 030 031/** 032 * Command Link with an overriden getActionExpression method. This is used to get the action expression querying the 033 * parent of this component, an {@link UIOutputFile} component which values may be changing if it is itself within an 034 * {@link UIInputFile} component. 035 * 036 * @author <a href="mailto:[email protected]">Anahide Tchertchian</a> 037 */ 038public class UIOutputFileCommandLink extends HtmlCommandLink { 039 040 public static final String COMPONENT_TYPE = UIOutputFileCommandLink.class.getName(); 041 042 @Override 043 public MethodExpression getActionExpression() { 044 UIComponent parent = getParent(); 045 if (parent instanceof UIOutputFile) { 046 UIOutputFile outputFile = (UIOutputFile) parent; 047 FacesContext context = FacesContext.getCurrentInstance(); 048 return new DownloadMethodExpression(outputFile.getBlobExpression(context), 049 outputFile.getFileNameExpression(context)); 050 } 051 return super.getActionExpression(); 052 } 053 054}