View Javadoc
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", "contentDisposition", "attachment; filename=\"${filename}\""})})
59      public String execute() {
60  
61          ExtractRawDataRequest request = requestBuilder(ExtractRawDataRequest.class).
62                  addFacade(facade).
63                  addZone(zone).
64                  toRequest();
65          result = getService().toFirstFileResult(request);
66          return SUCCESS;
67      }
68  
69      public String getFilename() {
70          return "source.zip";
71      }
72  
73      public InputStream getInputStream() {
74          return result.getInputStream();
75      }
76  
77  }