From 482d09a055d20f59215b942b8c5d4457dae500d7 Mon Sep 17 00:00:00 2001 From: aristides Date: Wed, 4 Jul 2018 13:45:40 +0000 Subject: [PATCH] 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-87c2c4800839 --- .../render/RenderRelatorioJasper.java | 75 +++++++++++-------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/render/RenderRelatorioJasper.java b/src/java/com/rjconsultores/ventaboletos/relatorios/render/RenderRelatorioJasper.java index 6c0fffbe7..620b9048c 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/render/RenderRelatorioJasper.java +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/render/RenderRelatorioJasper.java @@ -6,12 +6,14 @@ import java.util.Locale; import java.util.ResourceBundle; import net.sf.jasperreports.engine.JRDataSource; +import net.sf.jasperreports.engine.JRParagraph; import net.sf.jasperreports.engine.JRParameter; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.export.JExcelApiExporter; import net.sf.jasperreports.engine.export.JExcelApiExporterParameter; +import net.sf.jasperreports.engine.util.JRProperties; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -27,13 +29,13 @@ import com.rjconsultores.ventaboletos.utilerias.LocaleUtil; * */ public class RenderRelatorioJasper { - + private static Logger log = Logger.getLogger(Relatorio.class); protected JasperPrint jasperPrint; private Relatorio relatorio; - + /** * @param relatorio * 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 { this.relatorio = relatorio; } - + public void preRender() { this.initBundler(); this.initLocale(); @@ -55,22 +57,22 @@ public class RenderRelatorioJasper { private void initBundler() { // TODO Alterar para injeção de acordo com usuário logado ou outro meio para obter o Locale correto - + Locale locale = LocaleUtil.getLocale(); try { - + ResourceBundle resource = ResourceBundle.getBundle("com.rjconsultores.ventaboletos.relatorios.internacionalizacao." + this.relatorio.getNome(), locale); this.relatorio.getParametros().put(JRParameter.REPORT_RESOURCE_BUNDLE, resource); /* 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().length == 1 && StringUtils.isNotBlank(this.relatorio.getNomeSubReporte()[0])) { + if (this.relatorio.getNomeSubReporte() != null && this.relatorio.getNomeSubReporte().length > 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); 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; 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); this.relatorio.getParametros().put("SUBREPORT_RESOURCE_BUNDLE" + "_" + (++indice), resourceSubReporte); } @@ -78,7 +80,7 @@ public class RenderRelatorioJasper { } } } catch (Exception e) { - log.error(e.getMessage(),e); + log.error(e.getMessage(), e); } } @@ -108,29 +110,42 @@ public class RenderRelatorioJasper { this.preRender(); byte[] conteudo = null; - - if (this.jasperPrint == null) { + try { + if (this.jasperPrint == null) { - if (this.relatorio.isCollectionDataSource()) { - this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), this.relatorio.getCollectionDataSource()); - } 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()); + if (this.relatorio.isCollectionDataSource()) { + if (!StringUtils.isBlank(this.relatorio.getNome()) && this.relatorio.getNome().equalsIgnoreCase("RelatorioGratuidade")) { + JRProperties.setProperty(JRParagraph.DEFAULT_TAB_STOP_WIDTH, "10"); + } + this.jasperPrint = JasperFillManager.fillReport(this.getTemplateInputStream(), this.relatorio.getParametros(), this.relatorio.getCollectionDataSource()); + + } 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: - conteudo = this.renderPdf(); - break; + case PDF: + conteudo = this.renderPdf(); + break; - case XLS: - conteudo = this.renderXls(isCustomXls); - break; + case XLS: + conteudo = this.renderXls(isCustomXls); + 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; @@ -139,11 +154,11 @@ public class RenderRelatorioJasper { protected byte[] renderXls(boolean isCustomXls) throws Exception { JExcelApiExporter exporterXLS = new JExcelApiExporter(); 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.MAXIMUM_ROWS_PER_SHEET, 65500); - + exporterXLS.setParameter(JExcelApiExporterParameter.JASPER_PRINT, this.jasperPrint); exporterXLS.setParameter(JExcelApiExporterParameter.OUTPUT_STREAM, output);