Permalink
Browse files

* DynamicReportBuilder.setDefaultEncoding(String) to use as default e…

…ncoding in the report.

* Version 5.0.11
  • Loading branch information...
1 parent a594cf0 commit 97dff196d137daa43f6eb1b62451d640620cb1f2 @juanalvarezg juanalvarezg committed Sep 29, 2016
View
@@ -31,7 +31,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ar.com.fdvs</groupId>
<artifactId>DynamicJasper</artifactId>
- <version>5.0.11-SNAPSHOT</version>
+ <version>5.0.11</version>
<name>DynamicJasper</name>
<packaging>jar</packaging>
<description>
@@ -34,6 +34,16 @@
<author email="juan.alvarez@fdvsolutions.com">Juan Manuel Alvarez</author>
</properties>
<body>
+ <release version="5.0.11" date="2016-09-28" desc="">
+ <action dev="Juan Manuel Alvarez" type="Add" >
+ <![CDATA[Introducing JasperDesignDecorator. This enables you to tweak the JasperDesign object
+ before and after applying the layout. Check for JasperDesignDecoratorReportTest for an example]]>
+ </action>
+ <action dev="Juan Manuel Alvarez" type="Add" >
+ <![CDATA[DynamicReportBuilder.setDefaultEncoding(String) to use as default encoding in the report. Useful when
+exporting to PDF. Checkout DefaultEncodingReportTest for an example.]]>
+ </action>
+ </release>
<release version="5.0.10" date="2016-08-15" desc="">
<action dev="Juan Manuel Alvarez" type="Add" due-to="NerdKnight">
<![CDATA[AutoText Page X, and Page X / Y supports passing an offset for the starting page.
@@ -250,6 +250,11 @@ protected void ensureDJStyles() {
*/
public void addStyleToDesign(Style style) {
JRDesignStyle jrstyle = style.transform();
+
+ if (style.getFont() != null && style.getFont().getPdfFontEncoding() == null && getReport().getDefaultEncoding() != null) {
+ style.getFont().setPdfFontEncoding(getReport().getDefaultEncoding());
+ }
+
try {
if (jrstyle.getName() == null) {
String name = createUniqueStyleName();
@@ -48,10 +48,8 @@
public class DynamicReport extends DJBaseElement {
private static final long serialVersionUID = Entity.SERIAL_VERSION_UID;
-
+ protected Map fontsMap = new HashMap(); //<String, java.awt.Font>
private String reportName;
-
-
/**
Sets the language of the expressions used in the report
* (can be one of java, groovy, or javascript).
@@ -64,23 +62,17 @@
*
*/
private String language = DJConstants.REPORT_LANGUAGE_JAVA;
-
private String title;
private boolean titleIsJrExpression = false;
-
private String subtitle;
private Style titleStyle = new StyleBuilder(false,"reportTitleStyle")
.setStretching(Stretching.NO_STRETCH)
.build();
private Style subtitleStyle = new StyleBuilder(false,"reportSubtitleStyle")
.setStretching(Stretching.NO_STRETCH)
.build();
-
private Locale reportLocale = Locale.getDefault();
private String resourceBundle = null;
-
- protected Map fontsMap = new HashMap(); //<String, java.awt.Font>
-
private List<AbstractColumn> columns = new ArrayList<AbstractColumn>();
//<ColumnsGroup>
@@ -152,6 +144,18 @@
private JasperDesignDecorator jasperDesignDecorator;
+ private String defaultEncoding;
+
+ public DynamicReport() {}
+
+ public DynamicReport(String title, List columns, List columnsGroups, List charts, DynamicReportOptions options) {
+ this.title = title;
+ this.columns = columns;
+ this.columnsGroups = columnsGroups;
+ this.charts = charts;
+ this.options = options;
+ }
+
public void addStyle(Style style) {
styles.put(style.getName(), style);
}
@@ -168,16 +172,6 @@ public void setProperty(String name, String value) {
properties.put(name, value);
}
- public DynamicReport() {}
-
- public DynamicReport(String title, List columns, List columnsGroups, List charts, DynamicReportOptions options) {
- this.title = title;
- this.columns = columns;
- this.columnsGroups = columnsGroups;
- this.charts = charts;
- this.options = options;
- }
-
public String getTitle() {
return title;
}
@@ -363,14 +357,14 @@ public List getParameters() {
return parameters;
}
- public void addParameter(String name, String className){
- this.parameters.add(new Parameter(name, className));
- }
-
public void setParameters(List parameters) {
this.parameters = parameters;
}
+ public void addParameter(String name, String className){
+ this.parameters.add(new Parameter(name, className));
+ }
+
public boolean isAllowDetailSplit() {
return allowDetailSplit;
}
@@ -490,11 +484,19 @@ public void setWaterMark(DJWaterMark waterMark) {
this.waterMark = waterMark;
}
+ public JasperDesignDecorator getJasperDesignDecorator() {
+ return jasperDesignDecorator;
+ }
+
public void setJasperDesignDecorator(JasperDesignDecorator jasperDesignDecorator) {
this.jasperDesignDecorator = jasperDesignDecorator;
}
- public JasperDesignDecorator getJasperDesignDecorator() {
- return jasperDesignDecorator;
- }
+ public String getDefaultEncoding() {
+ return defaultEncoding;
+ }
+
+ public void setDefaultEncoding(String defaultEncoding) {
+ this.defaultEncoding = defaultEncoding;
+ }
}
@@ -1709,4 +1709,9 @@ public DynamicReportBuilder setJasperDesignDecorator(JasperDesignDecorator jaspe
this.report.setJasperDesignDecorator(jasperDesignDecorator);
return this;
}
+
+ public DynamicReportBuilder setDefaultEncoding(String encoding) {
+ this.report.setDefaultEncoding(encoding);
+ return this;
+ }
}
@@ -157,6 +157,7 @@ public Font(int fontSize, String fontName, boolean bold, boolean italic, boolean
public Font(int fontSize, String fontName, boolean bold) {
this.fontSize = fontSize;
this.fontName = fontName;
+ this.pdfFontName = fontName;
this.bold = bold;
}
@@ -0,0 +1,149 @@
+/*
+ * DynamicJasper: A library for creating reports dynamically by specifying
+ * columns, groups, styles, etc. at runtime. It also saves a lot of development
+ * time in many cases! (http://sourceforge.net/projects/dynamicjasper)
+ *
+ * Copyright (C) 2008 FDV Solutions (http://www.fdvsolutions.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ *
+ * License as published by the Free Software Foundation; either
+ *
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ *
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ *
+ */
+
+package ar.com.fdvs.dj.test.encoding;
+
+
+import ar.com.fdvs.dj.domain.DJCalculation;
+import ar.com.fdvs.dj.domain.DJValueFormatter;
+import ar.com.fdvs.dj.domain.DynamicReport;
+import ar.com.fdvs.dj.domain.Style;
+import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
+import ar.com.fdvs.dj.domain.constants.Font;
+import ar.com.fdvs.dj.test.BaseDjReportTest;
+import ar.com.fdvs.dj.test.ReportExporter;
+import ar.com.fdvs.dj.test.domain.Product;
+import net.sf.jasperreports.engine.JRDataSource;
+import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
+import net.sf.jasperreports.view.JasperDesignViewer;
+import net.sf.jasperreports.view.JasperViewer;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+public class DefaultEncodingReportTest extends BaseDjReportTest {
+
+ public static final String PDF_FONT_ENCODING = "ISO-8859-2";
+
+ /**
+ * For a list of supported encodings: http://docs.oracle.com/javase/6/docs/technotes/guides/intl/encoding.doc.html
+ */
+
+
+ public DynamicReport buildReport() throws Exception {
+
+
+ Style titleStyle = Style.createBlankStyle("title");
+ Style subtitleStyle = Style.createBlankStyle("subtitleStyle");
+ Style headerStyle = Style.createBlankStyle("headerStyle");
+ Style detailStyle = Style.createBlankStyle("detailStyle");
+
+ String encoding = PDF_FONT_ENCODING;
+
+ log.debug("ENCODING IS: " + encoding);
+
+ titleStyle.setFont(new Font(18, "Arial", true));
+ subtitleStyle.setFont(new Font(14, "Arial", false));
+ detailStyle.setFont(new Font(10, "Arial", false));
+
+ /**
+ * Creates the DynamicReportBuilder and sets the basic options for
+ * the report
+ */
+ FastReportBuilder drb = new FastReportBuilder();
+ drb.addColumn("State", "state", String.class.getName(), 30)
+ .addColumn("Branch", "branch", String.class.getName(), 30)
+ .addColumn("Product Line", "productLine", String.class.getName(), 50)
+ .addColumn("Item", "item", String.class.getName(), 50)
+ .addColumn("Item Code", "id", Long.class.getName(), 30, true)
+ .addColumn("Quantity", "quantity", Long.class.getName(), 60, true)
+ .addColumn("Amount", "amount", Float.class.getName(), 70, true)
+ .addGroups(2)
+ .setTitle("Report with Polish letters")
+ .setSubtitle("ĄĆ\tĘ\tŁ\tŃ\tÓ\tŚ\tŹ\tŻ\tą\tć\tę\tł\tń\tó\tś\tź\tż")
+ .setPrintBackgroundOnOddRows(true)
+ .setDefaultStyles(titleStyle, subtitleStyle, headerStyle, detailStyle)
+ .setDefaultEncoding(encoding)
+ .setUseFullPageWidth(true);
+
+ drb.addGlobalFooterVariable(drb.getColumn(4), DJCalculation.COUNT, null, new DJValueFormatter() {
+
+ public String getClassName() {
+ return String.class.getName();
+ }
+
+
+ public Object evaluate(Object value, Map fields, Map variables, Map parameters) {
+ return (value == null ? "0" : value.toString()) + " Clients";
+ }
+ });
+
+
+ DynamicReport dr = drb.build();
+
+ return dr;
+ }
+
+ public static Collection getDummyCollection() {
+
+ SimpleDateFormat dateFormat = new SimpleDateFormat();
+ dateFormat.applyPattern("dd/MM/yyyy");
+
+ List col = new ArrayList();
+
+ //The collection is ordered by State, Branch and Product Line
+ col.add(new Product(1l, "book", "ąćęłńóśźż", "abcdefghaijkslmnopqĄĆĘŁŃÓŚŹŻĄĆĘŁŃÓŚŹŻĄĆĘŁŃÓŚŹŻĄĆĘŁŃÓŚŹŻĄĆĘŁŃÓŚŹŻĄĆĘŁ", "Main Street", new Long("2500"), new Float("5")));
+ col.add(new Product(1l, "book", "áñö", "ĄĆĘŁŃÓŚŹŻ", "Main Street", new Long("2500"), new Float("5")));
+ return col;
+ }
+
+ @Override
+ protected void exportReport() throws Exception {
+ ReportExporter.exportReport(jp, System.getProperty("user.dir") + "/target/reports/" + this.getClass().getName() + ".pdf");
+ ReportExporter.exportReportXls(jp, System.getProperty("user.dir") + "/target/reports/" + this.getClass().getName() + ".xls");
+ exportToJRXML();
+ }
+
+ @Override
+ protected JRDataSource getDataSource() {
+ return new JRBeanCollectionDataSource(getDummyCollection());
+ }
+
+ public static void main(String[] args) throws Exception {
+ DefaultEncodingReportTest test = new DefaultEncodingReportTest();
+ test.testReport();
+ test.exportToJRXML();
+ JasperViewer.viewReport(test.jp); //finally display the report report
+ JasperDesignViewer.viewReportDesign(test.jr);
+ }
+
+}

0 comments on commit 97dff19

Please sign in to comment.