view gnv/src/main/java/de/intevation/gnv/action/DoExportAction.java @ 284:47e3647af88f

Added link in gui to export charts to svg. gnv/trunk@388 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 30 Nov 2009 17:46:57 +0000
parents ef10bf497a16
children 9005b39c52ac
line wrap: on
line source
/**
 *
 */
package de.intevation.gnv.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

/**
 * @author Tim Englich <tim.englich@intevation.de>
 * 
 */
public class DoExportAction extends DoOutputAction {

    /**
     * the logger, used to log exceptions and additonaly information
     */
    private static Logger log = Logger.getLogger(DoExportAction.class);

    /**
     * Constructor
     */
    public DoExportAction() {
        super();
    }

    @Override
    protected void setHeaders(String target, String mimeType,
                              HttpServletResponse response,
                              HttpServletRequest request) {
        log.debug("DoExportAction.setHeaders");
        try {
            super.setHeaders(target, mimeType, response, request);
            String fileName = "GNVEXPORT_" + System.currentTimeMillis() + ".";

            if (target.equalsIgnoreCase("chart")) {
                fileName = fileName
                           + mimeType.substring(mimeType.indexOf("/") + 1);
            } 
            else if (target.equalsIgnoreCase("pdf")) {
                fileName = fileName + "pdf";
            }
            else if (target.equalsIgnoreCase("svg")) {
                fileName = fileName + "svg";
            } else if (target.equalsIgnoreCase("CSV")) {
                fileName = fileName + "csv";
            } else {
                fileName = fileName + "txt";
            }
            log.debug("FileName for Export: " + fileName);
            response.setHeader("Content-Disposition", "attachment;filename="
                                                      + fileName);
        } catch (Exception e) {
            log.error(e, e);
        }
    }

}

http://dive4elements.wald.intevation.org