Search in sources :

Example 1 with JasperCompileManager

use of net.sf.jasperreports.engine.JasperCompileManager in project opennms by OpenNMS.

the class JasperReportService method compileReport.

/**
 * Compiles the given {@link JasperDesign} (*.jrxml) to a {@link JasperReport} (*.jasper)
 *
 * @param jasperDesign The Design (*.jrxml) to compile
 * @return The compiled report (*.jasper)
 * @throws ReportException If the design could not be compiled.
 */
private JasperReport compileReport(JasperDesign jasperDesign) throws ReportException {
    try {
        JasperReport report;
        // If the target report is written in Java, use our custom JDT compiler
        if (JRReport.LANGUAGE_JAVA.equals(jasperDesign.getLanguage())) {
            JasperReportsContext reportsContext = new SimpleJasperReportsContext();
            JRPropertiesUtil.getInstance(reportsContext).setProperty(JRCompiler.COMPILER_PREFIX + JRReport.LANGUAGE_JAVA, CustomJRJdtCompiler.class.getCanonicalName());
            JasperCompileManager jasperCompilerManager = JasperCompileManager.getInstance(reportsContext);
            report = jasperCompilerManager.compile(jasperDesign);
        } else {
            // Otherwise, use the default that Jasper providers
            report = JasperCompileManager.compileReport(jasperDesign);
        }
        for (Object eachKey : System.getProperties().keySet()) {
            String eachStringKey = (String) eachKey;
            if (eachStringKey.startsWith("net.sf.jasperreports")) {
                report.setProperty(eachStringKey, System.getProperty(eachStringKey));
            }
        }
        compileSubreportsRecursively(report);
        return report;
    } catch (final JRException e) {
        LOG.error("unable to compile jasper report {}", e);
        throw new ReportException("unable to compile jasperReport", e);
    }
}
Also used : CustomJRJdtCompiler(org.opennms.reporting.jasperreports.compiler.CustomJRJdtCompiler) JRException(net.sf.jasperreports.engine.JRException) SimpleJasperReportsContext(net.sf.jasperreports.engine.SimpleJasperReportsContext) ReportException(org.opennms.api.reporting.ReportException) JasperReport(net.sf.jasperreports.engine.JasperReport) JasperCompileManager(net.sf.jasperreports.engine.JasperCompileManager) SimpleJasperReportsContext(net.sf.jasperreports.engine.SimpleJasperReportsContext) JasperReportsContext(net.sf.jasperreports.engine.JasperReportsContext)

Aggregations

JRException (net.sf.jasperreports.engine.JRException)1 JasperCompileManager (net.sf.jasperreports.engine.JasperCompileManager)1 JasperReport (net.sf.jasperreports.engine.JasperReport)1 JasperReportsContext (net.sf.jasperreports.engine.JasperReportsContext)1 SimpleJasperReportsContext (net.sf.jasperreports.engine.SimpleJasperReportsContext)1 ReportException (org.opennms.api.reporting.ReportException)1 CustomJRJdtCompiler (org.opennms.reporting.jasperreports.compiler.CustomJRJdtCompiler)1