org.efaps.admin.program.jasper.JasperUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of efaps-kernel Show documentation
Show all versions of efaps-kernel Show documentation
eFaps is a framework used to map objects with or without attached files to
a relational database and optional file systems (only for attaches files). Configurable access control can be provided down to object and attribute level depending on implementation and use case. Depending on requirements, events (like triggers) allow to implement business logic and to separate business logic from user interface.
The framework includes integrations (e.g. webdav, full text search) and a web application as 'simple' configurable user interface. Some best practises, example web application modules (e.g. team work module) support administrators and implementers using this framework.
/*
* Copyright 2003 - 2011 The eFaps Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Revision: $Rev: 6210 $
* Last Changed: $Date: 2011-02-18 16:02:56 -0500 (Fri, 18 Feb 2011) $
* Last Changed By: $Author: [email protected] $
*/
package org.efaps.admin.program.jasper;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JRCompiler;
import net.sf.jasperreports.engine.design.JRDesignField;
import net.sf.jasperreports.engine.design.JRDesignGroup;
import net.sf.jasperreports.engine.design.JRDesignQuery;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.util.JRProperties;
import net.sf.jasperreports.engine.xml.JRXmlDigesterFactory;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import org.apache.commons.digester.Digester;
import org.efaps.db.Checkout;
import org.efaps.db.Instance;
import org.efaps.util.EFapsException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
import ar.com.fdvs.dj.core.DJDefaultScriptlet;
import ar.com.fdvs.dj.core.DJJRDesignHelper;
import ar.com.fdvs.dj.core.DynamicJasperHelper;
import ar.com.fdvs.dj.core.layout.LayoutManager;
import ar.com.fdvs.dj.core.registration.ColumnRegistrationManager;
import ar.com.fdvs.dj.core.registration.DJGroupRegistrationManager;
import ar.com.fdvs.dj.core.registration.DJGroupVariableDefRegistrationManager;
import ar.com.fdvs.dj.domain.ColumnProperty;
import ar.com.fdvs.dj.domain.DJCalculation;
import ar.com.fdvs.dj.domain.DynamicJasperDesign;
import ar.com.fdvs.dj.domain.DynamicReport;
import ar.com.fdvs.dj.domain.DynamicReportOptions;
import ar.com.fdvs.dj.domain.constants.Page;
import ar.com.fdvs.dj.domain.entities.DJGroup;
import ar.com.fdvs.dj.domain.entities.DJGroupVariableDef;
import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn;
import ar.com.fdvs.dj.domain.entities.columns.PercentageColumn;
import ar.com.fdvs.dj.util.LayoutUtils;
/**
* Util class used for jaspereport and dynamic jasper due to massive problems
* with the used classloaders and diggesters.
*
* @author The eFaps Team
* @version $Id: JasperUtil.java 6210 2011-02-18 21:02:56Z [email protected] $
*/
public final class JasperUtil
extends DynamicJasperHelper
{
/**
* Logger for this class.
*/
private static final Logger LOG = LoggerFactory.getLogger(JasperUtil.class);
/**
* Singelton util class.
*/
private JasperUtil()
{
}
/**
* Get a JasperDesign for an instance.
*
* @param _instance Instance the JasperDesign is wanted for
* @return JasperDesign
* @throws EFapsException on error
*/
public static JasperDesign getJasperDesign(final Instance _instance)
throws EFapsException
{
final Checkout checkout = new Checkout(_instance);
checkout.preprocess();
final InputStream source = checkout.execute();
JasperDesign jasperDesign = null;
try {
final Digester digester = new Digester();
JRXmlDigesterFactory.configureDigester(digester);
final JRXmlLoader loader = new JRXmlLoader(digester);
jasperDesign = loader.loadXML(source);
} catch (final ParserConfigurationException e) {
throw new EFapsException(JasperUtil.class, "getJasperDesign", e);
} catch (final SAXException e) {
throw new EFapsException(JasperUtil.class, "getJasperDesign", e);
} catch (final JRException e) {
throw new EFapsException(JasperUtil.class, "getJasperDesign", e);
}
return jasperDesign;
}
/**
* Create a jasperprint with a template. The method is basically the same as
* the method with the same name in DynamicJasperHelper
. Due to
* the problem that the templates can only be passed as file url this
* workaround was necessary.
*
* @param _dynReport DynamicReport
* @param _layoutManager LayoutManager
* @param _dataSource JRDataSource
* @param _parameters Map
* @param _template JasperDesign
* @return JasperPrint
* @throws EFapsException on error
*/
@SuppressWarnings("unchecked")
public static JasperPrint generateJasperPrint(final DynamicReport _dynReport,
final LayoutManager _layoutManager,
final JRDataSource _dataSource,
final Map, ?> _parameters,
final JasperDesign _template)
throws EFapsException
{
JasperPrint jp = null;
try {
Map, ?> parameters;
if (_parameters == null) {
parameters = new HashMap