- Pequena refatoração da geração de relatório
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@27966 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
a28cb467ae
commit
0836a48013
|
@ -1,14 +1,9 @@
|
|||
package com.rjconsultores.ventaboletos.relatorios.render;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.jasperreports.engine.JRDataSource;
|
||||
import net.sf.jasperreports.engine.JasperFillManager;
|
||||
import net.sf.jasperreports.engine.JasperPrint;
|
||||
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.IDataSource;
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.IRenderRelatorio;
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio;
|
||||
|
@ -25,9 +20,7 @@ public abstract class RenderRelatorioAbstract implements IRenderRelatorio {
|
|||
protected Relatorio relatorio;
|
||||
protected IDataSource datasource;
|
||||
protected Connection connection;
|
||||
private Map<String, Object> parametros = new HashMap<String, Object>();
|
||||
protected JasperPrint jasperPrint;
|
||||
|
||||
protected Map<String, Object> parametros = new HashMap<String, Object>();
|
||||
|
||||
/**
|
||||
* @param relatorio
|
||||
|
@ -39,7 +32,7 @@ public abstract class RenderRelatorioAbstract implements IRenderRelatorio {
|
|||
this.connection = connection;
|
||||
this.relatorio = relatorio;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renderiza o relatório solicitado
|
||||
*
|
||||
|
@ -51,7 +44,6 @@ public abstract class RenderRelatorioAbstract implements IRenderRelatorio {
|
|||
*/
|
||||
protected abstract byte[] render(SaidaRelatorio saida) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* @param relatorio
|
||||
* Enum do tipo Relatorio contendo as configurações de geração de todos os relatórios
|
||||
|
@ -77,30 +69,8 @@ public abstract class RenderRelatorioAbstract implements IRenderRelatorio {
|
|||
@Override
|
||||
public byte[] getConteudo(SaidaRelatorio saida) throws Exception {
|
||||
|
||||
|
||||
if(this.jasperPrint == null){
|
||||
|
||||
if(this.relatorio.getParametros()!=null)
|
||||
this.relatorio.getParametros().initParametros(this.parametros, this.connection);
|
||||
|
||||
InputStream iStemplate = this.getClass().getResourceAsStream("/com/rjconsultores/ventaboletos/relatorios/templates/"+this.relatorio.getTemplate());
|
||||
|
||||
|
||||
if (this.relatorio.getDatasource() != null)
|
||||
this.jasperPrint = JasperFillManager.fillReport(iStemplate, this.getParametros(), (JRDataSource) this.datasource);
|
||||
else
|
||||
this.jasperPrint = JasperFillManager.fillReport(iStemplate, this.getParametros(), this.connection);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return this.render(saida);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.io.InputStream;
|
|||
import java.sql.Connection;
|
||||
|
||||
import net.sf.jasperreports.engine.JRDataSource;
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import net.sf.jasperreports.engine.JasperExportManager;
|
||||
import net.sf.jasperreports.engine.JasperFillManager;
|
||||
import net.sf.jasperreports.engine.JasperPrint;
|
||||
|
@ -23,6 +22,8 @@ import com.rjconsultores.ventaboletos.relatorios.utilitarios.SaidaRelatorio;
|
|||
*/
|
||||
public class RenderRelatorioJasper extends RenderRelatorioAbstract {
|
||||
|
||||
protected JasperPrint jasperPrint;
|
||||
|
||||
/**
|
||||
* @param relatorio
|
||||
* Enum do tipo Relatorio contendo as configurações de geração de todos os relatórios
|
||||
|
@ -59,16 +60,29 @@ public class RenderRelatorioJasper extends RenderRelatorioAbstract {
|
|||
* @see com.rjconsultores.ventaboletos.relatorios.utilitarios.IRenderRelatorio#render()
|
||||
*/
|
||||
@Override
|
||||
protected byte[] render(SaidaRelatorio saida) throws JRException {
|
||||
protected byte[] render(SaidaRelatorio saida) throws Exception {
|
||||
byte[] conteudo = null;
|
||||
|
||||
|
||||
if (this.jasperPrint == null) {
|
||||
|
||||
if (this.relatorio.getParametros() != null)
|
||||
this.relatorio.getParametros().initParametros(this.parametros, this.connection);
|
||||
|
||||
InputStream iStemplate = this.getClass().getResourceAsStream("/com/rjconsultores/ventaboletos/relatorios/templates/" + this.relatorio.getTemplate());
|
||||
|
||||
if (this.relatorio.getDatasource() != null)
|
||||
this.jasperPrint = JasperFillManager.fillReport(iStemplate, this.getParametros(), (JRDataSource) this.datasource);
|
||||
else
|
||||
this.jasperPrint = JasperFillManager.fillReport(iStemplate, this.getParametros(), this.connection);
|
||||
|
||||
}
|
||||
|
||||
switch (saida) {
|
||||
|
||||
case PDF:
|
||||
conteudo = JasperExportManager.exportReportToPdf(this.jasperPrint);
|
||||
break;
|
||||
|
||||
|
||||
case XLS:
|
||||
JRXlsExporter exporterXLS = new JRXlsExporter();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
|
|
Loading…
Reference in New Issue