fixes bug#11452
dev:Claudio qua:Renato git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@83114 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
69fb9713ff
commit
482d09a055
|
@ -6,12 +6,14 @@ import java.util.Locale;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import net.sf.jasperreports.engine.JRDataSource;
|
import net.sf.jasperreports.engine.JRDataSource;
|
||||||
|
import net.sf.jasperreports.engine.JRParagraph;
|
||||||
import net.sf.jasperreports.engine.JRParameter;
|
import net.sf.jasperreports.engine.JRParameter;
|
||||||
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;
|
||||||
import net.sf.jasperreports.engine.export.JExcelApiExporter;
|
import net.sf.jasperreports.engine.export.JExcelApiExporter;
|
||||||
import net.sf.jasperreports.engine.export.JExcelApiExporterParameter;
|
import net.sf.jasperreports.engine.export.JExcelApiExporterParameter;
|
||||||
|
import net.sf.jasperreports.engine.util.JRProperties;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
@ -27,13 +29,13 @@ import com.rjconsultores.ventaboletos.utilerias.LocaleUtil;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RenderRelatorioJasper {
|
public class RenderRelatorioJasper {
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(Relatorio.class);
|
private static Logger log = Logger.getLogger(Relatorio.class);
|
||||||
|
|
||||||
protected JasperPrint jasperPrint;
|
protected JasperPrint jasperPrint;
|
||||||
|
|
||||||
private Relatorio relatorio;
|
private Relatorio relatorio;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
|
@ -46,7 +48,7 @@ public class RenderRelatorioJasper {
|
||||||
public RenderRelatorioJasper(Relatorio relatorio) throws Exception {
|
public RenderRelatorioJasper(Relatorio relatorio) throws Exception {
|
||||||
this.relatorio = relatorio;
|
this.relatorio = relatorio;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void preRender() {
|
public void preRender() {
|
||||||
this.initBundler();
|
this.initBundler();
|
||||||
this.initLocale();
|
this.initLocale();
|
||||||
|
@ -55,22 +57,22 @@ public class RenderRelatorioJasper {
|
||||||
|
|
||||||
private void initBundler() {
|
private void initBundler() {
|
||||||
// TODO Alterar para injeção de acordo com usuário logado ou outro meio para obter o Locale correto
|
// TODO Alterar para injeção de acordo com usuário logado ou outro meio para obter o Locale correto
|
||||||
|
|
||||||
Locale locale = LocaleUtil.getLocale();
|
Locale locale = LocaleUtil.getLocale();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ResourceBundle resource = ResourceBundle.getBundle("com.rjconsultores.ventaboletos.relatorios.internacionalizacao." + this.relatorio.getNome(), locale);
|
ResourceBundle resource = ResourceBundle.getBundle("com.rjconsultores.ventaboletos.relatorios.internacionalizacao." + this.relatorio.getNome(), locale);
|
||||||
this.relatorio.getParametros().put(JRParameter.REPORT_RESOURCE_BUNDLE, resource);
|
this.relatorio.getParametros().put(JRParameter.REPORT_RESOURCE_BUNDLE, resource);
|
||||||
|
|
||||||
/* Adicionar o arquivo de internacionalização para o subreporte quando informado */
|
/* Adicionar o arquivo de internacionalização para o subreporte quando informado */
|
||||||
if(this.relatorio.getNomeSubReporte() != null && this.relatorio.getNomeSubReporte().length > 0) {
|
if (this.relatorio.getNomeSubReporte() != null && this.relatorio.getNomeSubReporte().length > 0) {
|
||||||
if(this.relatorio.getNomeSubReporte().length == 1 && StringUtils.isNotBlank(this.relatorio.getNomeSubReporte()[0])) {
|
if (this.relatorio.getNomeSubReporte().length == 1 && StringUtils.isNotBlank(this.relatorio.getNomeSubReporte()[0])) {
|
||||||
ResourceBundle resourceSubReporte = ResourceBundle.getBundle("com.rjconsultores.ventaboletos.relatorios.internacionalizacao." + this.relatorio.getNomeSubReporte()[0], locale);
|
ResourceBundle resourceSubReporte = ResourceBundle.getBundle("com.rjconsultores.ventaboletos.relatorios.internacionalizacao." + this.relatorio.getNomeSubReporte()[0], locale);
|
||||||
this.relatorio.getParametros().put("SUBREPORT_RESOURCE_BUNDLE", resourceSubReporte);
|
this.relatorio.getParametros().put("SUBREPORT_RESOURCE_BUNDLE", resourceSubReporte);
|
||||||
} else if(this.relatorio.getNomeSubReporte() != null && this.relatorio.getNomeSubReporte().length > 1) {
|
} else if (this.relatorio.getNomeSubReporte() != null && this.relatorio.getNomeSubReporte().length > 1) {
|
||||||
int indice = 0;
|
int indice = 0;
|
||||||
for (String nomeSubReporte : this.relatorio.getNomeSubReporte()) {
|
for (String nomeSubReporte : this.relatorio.getNomeSubReporte()) {
|
||||||
if(StringUtils.isNotBlank(nomeSubReporte)) {
|
if (StringUtils.isNotBlank(nomeSubReporte)) {
|
||||||
ResourceBundle resourceSubReporte = ResourceBundle.getBundle("com.rjconsultores.ventaboletos.relatorios.internacionalizacao." + nomeSubReporte, locale);
|
ResourceBundle resourceSubReporte = ResourceBundle.getBundle("com.rjconsultores.ventaboletos.relatorios.internacionalizacao." + nomeSubReporte, locale);
|
||||||
this.relatorio.getParametros().put("SUBREPORT_RESOURCE_BUNDLE" + "_" + (++indice), resourceSubReporte);
|
this.relatorio.getParametros().put("SUBREPORT_RESOURCE_BUNDLE" + "_" + (++indice), resourceSubReporte);
|
||||||
}
|
}
|
||||||
|
@ -78,7 +80,7 @@ public class RenderRelatorioJasper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(),e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,29 +110,42 @@ public class RenderRelatorioJasper {
|
||||||
this.preRender();
|
this.preRender();
|
||||||
|
|
||||||
byte[] conteudo = null;
|
byte[] conteudo = null;
|
||||||
|
try {
|
||||||
if (this.jasperPrint == null) {
|
if (this.jasperPrint == null) {
|
||||||
|
|
||||||
if (this.relatorio.isCollectionDataSource()) {
|
if (this.relatorio.isCollectionDataSource()) {
|
||||||
this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), this.relatorio.getCollectionDataSource());
|
if (!StringUtils.isBlank(this.relatorio.getNome()) && this.relatorio.getNome().equalsIgnoreCase("RelatorioGratuidade")) {
|
||||||
} else {
|
JRProperties.setProperty(JRParagraph.DEFAULT_TAB_STOP_WIDTH, "10");
|
||||||
if (this.relatorio.isCustomDataSource())
|
}
|
||||||
this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), (JRDataSource) this.relatorio.getCustomDataSource());
|
this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), this.relatorio.getCollectionDataSource());
|
||||||
else
|
|
||||||
this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), this.relatorio.getConexao());
|
} else {
|
||||||
|
if (this.relatorio.isCustomDataSource())
|
||||||
|
this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), (JRDataSource) this.relatorio.getCustomDataSource());
|
||||||
|
else
|
||||||
|
this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), this.relatorio.getConexao());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
switch (saida) {
|
switch (saida) {
|
||||||
|
|
||||||
case PDF:
|
case PDF:
|
||||||
conteudo = this.renderPdf();
|
conteudo = this.renderPdf();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XLS:
|
case XLS:
|
||||||
conteudo = this.renderXls(isCustomXls);
|
conteudo = this.renderXls(isCustomXls);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO: handle exception
|
||||||
|
throw new Exception();
|
||||||
|
} finally {
|
||||||
|
if (!StringUtils.isBlank(this.relatorio.getNome()) && this.relatorio.getNome().equalsIgnoreCase("RelatorioGratuidade")) {
|
||||||
|
JRProperties.setProperty(JRParagraph.DEFAULT_TAB_STOP_WIDTH, "40");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return conteudo;
|
return conteudo;
|
||||||
|
@ -139,11 +154,11 @@ public class RenderRelatorioJasper {
|
||||||
protected byte[] renderXls(boolean isCustomXls) throws Exception {
|
protected byte[] renderXls(boolean isCustomXls) throws Exception {
|
||||||
JExcelApiExporter exporterXLS = new JExcelApiExporter();
|
JExcelApiExporter exporterXLS = new JExcelApiExporter();
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||||
|
|
||||||
//As duas propriedades são para quando o arquivo xls chegar no máximo de linhas pular para a próxima aba do arquivo mantis #11294
|
// As duas propriedades são para quando o arquivo xls chegar no máximo de linhas pular para a próxima aba do arquivo mantis #11294
|
||||||
exporterXLS.setParameter(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
|
exporterXLS.setParameter(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
|
||||||
exporterXLS.setParameter(JExcelApiExporterParameter.MAXIMUM_ROWS_PER_SHEET, 65500);
|
exporterXLS.setParameter(JExcelApiExporterParameter.MAXIMUM_ROWS_PER_SHEET, 65500);
|
||||||
|
|
||||||
exporterXLS.setParameter(JExcelApiExporterParameter.JASPER_PRINT, this.jasperPrint);
|
exporterXLS.setParameter(JExcelApiExporterParameter.JASPER_PRINT, this.jasperPrint);
|
||||||
exporterXLS.setParameter(JExcelApiExporterParameter.OUTPUT_STREAM, output);
|
exporterXLS.setParameter(JExcelApiExporterParameter.OUTPUT_STREAM, output);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue