001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 016 * 017 * $Id: UIOutputFileCommandLink.java 20116 2007-06-06 09:13:31Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.platform.ui.web.component.file; 021 022import javax.el.MethodExpression; 023import javax.faces.component.UIComponent; 024import javax.faces.component.html.HtmlCommandLink; 025import javax.faces.context.FacesContext; 026 027import org.nuxeo.ecm.platform.ui.web.binding.DownloadMethodExpression; 028 029/** 030 * Command Link with an overriden getActionExpression method. This is used to get the action expression querying the 031 * parent of this component, an {@link UIOutputFile} component which values may be changing if it is itself within an 032 * {@link UIInputFile} component. 033 * 034 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 035 */ 036public class UIOutputFileCommandLink extends HtmlCommandLink { 037 038 public static final String COMPONENT_TYPE = UIOutputFileCommandLink.class.getName(); 039 040 @Override 041 public MethodExpression getActionExpression() { 042 UIComponent parent = getParent(); 043 if (parent instanceof UIOutputFile) { 044 UIOutputFile outputFile = (UIOutputFile) parent; 045 FacesContext context = FacesContext.getCurrentInstance(); 046 return new DownloadMethodExpression(outputFile.getBlobExpression(context), 047 outputFile.getFileNameExpression(context)); 048 } 049 return super.getActionExpression(); 050 } 051 052}