- 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;
|
package com.rjconsultores.ventaboletos.relatorios.render;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
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.IDataSource;
|
||||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.IRenderRelatorio;
|
import com.rjconsultores.ventaboletos.relatorios.utilitarios.IRenderRelatorio;
|
||||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio;
|
import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio;
|
||||||
|
@ -25,9 +20,7 @@ public abstract class RenderRelatorioAbstract implements IRenderRelatorio {
|
||||||
protected Relatorio relatorio;
|
protected Relatorio relatorio;
|
||||||
protected IDataSource datasource;
|
protected IDataSource datasource;
|
||||||
protected Connection connection;
|
protected Connection connection;
|
||||||
private Map<String, Object> parametros = new HashMap<String, Object>();
|
protected Map<String, Object> parametros = new HashMap<String, Object>();
|
||||||
protected JasperPrint jasperPrint;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param relatorio
|
* @param relatorio
|
||||||
|
@ -39,7 +32,7 @@ public abstract class RenderRelatorioAbstract implements IRenderRelatorio {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
this.relatorio = relatorio;
|
this.relatorio = relatorio;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza o relatório solicitado
|
* Renderiza o relatório solicitado
|
||||||
*
|
*
|
||||||
|
@ -51,7 +44,6 @@ public abstract class RenderRelatorioAbstract implements IRenderRelatorio {
|
||||||
*/
|
*/
|
||||||
protected abstract byte[] render(SaidaRelatorio saida) throws Exception;
|
protected abstract byte[] render(SaidaRelatorio saida) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param relatorio
|
* @param relatorio
|
||||||
* Enum do tipo Relatorio contendo as configurações de geração de todos os relatórios
|
* 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
|
@Override
|
||||||
public byte[] getConteudo(SaidaRelatorio saida) throws Exception {
|
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);
|
return this.render(saida);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.io.InputStream;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
|
||||||
import net.sf.jasperreports.engine.JRDataSource;
|
import net.sf.jasperreports.engine.JRDataSource;
|
||||||
import net.sf.jasperreports.engine.JRException;
|
|
||||||
import net.sf.jasperreports.engine.JasperExportManager;
|
import net.sf.jasperreports.engine.JasperExportManager;
|
||||||
import net.sf.jasperreports.engine.JasperFillManager;
|
import net.sf.jasperreports.engine.JasperFillManager;
|
||||||
import net.sf.jasperreports.engine.JasperPrint;
|
import net.sf.jasperreports.engine.JasperPrint;
|
||||||
|
@ -23,6 +22,8 @@ import com.rjconsultores.ventaboletos.relatorios.utilitarios.SaidaRelatorio;
|
||||||
*/
|
*/
|
||||||
public class RenderRelatorioJasper extends RenderRelatorioAbstract {
|
public class RenderRelatorioJasper extends RenderRelatorioAbstract {
|
||||||
|
|
||||||
|
protected JasperPrint jasperPrint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param relatorio
|
* @param relatorio
|
||||||
* Enum do tipo Relatorio contendo as configurações de geração de todos os relatórios
|
* 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()
|
* @see com.rjconsultores.ventaboletos.relatorios.utilitarios.IRenderRelatorio#render()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected byte[] render(SaidaRelatorio saida) throws JRException {
|
protected byte[] render(SaidaRelatorio saida) throws Exception {
|
||||||
byte[] conteudo = null;
|
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) {
|
switch (saida) {
|
||||||
|
|
||||||
case PDF:
|
case PDF:
|
||||||
conteudo = JasperExportManager.exportReportToPdf(this.jasperPrint);
|
conteudo = JasperExportManager.exportReportToPdf(this.jasperPrint);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XLS:
|
case XLS:
|
||||||
JRXlsExporter exporterXLS = new JRXlsExporter();
|
JRXlsExporter exporterXLS = new JRXlsExporter();
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
|
|
Loading…
Reference in New Issue