/**
 * 
 */
package it.mice.voila.runtime.jasper.view;

import java.util.HashMap;
import java.util.Map;

import it.mice.voila.runtime.jasper.view.helpers.AbstractJasperReportsView;
import it.mice.voila.runtime.jasper.view.helpers.JasperReportsCsvView;
import it.mice.voila.runtime.jasper.view.helpers.JasperReportsMultiFormatViewJasper;
import it.mice.voila.runtime.jasper.view.helpers.JasperReportsPdfView;
import it.mice.voila.runtime.jasper.view.helpers.JasperReportsXlsView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 */
public class JasperReportsMultiFormatView extends JasperReportsMultiFormatViewJasper {
	private boolean debug = false;
	/**
	 * Costruttore di classe.
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public JasperReportsMultiFormatView() {
		Map formatMappings = new HashMap<String, Class<? extends AbstractJasperReportsView>>(5);
		formatMappings.put("csv", JasperReportsCsvView.class);
		formatMappings.put("html", JasperReportsHtmlView.class);
		formatMappings.put("pdf", JasperReportsPdfView.class);
		formatMappings.put("xls", JasperReportsXlsView.class);
		formatMappings.put("rtf", JasperReportsRtfView.class);
		setFormatMappings(formatMappings);
	}
	
	/**
	 * Getter per la proprietà debug.
	 * @return la proprietà debug
	 */
	public boolean isDebug() {
		return debug;
	}

	/**
	 * Setter per la proprietà debug.
	 * @param debug la proprietà debug da settare
	 */
	public void setDebug(boolean debug) {
		this.debug = debug;
	}

	/**
	 * Finds the report data to use for rendering the report and then invokes the
	 * {@link #renderReport} method that should be implemented by the subclass.
	 * @param model the model map, as passed in for view rendering. Must contain
	 * a report data value that can be converted to a <code>JRDataSource</code>,
	 * acccording to the rules of the {@link #fillReport} method.
	 */
	@Override
	protected void renderMergedOutputModel(
			Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {

		if (isDebug()) {
			initApplicationContext();
		}
		super.renderMergedOutputModel(model, request, response);
	}

}
