ResocontoExporter.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */


  20. package org.openspcoop2.web.ctrlstat.servlet.archivi;

  21. import java.io.IOException;
  22. import java.io.OutputStream;

  23. import javax.servlet.ServletException;
  24. import javax.servlet.http.HttpServlet;
  25. import javax.servlet.http.HttpServletRequest;
  26. import javax.servlet.http.HttpServletResponse;

  27. import org.openspcoop2.utils.transport.http.HttpUtilities;
  28. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;

  29. /**
  30.  * ResocontoExporter
  31.  *
  32.  * @author Andrea Poli (apoli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  *
  36.  */
  37. public class ResocontoExporter extends HttpServlet {

  38.     private static final long serialVersionUID = -7341279067126334095L;
  39.    
  40.     @Override
  41.     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  42.         this.processRequest(req, resp);
  43.     }

  44.     @Override
  45.     protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  46.         this.processRequest(req, resp);
  47.     }

  48.     /**
  49.      * Processa la richiesta pervenuta e si occupa di fornire i dati richiesti
  50.      * in formato zip
  51.      *
  52.      * @param req
  53.      * @param resp
  54.      * @throws ServletException
  55.      * @throws IOException
  56.      */
  57.     private void processRequest(HttpServletRequest request, HttpServletResponse response) {


  58.         ControlStationCore.logDebug("Ricevuta Richiesta di esportazione resoconto...");
  59.        
  60.         try {
  61.            
  62.             Object valore = request.getSession().getAttribute(ArchiviCostanti.PARAMETRO_DOWNLOAD_RESOCONTO_VALORE);
  63.             if(valore==null){
  64.                 throw new Exception("Resoconto da esportare non presente");
  65.             }
  66.             if(!(valore instanceof String)){
  67.                 throw new Exception("Resoconto da esportare non valido");
  68.             }
  69.             String contenuto = (String) valore;
  70.            
  71.             // Setto Proprietà Export File
  72.             HttpUtilities.setOutputFile(response, true, "Resoconto.txt");
  73.    
  74.             OutputStream out = response.getOutputStream();  
  75.             out.write(contenuto.getBytes());
  76.             out.flush();
  77.             out.close();
  78.        
  79.         } catch (Exception e) {
  80.             ControlStationCore.logError("Errore durante il download del resoconto: "+e.getMessage(), e);
  81.         }
  82.     }

  83. }