1 /* 2 * #%L 3 * Coser :: Web 4 * %% 5 * Copyright (C) 2010 - 2012 Ifremer, Codelutin, Chatellier Eric, Chemit Tony 6 * %% 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU Affero General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU Affero General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * #L% 20 */ 21 22 package fr.ifremer.coser.web.actions.source; 23 24 import fr.ifremer.coser.result.result.FileResult; 25 import fr.ifremer.coser.result.request.ExtractRawDataRequest; 26 import org.apache.struts2.convention.annotation.Action; 27 import org.apache.struts2.convention.annotation.Result; 28 29 import java.io.InputStream; 30 31 /** 32 * Force le téléchargement du zip. 33 * 34 * @author chatellier 35 * @version $Revision$ 36 * <p/> 37 * Last update : $Date$ 38 * By : $Author$ 39 */ 40 public class SourceDataAction extends SourceAction { 41 42 /** serialVersionUID. */ 43 private static final long serialVersionUID = 3385467755357775199L; 44 45 protected boolean accepted; 46 47 protected FileResult result; 48 49 public void setAccepted(boolean accepted) { 50 this.accepted = accepted; 51 } 52 53 // used by validator 54 public boolean isAccepted() { 55 return accepted; 56 } 57 58 // @Action(results = {@Result(type = "stream", params = {"contentType", "application/zip", "inputName", "inputStream", "contentDisposition", "attachment; filename=\"${filename}\""})}) 59 @Action(results = {@Result(type = "stream", params = {"contentType", "application/zip", "contentDisposition", "attachment; filename=\"${filename}\""})}) 60 public String execute() { 61 62 ExtractRawDataRequest request = requestBuilder(ExtractRawDataRequest.class). 63 addFacade(facade). 64 addZone(zone). 65 toRequest(); 66 result = getService().toFileResult(request); 67 return SUCCESS; 68 } 69 70 public String getFilename() { 71 return "source.zip"; 72 } 73 74 public InputStream getInputStream() { 75 return result.getInputStream(); 76 } 77 78 // @Override 79 // public void validate() { 80 // 81 // if (!accepted) { 82 // addFieldError("accepted", getText("message.quality.notaccepted")); 83 // } 84 // 85 // } 86 // 87 // public InputStream getInputStream() { 88 // WebService webService = ServiceFactory.getWebService(); 89 // 90 // Locale locale = getLocale(); 91 // 92 // InputStream input = null; 93 // try { 94 // 95 // File sourceZip = webService.getSourceZip(zone, locale); 96 // input = new FileInputStream(sourceZip); 97 // } catch (Exception ex) { 98 // if (log.isErrorEnabled()) { 99 // log.error("Can't get file data", ex); 100 // } 101 // throw new CoserWebException("Can't get source zip file", ex); 102 // } 103 // 104 // return input; 105 // } 106 }