ar.com.fdvs.dj.domain.ExpressionHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of DynamicJasper Show documentation
Show all versions of DynamicJasper Show documentation
DynamicJasper (DJ) is an API that hides the complexity of Jasper
Reports, it helps developers to save time when designing
simple/medium complexity reports generating the layout of the
report elements automatically. It creates reports dynamically,
defining at runtime the columns, column width (auto width), groups,
variables, fonts, charts, crosstabs, sub reports (that can also be dynamic), page size
and everything else that you can define at design time.
DJ keeps full compatibility with Jasper Reports since
it's a tool that helps create reports programmatically in
a easy way (it only interferes with the creation of the report
design doing the layout of the elements).
You can use the classic .jrxml files as templates while the
content and layout of the report elements are handled by the DJ
API.
http://dynamicjasper.com
package ar.com.fdvs.dj.domain;
import ar.com.fdvs.dj.domain.entities.Entity;
import ar.com.fdvs.dj.util.customexpression.PageNumberCustomExpression;
import ar.com.fdvs.dj.util.customexpression.RecordsInPageCustomExpression;
import ar.com.fdvs.dj.util.customexpression.RecordsInReportCustomExpression;
import java.util.Map;
public class ExpressionHelper {
private static final BooleanExpression printInFirstPage = new PrintInFirstPage();
private static final BooleanExpression printNotInFirstPage = new PrintNotInFirstPage();
private static final CustomExpression pageNumber = new PageNumberCustomExpression();
private static final CustomExpression recordsInPage = new RecordsInPageCustomExpression();
private static final CustomExpression recordsInReport = new RecordsInReportCustomExpression();
public static BooleanExpression printInFirstPage() {
return printInFirstPage;
}
public static BooleanExpression printNotInFirstPage() {
return printNotInFirstPage;
}
/**
* Convenient CustomExpression that returns page number
*/
public static CustomExpression getPageNumber() {
return pageNumber;
}
/**
* Convenient CustomExpression that returns the record number for the current page
*/
public static CustomExpression getRecordsInPage() {
return recordsInPage;
}
/**
* Convenient CustomExpression that returns the record number for whole report
*/
public static CustomExpression getRecordsInReport() {
return recordsInReport;
}
public static BooleanExpression printWhenGroupHasMoreThanOneRecord(final String groupName) {
return new BooleanExpression() {
private static final long serialVersionUID = Entity.SERIAL_VERSION_UID;
public Object evaluate(Map fields, Map variables, Map parameters) {
return getGroupCount(groupName, variables) > 1;
}
};
}
public static int getPageNumber(Map variables) {
return (Integer) variables.get("PAGE_NUMBER");
}
public static int getGroupCount(String groupName, Map variables) {
return (Integer) variables.get(groupName + "_COUNT");
}
private static class PrintInFirstPage extends BooleanExpression {
private static final long serialVersionUID = Entity.SERIAL_VERSION_UID;
public Object evaluate(Map fields, Map variables, Map parameters) {
return getPageNumber(variables) == 1;
}
}
private static class PrintNotInFirstPage extends BooleanExpression {
private static final long serialVersionUID = Entity.SERIAL_VERSION_UID;
public Object evaluate(Map fields, Map variables, Map parameters) {
return getPageNumber(variables) > 1;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy