1 16 17 package org.springframework.web.servlet.view.jasperreports; 18 19 import java.util.HashMap ; 20 import java.util.Map ; 21 import java.util.Properties ; 22 23 import javax.sql.DataSource ; 24 25 import net.sf.jasperreports.engine.design.JRCompiler; 26 27 import org.springframework.web.servlet.view.AbstractUrlBasedView; 28 import org.springframework.web.servlet.view.UrlBasedViewResolver; 29 30 38 public class JasperReportsViewResolver extends UrlBasedViewResolver { 39 40 private String reportDataKey; 41 42 private Properties subReportUrls; 43 44 private String [] subReportDataKeys; 45 46 private Properties headers; 47 48 private Map exporterParameters = new HashMap (); 49 50 private DataSource jdbcDataSource; 51 52 private JRCompiler reportCompiler; 53 54 55 58 protected Class requiredViewClass() { 59 return AbstractJasperReportsView.class; 60 } 61 62 66 public void setReportDataKey(String reportDataKey) { 67 this.reportDataKey = reportDataKey; 68 } 69 70 74 public void setSubReportUrls(Properties subReportUrls) { 75 this.subReportUrls = subReportUrls; 76 } 77 78 82 public void setSubReportDataKeys(String [] subReportDataKeys) { 83 this.subReportDataKeys = subReportDataKeys; 84 } 85 86 90 public void setHeaders(Properties headers) { 91 this.headers = headers; 92 } 93 94 98 public void setExporterParameters(Map exporterParameters) { 99 this.exporterParameters = exporterParameters; 100 } 101 102 106 public void setJdbcDataSource(DataSource jdbcDataSource) { 107 this.jdbcDataSource = jdbcDataSource; 108 } 109 110 114 public void setReportCompiler(JRCompiler reportCompiler) { 115 this.reportCompiler = reportCompiler; 116 } 117 118 119 protected AbstractUrlBasedView buildView(String viewName) throws Exception { 120 AbstractJasperReportsView view = (AbstractJasperReportsView) super.buildView(viewName); 121 122 view.setReportDataKey(this.reportDataKey); 123 view.setSubReportUrls(this.subReportUrls); 124 view.setSubReportDataKeys(this.subReportDataKeys); 125 view.setHeaders(this.headers); 126 view.setExporterParameters(this.exporterParameters); 127 view.setJdbcDataSource(this.jdbcDataSource); 128 129 if (this.reportCompiler != null) { 130 view.setReportCompiler(this.reportCompiler); 131 } 132 133 return view; 134 } 135 136 } 137 | Popular Tags |