Centralize reporting API in ReportingUtils class
authorCarlos Aristu <carlos.aristu@openbravo.com>
Wed, 06 May 2015 18:24:45 +0200
changeset 26738 acc1ac7b36bd
parent 26419 628d66d2161b
child 26739 a356e9b1cf69
Centralize reporting API in ReportingUtils class
modules/org.openbravo.client.application/src/org/openbravo/client/application/report/ReportingUtils.java
src/org/openbravo/base/secureApp/HttpSecureAppServlet.java
src/org/openbravo/erpCommon/ad_process/JasperProcess.java
src/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast.java
src/org/openbravo/erpCommon/ad_reports/ReportProductionJR.java
src/org/openbravo/erpCommon/ad_reports/ReportStandardCostJR.java
src/org/openbravo/erpCommon/utility/GridBO.java
src/org/openbravo/erpCommon/utility/GridReportVO.java
src/org/openbravo/erpCommon/utility/PrintJR.java
src/org/openbravo/erpCommon/utility/ReportDesignBO.java
src/org/openbravo/erpCommon/utility/reporting/ReportManager.java
src/org/openbravo/erpCommon/utility/reporting/printing/PrintController.java
src/org/openbravo/erpReports/RptC_Invoice.java
src/org/openbravo/erpReports/RptC_Order.java
src/org/openbravo/erpReports/RptC_OrderPO.java
src/org/openbravo/erpReports/RptC_ProposalJr.java
src/org/openbravo/erpReports/RptM_Requisition.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/report/ReportingUtils.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/report/ReportingUtils.java	Wed May 06 18:24:45 2015 +0200
@@ -19,23 +19,41 @@
 package org.openbravo.client.application.report;
 
 import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.sql.Connection;
+import java.sql.SQLException;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
+import javax.servlet.http.HttpSession;
+
+import net.sf.jasperreports.engine.JRDataSource;
 import net.sf.jasperreports.engine.JRException;
 import net.sf.jasperreports.engine.JRExporterParameter;
 import net.sf.jasperreports.engine.JRParameter;
+import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperExportManager;
 import net.sf.jasperreports.engine.JasperFillManager;
 import net.sf.jasperreports.engine.JasperPrint;
 import net.sf.jasperreports.engine.JasperReport;
+import net.sf.jasperreports.engine.design.JRDesignParameter;
+import net.sf.jasperreports.engine.design.JasperDesign;
 import net.sf.jasperreports.engine.export.JExcelApiExporter;
 import net.sf.jasperreports.engine.export.JExcelApiExporterParameter;
+import net.sf.jasperreports.engine.export.JRCsvExporter;
+import net.sf.jasperreports.engine.export.JRHtmlExporter;
+import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
 import net.sf.jasperreports.engine.fill.JRSwapFileVirtualizer;
 import net.sf.jasperreports.engine.util.JRSwapFile;
+import net.sf.jasperreports.engine.xml.JRXmlLoader;
+import net.sf.jasperreports.j2ee.servlets.ImageServlet;
 
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.session.OBPropertiesProvider;
@@ -44,11 +62,16 @@
 import org.openbravo.dal.core.DalContextListener;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.erpCommon.utility.GridReportVO;
+import org.openbravo.erpCommon.utility.JRFieldProviderDataSource;
 import org.openbravo.erpCommon.utility.JRFormatFactory;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
+import org.openbravo.erpCommon.utility.ReportDesignBO;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.ad.utility.FileType;
 import org.openbravo.service.db.DalConnectionProvider;
+import org.openbravo.utils.Replace;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -59,7 +82,8 @@
   private static final Logger log = LoggerFactory.getLogger(ReportingUtils.class);
 
   /**
-   * Exports the report to a file in a temporary folder.
+   * Exports the report to a file in a temporary folder. This method adds automatically the
+   * parameters needed to print a report from a Process Definition
    * 
    * @param jasperFilePath
    *          The path to the JR template of the report.
@@ -75,58 +99,519 @@
    */
   public static void exportJR(String jasperFilePath, ExportType expType,
       Map<String, Object> parameters, String strFileName) throws OBException {
+    File target = new File(getTempFolder(), strFileName);
+    exportJR(jasperFilePath, expType, parameters, target, true, null, null, null);
+  }
 
+  /**
+   * Exports the report to a file in a temporary folder.
+   * 
+   * @param jasperFilePath
+   *          The path to the JR template of the report.
+   * @param expType
+   *          The desired output type of the report.
+   * @param parameters
+   *          The parameters to be sent to Jasper Report.
+   * @param strFileName
+   *          The name to be used on the generated file.
+   * @param addProcessDefinitionParameters
+   *          A flag to indicate if the parameters needed to print a report from a Process
+   *          Definition should be added.
+   * @throws OBException
+   *           In case there is any error generating the file an exception is thrown with the error
+   *           message.
+   */
+  public static void exportJR(String jasperFilePath, ExportType expType,
+      Map<String, Object> parameters, String strFileName, boolean addProcessDefinitionParameters)
+      throws OBException {
+    File target = new File(getTempFolder(), strFileName);
+    exportJR(jasperFilePath, expType, parameters, target, addProcessDefinitionParameters, null,
+        null, null);
+  }
+
+  /**
+   * Exports the report to a file in a temporary folder.
+   * 
+   * @param jasperFilePath
+   *          The path to the JR template of the report.
+   * @param expType
+   *          The desired output type of the report.
+   * @param parameters
+   *          The parameters to be sent to Jasper Report.
+   * @param strFileName
+   *          The name to be used on the generated file.
+   * @param addProcessDefinitionParameters
+   *          A flag to indicate if the parameters needed to print a report from a Process
+   *          Definition should be added.
+   * @param connectionProvider
+   *          A connection provider in case the report needs it.
+   * @param data
+   *          The data to be used in the report, if required.
+   * @param additionalExportParameters
+   *          Additional export parameters than can be added to configure the resulting report.
+   * @throws OBException
+   *           In case there is any error generating the report an exception is thrown with the
+   *           error message.
+   */
+  public static void exportJR(String jasperFilePath, ExportType expType,
+      Map<String, Object> parameters, String strFileName, boolean addProcessDefinitionParameters,
+      ConnectionProvider connectionProvider, JRDataSource data,
+      Map<Object, Object> additionalExportParameters) throws OBException {
+    File target = new File(getTempFolder(), strFileName);
+    exportJR(jasperFilePath, expType, parameters, target, addProcessDefinitionParameters,
+        connectionProvider, data, additionalExportParameters);
+  }
+
+  /**
+   * Exports the report to a file, without compiling any sub-report.
+   * 
+   * @param jasperFilePath
+   *          The path to the JR template of the report.
+   * @param expType
+   *          The desired output type of the report.
+   * @param parameters
+   *          The parameters to be sent to Jasper Report.
+   * @param target
+   *          The file used to return the report.
+   * @param addProcessDefinitionParameters
+   *          A flag to indicate if the parameters needed to print a report from a Process
+   *          Definition should be added.
+   * @param connectionProvider
+   *          A connection provider in case the report needs it.
+   * @param data
+   *          The data to be used in the report, if required.
+   * @param additionalExportParameters
+   *          Additional export parameters than can be added to configure the resulting report.
+   * @throws OBException
+   *           In case there is any error generating the file an exception is thrown with the error
+   *           message.
+   */
+  public static void exportJR(String jasperFilePath, ExportType expType,
+      Map<String, Object> parameters, File target, boolean addProcessDefinitionParameters,
+      ConnectionProvider connectionProvider, JRDataSource data,
+      Map<Object, Object> additionalExportParameters) throws OBException {
+    exportJR(jasperFilePath, expType, parameters, target, addProcessDefinitionParameters,
+        connectionProvider, data, additionalExportParameters, false);
+  }
+
+  /**
+   * Exports the report to an output stream, without compiling any sub-report.
+   * 
+   * @param jasperFilePath
+   *          The path to the JR template of the report.
+   * @param expType
+   *          The desired output type of the report.
+   * @param parameters
+   *          The parameters to be sent to Jasper Report.
+   * @param outputStream
+   *          An output stream used to return the report.
+   * @param addProcessDefinitionParameters
+   *          A flag to indicate if the parameters needed to print a report from a Process
+   *          Definition should be added.
+   * @param connectionProvider
+   *          A connection provider in case the report needs it.
+   * @param data
+   *          The data to be used in the report, if required.
+   * @param additionalExportParameters
+   *          Additional export parameters than can be added to configure the resulting report.
+   * @throws OBException
+   *           In case there is any error generating the file an exception is thrown with the error
+   *           message.
+   */
+  public static void exportJR(String jasperFilePath, ExportType expType,
+      Map<String, Object> parameters, OutputStream outputStream,
+      boolean addProcessDefinitionParameters, ConnectionProvider connectionProvider,
+      JRDataSource data, Map<Object, Object> additionalExportParameters) throws OBException {
+    exportJR(jasperFilePath, expType, parameters, outputStream, addProcessDefinitionParameters,
+        connectionProvider, data, additionalExportParameters, false);
+  }
+
+  /**
+   * Exports the report to a file.
+   * 
+   * @param jasperFilePath
+   *          The path to the JR template of the report.
+   * @param expType
+   *          The desired output type of the report.
+   * @param parameters
+   *          The parameters to be sent to Jasper Report.
+   * @param target
+   *          The file used to return the report.
+   * @param addProcessDefinitionParameters
+   *          A flag to indicate if the parameters needed to print a report from a Process
+   *          Definition should be added.
+   * @param connectionProvider
+   *          A connection provider in case the report needs it.
+   * @param data
+   *          The data to be used in the report, if required.
+   * @param additionalExportParameters
+   *          Additional export parameters than can be added to configure the resulting report.
+   * @param compileSubreports
+   *          A flag to indicate if the sub-reports should be compiled too. If true, the sub-report
+   *          jrxml files should be placed in the same folder as the main report and their name
+   *          should start with SUBREP_
+   * @throws OBException
+   *           In case there is any error generating the report an exception is thrown with the
+   *           error message.
+   */
+  public static void exportJR(String jasperFilePath, ExportType expType,
+      Map<String, Object> parameters, File target, boolean addProcessDefinitionParameters,
+      ConnectionProvider connectionProvider, JRDataSource data,
+      Map<Object, Object> additionalExportParameters, boolean compileSubreports) throws OBException {
+
+    Map<Object, Object> exportParameters = new HashMap<Object, Object>();
+    parameters.putAll(expType.getExportParameters());
+    if (additionalExportParameters != null && additionalExportParameters.size() > 0) {
+      exportParameters.putAll(additionalExportParameters);
+    }
+    if (addProcessDefinitionParameters) {
+      addProcessDefinitionParameters(parameters);
+    }
+    JasperPrint jasperPrint = generateJasperPrint(jasperFilePath, parameters, compileSubreports,
+        connectionProvider, data);
+    if (expType == ExportType.HTML) {
+      HttpSession session = (HttpSession) parameters.get("HTTP_SESSION");
+      if (session != null) {
+        session.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
+      }
+    }
+    try {
+      saveReport(jasperPrint, expType, exportParameters, target);
+    } catch (JRException e) {
+      log.error("Error generating Jasper Report: " + jasperFilePath, e);
+      throw new OBException(e.getMessage(), e);
+    }
+  }
+
+  /**
+   * Exports the report to an output stream.
+   * 
+   * @param jasperFilePath
+   *          The path to the JR template of the report.
+   * @param expType
+   *          The desired output type of the report.
+   * @param parameters
+   *          The parameters to be sent to Jasper Report.
+   * @param outputStream
+   *          An output stream used to return the report.
+   * @param addProcessDefinitionParameters
+   *          A flag to indicate if the parameters needed to print a report from a Process
+   *          Definition should be added.
+   * @param connectionProvider
+   *          A connection provider in case the report needs it.
+   * @param data
+   *          The data to be used in the report, if required.
+   * @param additionalExportParameters
+   *          Additional export parameters than can be added to configure the resulting report.
+   * @param compileSubreports
+   *          A flag to indicate if the sub-reports should be compiled too. If true, the sub-report
+   *          jrxml files should be placed in the same folder as the main report and their name
+   *          should start with SUBREP_
+   * @throws OBException
+   *           In case there is any error generating the report an exception is thrown with the
+   *           error message.
+   */
+  public static void exportJR(String jasperFilePath, ExportType expType,
+      Map<String, Object> parameters, OutputStream outputStream,
+      boolean addProcessDefinitionParameters, ConnectionProvider connectionProvider,
+      JRDataSource data, Map<Object, Object> additionalExportParameters, boolean compileSubreports)
+      throws OBException {
+
+    Map<Object, Object> exportParameters = new HashMap<Object, Object>();
+    parameters.putAll(expType.getExportParameters());
+    if (additionalExportParameters != null && additionalExportParameters.size() > 0) {
+      exportParameters.putAll(additionalExportParameters);
+    }
+    if (addProcessDefinitionParameters) {
+      addProcessDefinitionParameters(parameters);
+    }
+    JasperPrint jasperPrint = generateJasperPrint(jasperFilePath, parameters, compileSubreports,
+        connectionProvider, data);
+    if (expType == ExportType.HTML) {
+      HttpSession session = (HttpSession) parameters.get("HTTP_SESSION");
+      if (session != null) {
+        session.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
+      }
+    }
+    try {
+      saveReport(jasperPrint, expType, exportParameters, outputStream);
+    } catch (JRException e) {
+      log.error("Error generating Jasper Report: " + jasperFilePath, e);
+      throw new OBException(e.getMessage(), e);
+    }
+  }
+
+  /**
+   * Saves a pre-compiled report into a file.
+   * 
+   * @param jasperPrint
+   *          JasperPrint object which contains a compiled report.
+   * @param expType
+   *          The desired output type of the report.
+   * @param exportParameters
+   *          Export parameters than can be added to configure the resulting report.
+   * @param target
+   *          The file used to return the report.
+   * @throws JRException
+   *           In case there is any error saving the report an exception is thrown with the error
+   *           message.
+   */
+  public static void saveReport(JasperPrint jasperPrint, ExportType expType,
+      Map<Object, Object> exportParameters, File target) throws JRException {
+    switch (expType) {
+    case CSV:
+      saveCsvReportToFile(jasperPrint, exportParameters, target);
+      break;
+    case HTML:
+      if (log.isDebugEnabled())
+        log.debug("JR: Print HTML");
+      saveHTMLReportToFile(jasperPrint, exportParameters, target);
+      break;
+    case PDF:
+      JasperExportManager.exportReportToPdfFile(jasperPrint, target.getAbsolutePath());
+      break;
+    case XLS:
+      saveExcelReportToFile(jasperPrint, exportParameters, target);
+      break;
+    case XML:
+      JasperExportManager.exportReportToXmlFile(jasperPrint, target.getAbsolutePath(), true);
+      break;
+    }
+  }
+
+  /**
+   * Returns a pre-compiled report into an Output Stream.
+   * 
+   * @param jasperPrint
+   *          JasperPrint object which contains a compiled report.
+   * @param expType
+   *          The desired output type of the report.
+   * @param exportParameters
+   *          Export parameters than can be added to configure the resulting report.
+   * @param outputStream
+   *          The output stream used to return the report.
+   * @throws JRException
+   *           In case there is any error generating the report an exception is thrown with the
+   *           error message.
+   */
+  public static void saveReport(JasperPrint jasperPrint, ExportType expType,
+      Map<Object, Object> exportParameters, OutputStream outputStream) throws JRException {
+    switch (expType) {
+    case CSV:
+      saveCsvReportToOutputStream(jasperPrint, exportParameters, outputStream);
+      break;
+    case HTML:
+      if (log.isDebugEnabled())
+        log.debug("JR: Print HTML");
+      saveHTMLReportToOutputStream(jasperPrint, exportParameters, outputStream);
+      break;
+    case PDF:
+      JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
+      break;
+    case XLS:
+      saveExcelReportToOutputStream(jasperPrint, exportParameters, outputStream);
+      break;
+    case XML:
+      JasperExportManager.exportReportToXmlStream(jasperPrint, outputStream);
+      break;
+    }
+  }
+
+  /**
+   * Generates an HTML report from a pre-compiled report and returns it into a file.
+   * 
+   * @param jasperPrint
+   *          JasperPrint object which contains a compiled report.
+   * @param exportParameters
+   *          Export parameters than can be added to configure the resulting report.
+   * @param file
+   *          The file used to return the report.
+   * @throws JRException
+   *           In case there is any error generating the report an exception is thrown with the
+   *           error message.
+   */
+  private static void saveHTMLReportToFile(JasperPrint jasperPrint,
+      Map<Object, Object> exportParameters, File file) throws JRException {
+    final JRHtmlExporter htmlExporter = new JRHtmlExporter();
+    Map<Object, Object> params = new HashMap<Object, Object>();
+    if (exportParameters != null && exportParameters.size() > 0) {
+      params.putAll(exportParameters);
+    }
+    params.put(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
+    params.put(JRHtmlExporterParameter.OUTPUT_FILE_NAME, file.getAbsolutePath());
+    params.put(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
+    params.put(JRHtmlExporterParameter.SIZE_UNIT, JRHtmlExporterParameter.SIZE_UNIT_POINT);
+    htmlExporter.setParameters(params);
+    htmlExporter.exportReport();
+  }
+
+  /**
+   * Generates an HTML report from a pre-compiled report and returns it into an output stream.
+   * 
+   * @param jasperPrint
+   *          JasperPrint object which contains a compiled report.
+   * @param exportParameters
+   *          Export parameters than can be added to configure the resulting report.
+   * @param outputStream
+   *          The output stream used to return the report.
+   * @throws JRException
+   *           In case there is any error generating the report an exception is thrown with the
+   *           error message.
+   */
+  private static void saveHTMLReportToOutputStream(JasperPrint jasperPrint,
+      Map<Object, Object> exportParameters, OutputStream outputStream) throws JRException {
+    final JRHtmlExporter htmlExporter = new JRHtmlExporter();
+    Map<Object, Object> params = new HashMap<Object, Object>();
+    if (exportParameters != null && exportParameters.size() > 0) {
+      params.putAll(exportParameters);
+    }
+    params.put(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
+    params.put(JRHtmlExporterParameter.OUTPUT_STREAM, outputStream);
+    params.put(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
+    params.put(JRHtmlExporterParameter.SIZE_UNIT, JRHtmlExporterParameter.SIZE_UNIT_POINT);
+    htmlExporter.setParameters(params);
+    htmlExporter.exportReport();
+  }
+
+  /**
+   * Generates an XLS report from a pre-compiled report and returns it into a file.
+   * 
+   * @param jasperPrint
+   *          JasperPrint object which contains a compiled report.
+   * @param exportParameters
+   *          Export parameters than can be added to configure the resulting report.
+   * @param file
+   *          The file used to return the report.
+   * @throws JRException
+   *           In case there is any error generating the report an exception is thrown with the
+   *           error message.
+   */
+  private static void saveExcelReportToFile(JasperPrint jasperPrint,
+      Map<Object, Object> exportParameters, File file) throws JRException {
+    JExcelApiExporter excelExporter = new JExcelApiExporter();
+    Map<Object, Object> params = new HashMap<Object, Object>();
+    if (exportParameters != null && exportParameters.size() > 0) {
+      params.putAll(exportParameters);
+    }
+    params.put(JRExporterParameter.JASPER_PRINT, jasperPrint);
+    params.put(JRExporterParameter.OUTPUT_FILE_NAME, file.getAbsolutePath());
+    params.put(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
+    params.put(JExcelApiExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
+    params.put(JExcelApiExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
+    excelExporter.setParameters(params);
+    excelExporter.exportReport();
+  }
+
+  /**
+   * Generates an XLS report from a pre-compiled report and returns it into an output stream.
+   * 
+   * @param jasperPrint
+   *          JasperPrint object which contains a compiled report.
+   * @param exportParameters
+   *          Export parameters than can be added to configure the resulting report.
+   * @param outputStream
+   *          The output stream used to return the report.
+   * @throws JRException
+   *           In case there is any error generating the report an exception is thrown with the
+   *           error message.
+   */
+  private static void saveExcelReportToOutputStream(JasperPrint jasperPrint,
+      Map<Object, Object> exportParameters, OutputStream outputStream) throws JRException {
+    JExcelApiExporter excelExporter = new JExcelApiExporter();
+    Map<Object, Object> params = new HashMap<Object, Object>();
+    if (exportParameters != null && exportParameters.size() > 0) {
+      params.putAll(exportParameters);
+    }
+    params.put(JRExporterParameter.JASPER_PRINT, jasperPrint);
+    params.put(JRExporterParameter.OUTPUT_STREAM, outputStream);
+    params.put(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
+    params.put(JExcelApiExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
+    params.put(JExcelApiExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
+    excelExporter.setParameters(params);
+    excelExporter.exportReport();
+  }
+
+  /**
+   * Generates a CSV report from a pre-compiled report and returns it into a file.
+   * 
+   * @param jasperPrint
+   *          JasperPrint object which contains a compiled report.
+   * @param exportParameters
+   *          Export parameters than can be added to configure the resulting report.
+   * @param file
+   *          The file used to return the report.
+   * @throws JRException
+   *           In case there is any error generating the report an exception is thrown with the
+   *           error message.
+   */
+  private static void saveCsvReportToFile(JasperPrint jasperPrint,
+      Map<Object, Object> exportParameters, File file) throws JRException {
+    JRCsvExporter csvExporter = new JRCsvExporter();
+    Map<Object, Object> params = new HashMap<Object, Object>();
+    if (exportParameters != null && exportParameters.size() > 0) {
+      params.putAll(exportParameters);
+    }
+    params.put(JRExporterParameter.JASPER_PRINT, jasperPrint);
+    params.put(JRExporterParameter.OUTPUT_FILE_NAME, file.getAbsolutePath());
+    csvExporter.setParameters(params);
+    csvExporter.exportReport();
+  }
+
+  /**
+   * Generates a CSV report from a pre-compiled report and returns it into an output stream.
+   * 
+   * @param jasperPrint
+   *          JasperPrint object which contains a compiled report.
+   * @param exportParameters
+   *          Export parameters than can be added to configure the resulting report.
+   * @param outputStream
+   *          The output stream used to return the report.
+   * @throws JRException
+   *           In case there is any error generating the report an exception is thrown with the
+   *           error message.
+   */
+  private static void saveCsvReportToOutputStream(JasperPrint jasperPrint,
+      Map<Object, Object> exportParameters, OutputStream outputStream) throws JRException {
+    JRCsvExporter csvExporter = new JRCsvExporter();
+    Map<Object, Object> params = new HashMap<Object, Object>();
+    if (exportParameters != null && exportParameters.size() > 0) {
+      params.putAll(exportParameters);
+    }
+    params.put(JRExporterParameter.JASPER_PRINT, jasperPrint);
+    params.put(JRExporterParameter.OUTPUT_STREAM, outputStream);
+    csvExporter.setParameters(params);
+    csvExporter.exportReport();
+  }
+
+  /**
+   * Generates a compiled, translated and filled report into a JasperPrint object.
+   * 
+   * @param jasperFilePath
+   *          The path to the JR template of the report.
+   * @param parameters
+   *          The parameters to be sent to Jasper Report.
+   * @param compileSubreports
+   *          A flag to indicate if the sub-reports of the report should be compiled too. If true,
+   *          the sub-report jrxml files should be placed in the same folder as the main report and
+   *          their name should start with SUBREP_
+   * @param connectionProvider
+   *          A connection provider in case the report needs it.
+   * @param data
+   *          The data to be used in the report, if required.
+   * @return A JasperPrint object with the compiled, translated and filled report.
+   * @throws OBException
+   *           In case there is any error processing the report an exception is thrown with the
+   *           error message.
+   */
+  public static JasperPrint generateJasperPrint(String jasperFilePath,
+      Map<String, Object> parameters, boolean compileSubreports,
+      ConnectionProvider connectionProvider, JRDataSource data) throws OBException {
+
+    JasperPrint jasperPrint = null;
     JRSwapFileVirtualizer virtualizer = null;
+    String language = OBContext.getOBContext().getLanguage().getLanguage();
     try {
-      parameters.put(JASPER_PARAM_HBSESSION, OBDal.getInstance().getSession());
-      parameters.put(JASPER_PARAM_OBCONTEXT, OBContext.getOBContext());
-      parameters.putAll(expType.getExportParameters());
-
-      {
-        final FormatDefinition reportFormat = UIDefinitionController.getInstance()
-            .getFormatDefinition("amount", UIDefinitionController.NORMALFORMAT_QUALIFIER);
-
-        final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
-        dfs.setDecimalSeparator(reportFormat.getDecimalSymbol().charAt(0));
-        dfs.setGroupingSeparator(reportFormat.getGroupingSymbol().charAt(0));
-
-        final DecimalFormat numberFormat = new DecimalFormat(correctMaskForGrouping(
-            reportFormat.getFormat(), reportFormat.getDecimalSymbol(),
-            reportFormat.getGroupingSymbol()), dfs);
-        parameters.put("AMOUNTFORMAT", numberFormat);
-      }
-
-      {
-        final FormatDefinition reportFormat = UIDefinitionController.getInstance()
-            .getFormatDefinition("generalQty", UIDefinitionController.SHORTFORMAT_QUALIFIER);
-
-        final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
-        dfs.setDecimalSeparator(reportFormat.getDecimalSymbol().charAt(0));
-        dfs.setGroupingSeparator(reportFormat.getGroupingSymbol().charAt(0));
-
-        final DecimalFormat numberFormat = new DecimalFormat(correctMaskForGrouping(
-            reportFormat.getFormat(), reportFormat.getDecimalSymbol(),
-            reportFormat.getGroupingSymbol()), dfs);
-        parameters.put("QUANTITYFORMAT", numberFormat);
-      }
-
-      final JRFormatFactory jrFormatFactory = new JRFormatFactory();
-      jrFormatFactory.setDatePattern((OBPropertiesProvider.getInstance().getOpenbravoProperties()
-          .getProperty("dateFormat.java")));
-      parameters.put(JRParameter.REPORT_FORMAT_FACTORY, jrFormatFactory);
-
-      String strClientId = OBContext.getOBContext().getCurrentClient().getId();
-      parameters.put("Current_Client_ID", strClientId);
-      String strOrgs = "";
-      boolean isNotFirst = false;
-      for (String strOrgId : OBContext.getOBContext().getReadableOrganizations()) {
-        if (isNotFirst) {
-          strOrgs += ",";
-        }
-        strOrgs += "'" + strOrgId + "'";
-        isNotFirst = true;
-      }
-      parameters.put("Readable_Organizations", strOrgs);
+      setReportFormatFactory(parameters);
 
       // if no custom virtualizer is requested use a default one
       if (!parameters.containsKey(JRParameter.REPORT_VIRTUALIZER)) {
@@ -150,36 +635,47 @@
         }
       }
 
-      JasperPrint jasperPrint = null;
       if (jasperFilePath.endsWith("jrxml")) {
         String strBaseDesign = DalContextListener.getServletContext().getRealPath("");
         JasperReport jReport = Utility.getTranslatedJasperReport(new DalConnectionProvider(false),
-            jasperFilePath, OBContext.getOBContext().getLanguage().getLanguage(), strBaseDesign);
-        jasperPrint = JasperFillManager.fillReport(jReport, parameters, OBDal.getInstance()
-            .getConnection());
-
+            jasperFilePath, language, strBaseDesign);
+        if (connectionProvider != null) {
+          if (compileSubreports) {
+            processSubReports(jasperFilePath, parameters, strBaseDesign, connectionProvider,
+                language);
+          }
+          Connection con = null;
+          try {
+            con = connectionProvider.getTransactionConnection();
+            if (data != null) {
+              parameters.put("REPORT_CONNECTION", con);
+              jasperPrint = JasperFillManager.fillReport(jReport, parameters, data);
+            } else {
+              jasperPrint = JasperFillManager.fillReport(jReport, parameters, con);
+            }
+          } catch (final Exception e) {
+            Throwable t = (e.getCause() != null) ? e.getCause().getCause() : null;
+            if (t != null) {
+              throw new OBException((t instanceof SQLException && t.getMessage().contains(
+                  "@NoConversionRate@")) ? t.getMessage() : e.getMessage(), e);
+            } else {
+              throw new OBException(e.getCause() instanceof SQLException ? e.getCause()
+                  .getMessage() : e.getMessage(), e);
+            }
+          } finally {
+            try {
+              connectionProvider.releaseRollbackConnection(con);
+            } catch (SQLException e) {
+            }
+          }
+        } else {
+          jasperPrint = JasperFillManager.fillReport(jReport, parameters, OBDal.getInstance()
+              .getConnection());
+        }
       } else {
         jasperPrint = JasperFillManager.fillReport(jasperFilePath, parameters);
       }
-      File target = new File(getTempFolder(), strFileName);
-
-      switch (expType) {
-      case PDF:
-        JasperExportManager.exportReportToPdfFile(jasperPrint, target.getAbsolutePath());
-        break;
-      case XLS:
-        JExcelApiExporter exporter = new JExcelApiExporter();
-        Map<Object, Object> exportParameters = new HashMap<Object, Object>();
-        exportParameters.put(JRExporterParameter.JASPER_PRINT, jasperPrint);
-        exportParameters.put(JRExporterParameter.OUTPUT_FILE_NAME, target.getAbsolutePath());
-        exportParameters.put(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
-        exportParameters.put(JExcelApiExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
-            Boolean.TRUE);
-        exportParameters.put(JExcelApiExporterParameter.IS_DETECT_CELL_TYPE, true);
-        exporter.setParameters(exportParameters);
-        exporter.exportReport();
-        break;
-      }
+      return jasperPrint;
     } catch (JRException e) {
       log.error("Error generating Jasper Report: " + jasperFilePath, e);
       throw new OBException(e.getMessage(), e);
@@ -192,6 +688,212 @@
   }
 
   /**
+   * Generates sub-reports and adds them into the parameter map.
+   * 
+   * @param templateFile
+   *          The path to the JR template of the report.
+   * @param parameters
+   *          The parameters to be sent to Jasper Report.
+   * @param baseDesignPath
+   *          Base design path.
+   * @param connectionProvider
+   *          A connection provider in case the report needs it.
+   * @param language
+   *          Language to be used when generating the sub-report.
+   * @throws OBException
+   *           In case there is any error generating the sub-reports an exception is thrown with the
+   *           error message.
+   */
+  private static void processSubReports(String templateFile, Map<String, Object> parameters,
+      String baseDesignPath, ConnectionProvider connectionProvider, String language)
+      throws OBException {
+    try {
+      JasperDesign jasperDesign = JRXmlLoader.load(templateFile);
+
+      Object[] parameterList = jasperDesign.getParametersList().toArray();
+      String parameterName = "";
+      String subReportName = "";
+      Collection<String> subreportList = new ArrayList<String>();
+      File template = new File(templateFile);
+      String templateLocation = template.getParent() + "/";
+
+      /*
+       * TODO: At present this process assumes the subreport is a .jrxml file. Need to handle the
+       * possibility that this subreport file could be a .jasper file.
+       */
+      for (int i = 0; i < parameterList.length; i++) {
+        final JRDesignParameter parameter = (JRDesignParameter) parameterList[i];
+        if (parameter.getName().startsWith("SUBREP_")) {
+          parameterName = parameter.getName();
+          subreportList.add(parameterName);
+          subReportName = Replace.replace(parameterName, "SUBREP_", "") + ".jrxml";
+          JasperReport jasperReportLines = createSubReport(templateLocation, subReportName,
+              baseDesignPath, connectionProvider, language);
+          parameters.put(parameterName, jasperReportLines);
+        }
+      }
+
+    } catch (final JRException exception) {
+      log.error(exception.getMessage());
+      exception.printStackTrace();
+      throw new OBException(exception);
+    }
+  }
+
+  /**
+   * Create a translated and compiled sub-report into a JasperReport object.
+   * 
+   * @param templateLocation
+   *          The location of the JR template of the sub-report.
+   * @param subReportFileName
+   *          The name of the sub-report jrxml file.
+   * @param baseDesignPath
+   *          Base design path.
+   * @param connectionProvider
+   *          A connection provider in case the report needs it.
+   * @param language
+   *          Language to be used when generating the sub-report.
+   * @return A JasperReport object with the compiled and translated sub-report.
+   */
+  private static JasperReport createSubReport(String templateLocation, String subReportFileName,
+      String baseDesignPath, ConnectionProvider connectionProvider, String language) {
+    JasperReport jasperReportLines = null;
+    try {
+      jasperReportLines = Utility.getTranslatedJasperReport(connectionProvider, templateLocation
+          + subReportFileName, language, baseDesignPath);
+    } catch (final JRException e1) {
+      log.error(e1.getMessage());
+      e1.printStackTrace();
+    }
+    return jasperReportLines;
+  }
+
+  /**
+   * Compiles a jrxml file generating a JasperReport object.
+   * 
+   * @param jasperFilePath
+   *          The path to the JR template of the report.
+   * @return A JasperReport object with the compiled report.
+   * @throws JRException
+   *           In case there is any error compiling the report an exception is thrown with the error
+   *           message.
+   */
+  public static JasperReport compileReport(String jasperFilePath) throws JRException {
+    JasperDesign jasperDesign = JRXmlLoader.load(jasperFilePath);
+    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
+    return jasperReport;
+  }
+
+  /**
+   * Adds the parameters needed to print a report from a standard process definition into the
+   * parameter map.
+   * 
+   * @param parameters
+   *          Map of parameters where the standard process definition parameters are added.
+   */
+  private static void addProcessDefinitionParameters(Map<String, Object> parameters) {
+    parameters.put(JASPER_PARAM_HBSESSION, OBDal.getInstance().getSession());
+    parameters.put(JASPER_PARAM_OBCONTEXT, OBContext.getOBContext());
+
+    {
+      final FormatDefinition reportFormat = UIDefinitionController.getInstance()
+          .getFormatDefinition("amount", UIDefinitionController.NORMALFORMAT_QUALIFIER);
+
+      final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
+      dfs.setDecimalSeparator(reportFormat.getDecimalSymbol().charAt(0));
+      dfs.setGroupingSeparator(reportFormat.getGroupingSymbol().charAt(0));
+
+      final DecimalFormat numberFormat = new DecimalFormat(correctMaskForGrouping(
+          reportFormat.getFormat(), reportFormat.getDecimalSymbol(),
+          reportFormat.getGroupingSymbol()), dfs);
+      parameters.put("AMOUNTFORMAT", numberFormat);
+    }
+
+    {
+      final FormatDefinition reportFormat = UIDefinitionController.getInstance()
+          .getFormatDefinition("generalQty", UIDefinitionController.SHORTFORMAT_QUALIFIER);
+
+      final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
+      dfs.setDecimalSeparator(reportFormat.getDecimalSymbol().charAt(0));
+      dfs.setGroupingSeparator(reportFormat.getGroupingSymbol().charAt(0));
+
+      final DecimalFormat numberFormat = new DecimalFormat(correctMaskForGrouping(
+          reportFormat.getFormat(), reportFormat.getDecimalSymbol(),
+          reportFormat.getGroupingSymbol()), dfs);
+      parameters.put("QUANTITYFORMAT", numberFormat);
+    }
+
+    String strClientId = OBContext.getOBContext().getCurrentClient().getId();
+    parameters.put("Current_Client_ID", strClientId);
+    String strOrgs = "";
+    boolean isNotFirst = false;
+    for (String strOrgId : OBContext.getOBContext().getReadableOrganizations()) {
+      if (isNotFirst) {
+        strOrgs += ",";
+      }
+      strOrgs += "'" + strOrgId + "'";
+      isNotFirst = true;
+    }
+    parameters.put("Readable_Organizations", strOrgs);
+  }
+
+  /**
+   * Adds the date format configuration into the parameter map.
+   * 
+   * @param parameters
+   *          Map of parameters where the date format configuration is put.
+   */
+  private static void setReportFormatFactory(Map<String, Object> parameters) {
+    String javaDateFormat = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+        .getProperty("dateFormat.java");
+    if (log.isDebugEnabled())
+      log.debug("creating the format factory: " + javaDateFormat);
+    final JRFormatFactory jrFormatFactory = new JRFormatFactory();
+    jrFormatFactory.setDatePattern(javaDateFormat);
+    parameters.put(JRParameter.REPORT_FORMAT_FACTORY, jrFormatFactory);
+  }
+
+  /**
+   * Creates a JasperPrint from a grid report.
+   * 
+   * @param reportFile
+   *          An input stream containing the report file.
+   * @param gridReportVO
+   *          A grid report.
+   * @return A JasperPrint object with the compiled report.
+   * @throws JRException
+   *           In case there is any error generating the file an exception is thrown with the error
+   *           message.
+   * @throws IOException
+   *           In case there is any error generating the JasperPrint an exception is thrown with the
+   *           error message.
+   */
+  public static JasperPrint createJasperPrint(InputStream reportFile, GridReportVO gridReportVO)
+      throws JRException, IOException {
+    JasperDesign jasperDesign = JRXmlLoader.load(reportFile);
+    if (log.isDebugEnabled())
+      log.debug("Create JasperDesign");
+    ReportDesignBO designBO = new ReportDesignBO(jasperDesign, gridReportVO);
+    designBO.define();
+    if (log.isDebugEnabled())
+      log.debug("JasperDesign created, pageWidth: " + jasperDesign.getPageWidth()
+          + " left margin: " + jasperDesign.getLeftMargin() + " right margin: "
+          + jasperDesign.getRightMargin());
+    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
+    Map<String, Object> parameters = new HashMap<String, Object>();
+    parameters.put("BaseDir", gridReportVO.getContext());
+    parameters.put("IS_IGNORE_PAGINATION", gridReportVO.getPagination());
+
+    JasperPrint jasperPrint = JasperFillManager
+        .fillReport(
+            jasperReport,
+            parameters,
+            new JRFieldProviderDataSource(gridReportVO.getFieldProvider(), gridReportVO
+                .getDateFormat()));
+    return jasperPrint;
+  }
+
+  /**
    * Changes the mask to use "." as Decimal Symbol and "," as grouping symbol.
    * 
    * @param mask
@@ -216,6 +918,18 @@
    */
   public enum ExportType {
     @SuppressWarnings("serial")
+    CSV("csv", "", new HashMap<String, Object>() {
+      {
+        put("IS_IGNORE_PAGINATION", true);
+      }
+    }), //
+    @SuppressWarnings("serial")
+    HTML("html", "", new HashMap<String, Object>() {
+      {
+        put("IS_IGNORE_PAGINATION", true);
+      }
+    }), //
+    @SuppressWarnings("serial")
     PDF("pdf", "103", new HashMap<String, Object>() {
       {
         put("IS_IGNORE_PAGINATION", false);
@@ -226,6 +940,12 @@
       {
         put("IS_IGNORE_PAGINATION", true);
       }
+    }), //
+    @SuppressWarnings("serial")
+    XML("xml", "800004", new HashMap<String, Object>() {
+      {
+        put("IS_IGNORE_PAGINATION", true);
+      }
     });
     private final String extension;
     private final String fileType;
@@ -239,7 +959,11 @@
         if (type != null) {
           fileType = type.getFormat();
         } else {
-          fileType = "application/" + extension;
+          if ("html".equals(extension) || "csv".equals(extension)) {
+            fileType = "text/" + extension;
+          } else {
+            fileType = "application/" + extension;
+          }
         }
       } finally {
         OBContext.restorePreviousMode();
@@ -266,10 +990,16 @@
      * Returns the corresponding ExportType item based on the action.
      */
     public static ExportType getExportType(String action) throws OBException {
-      if ("PDF".equals(action)) {
+      if ("CSV".equals(action)) {
+        return ExportType.CSV;
+      } else if ("HTML".equals(action)) {
+        return ExportType.HTML;
+      } else if ("PDF".equals(action)) {
         return ExportType.PDF;
       } else if ("XLS".equals(action)) {
         return ExportType.XLS;
+      } else if ("XML".equals(action)) {
+        return ExportType.XML;
       } else {
         throw new OBException(OBMessageUtils.messageBD("OBUIAPP_UnsupportedAction"));
       }
--- a/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java	Wed May 06 18:24:45 2015 +0200
@@ -16,8 +16,6 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintWriter;
-import java.sql.Connection;
-import java.sql.SQLException;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
 import java.util.HashMap;
@@ -37,20 +35,7 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import net.sf.jasperreports.engine.JRDataSource;
-import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JRExporterParameter;
-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.JasperReport;
-import net.sf.jasperreports.engine.export.JExcelApiExporter;
-import net.sf.jasperreports.engine.export.JExcelApiExporterParameter;
-import net.sf.jasperreports.engine.export.JRHtmlExporter;
 import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
-import net.sf.jasperreports.engine.fill.JRSwapFileVirtualizer;
-import net.sf.jasperreports.engine.util.JRSwapFile;
-import net.sf.jasperreports.j2ee.servlets.ImageServlet;
 
 import org.codehaus.jettison.json.JSONObject;
 import org.hibernate.criterion.Restrictions;
@@ -60,6 +45,8 @@
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.secureApp.LoginUtils.RoleDefaults;
 import org.openbravo.base.session.OBPropertiesProvider;
+import org.openbravo.client.application.report.ReportingUtils;
+import org.openbravo.client.application.report.ReportingUtils.ExportType;
 import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
@@ -73,7 +60,6 @@
 import org.openbravo.erpCommon.security.SessionLogin;
 import org.openbravo.erpCommon.security.UsageAudit;
 import org.openbravo.erpCommon.utility.JRFieldProviderDataSource;
-import org.openbravo.erpCommon.utility.JRFormatFactory;
 import org.openbravo.erpCommon.utility.JRScrollableFieldProviderDataSource;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
@@ -1262,19 +1248,10 @@
 
     ServletOutputStream os = null;
     UUID reportId = null;
-    JRSwapFileVirtualizer virtualizer = null;
     try {
-
-      final JasperReport jasperReport = Utility.getTranslatedJasperReport(this, strReportName,
-          strLanguage, strBaseDesign);
       if (designParameters == null)
         designParameters = new HashMap<String, Object>();
 
-      Boolean pagination = true;
-      if (strOutputType.equals("pdf"))
-        pagination = false;
-
-      designParameters.put("IS_IGNORE_PAGINATION", pagination);
       designParameters.put("BASE_WEB", strReplaceWithFull);
       designParameters.put("BASE_DESIGN", strBaseDesign);
       designParameters.put("ATTACH", strAttach);
@@ -1292,78 +1269,30 @@
           variables.getSessionValue("#AD_ReportNumberFormat"), dfs);
       designParameters.put("NUMBERFORMAT", numberFormat);
 
-      if (log4j.isDebugEnabled())
-        log4j.debug("creating the format factory: " + variables.getJavaDateFormat());
-      final JRFormatFactory jrFormatFactory = new JRFormatFactory();
-      jrFormatFactory.setDatePattern(variables.getJavaDateFormat());
-      designParameters.put(JRParameter.REPORT_FORMAT_FACTORY, jrFormatFactory);
-
-      // if no custom virtualizer is requested use a default one
-      if (!designParameters.containsKey(JRParameter.REPORT_VIRTUALIZER)) {
-        // virtualizer is essentially using a tmp-file to avoid huge memory consumption by jasper
-        // when processing big reports
-        JRSwapFile swap = new JRSwapFile(System.getProperty("java.io.tmpdir"), 4096, 1);
-        // start using the virtualizer when having more than 100 pages of data
-        virtualizer = new JRSwapFileVirtualizer(100, swap);
-        designParameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
-      }
-
-      JasperPrint jasperPrint;
-      Connection con = null;
-      try {
-        con = getTransactionConnection();
-        if (data != null) {
-          designParameters.put("REPORT_CONNECTION", con);
-          jasperPrint = JasperFillManager.fillReport(jasperReport, designParameters, data);
-        } else {
-          jasperPrint = JasperFillManager.fillReport(jasperReport, designParameters, con);
-        }
-      } catch (final Exception e) {
-        Throwable t = (e.getCause() != null) ? e.getCause().getCause() : null;
-        if (t != null) {
-          throw new ServletException((t instanceof SQLException && t.getMessage().contains(
-              "@NoConversionRate@")) ? t.getMessage() : e.getMessage(), e);
-        } else {
-          throw new ServletException(e.getCause() instanceof SQLException ? e.getCause()
-              .getMessage() : e.getMessage(), e);
-        }
-      } finally {
-        releaseRollbackConnection(con);
-      }
-
       os = response.getOutputStream();
       if (exportParameters == null)
         exportParameters = new HashMap<Object, Object>();
       if (strOutputType == null || strOutputType.equals(""))
         strOutputType = "html";
+      final ExportType expType = ExportType.getExportType(strOutputType.toUpperCase());
+
       if (strOutputType.equals("html")) {
         if (log4j.isDebugEnabled())
           log4j.debug("JR: Print HTML");
         response.setHeader("Content-disposition", "inline" + "; filename=" + strFileName + "."
             + strOutputType);
-        final JRHtmlExporter exporter = new JRHtmlExporter();
-        exportParameters.put(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
-        exportParameters.put(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
-        exportParameters.put(JRHtmlExporterParameter.SIZE_UNIT,
-            JRHtmlExporterParameter.SIZE_UNIT_POINT);
-        exportParameters.put(JRHtmlExporterParameter.OUTPUT_STREAM, os);
-
-        HttpSession session = (HttpSession) designParameters.get("HTTP_SESSION");
-        if (session != null) {
-          session.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
-        }
-
         HttpServletRequest request = RequestContext.get().getRequest();
         String localAddress = HttpBaseUtils.getLocalAddress(request);
         exportParameters.put(JRHtmlExporterParameter.IMAGES_URI, localAddress
             + "/servlets/image?image=");
-
-        exporter.setParameters(exportParameters);
-        exporter.exportReport();
+        ReportingUtils.exportJR(strReportName, expType, designParameters, os, false, this, data,
+            exportParameters);
       } else if (strOutputType.equals("pdf") || strOutputType.equalsIgnoreCase("xls")) {
         reportId = UUID.randomUUID();
-        saveReport(variables, jasperPrint, exportParameters, strFileName + "-" + (reportId) + "."
-            + strOutputType);
+        File outputFile = new File(globalParameters.strFTPDirectory + "/" + strFileName + "-"
+            + (reportId) + "." + strOutputType);
+        ReportingUtils.exportJR(strReportName, expType, designParameters, outputFile, false, this,
+            data, exportParameters);
         response.setContentType("text/html;charset=UTF-8");
         response.setHeader("Content-disposition", "inline" + "; filename=" + strFileName + "-"
             + (reportId) + ".html");
@@ -1374,12 +1303,8 @@
           printPagePopUpDownload(response.getOutputStream(), strFileName + "-" + (reportId) + "."
               + strOutputType);
         }
-      } else {
-        throw new ServletException("Output format no supported");
       }
-    } catch (final JRException e) {
-      log4j.error("JR: Error: ", e);
-      throw new ServletException(e.getMessage(), e);
+
     } catch (IOException ioe) {
       try {
         FileUtility f = new FileUtility(globalParameters.strFTPDirectory, strFileName + "-"
@@ -1397,10 +1322,6 @@
         os.close();
       } catch (final Exception e) {
       }
-      // remove virtualizer tmp files if we created them
-      if (virtualizer != null) {
-        virtualizer.cleanup();
-      }
     }
   }
 
@@ -1446,41 +1367,6 @@
   }
 
   /**
-   * Saves the report on the attachments folder for future retrieval
-   * 
-   * @param vars
-   *          An instance of VariablesSecureApp that contains the request parameters
-   * @param jp
-   *          An instance of JasperPrint of the loaded JRXML template
-   * @param exportParameters
-   *          A Map with all the parameters passed to all reports
-   * @param fileName
-   *          The file name for the report
-   * @throws JRException
-   */
-  private void saveReport(VariablesSecureApp vars, JasperPrint jp,
-      Map<Object, Object> exportParameters, String fileName) throws JRException {
-    final String outputFile = globalParameters.strFTPDirectory + "/" + fileName;
-    final String reportType = fileName.substring(fileName.lastIndexOf(".") + 1);
-    if (reportType.equalsIgnoreCase("pdf")) {
-      JasperExportManager.exportReportToPdfFile(jp, outputFile);
-    } else if (reportType.equalsIgnoreCase("xls")) {
-      JExcelApiExporter exporter = new JExcelApiExporter();
-      exportParameters.put(JRExporterParameter.JASPER_PRINT, jp);
-      exportParameters.put(JRExporterParameter.OUTPUT_FILE_NAME, outputFile);
-      exportParameters.put(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
-      exportParameters.put(JExcelApiExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
-          Boolean.TRUE);
-      exportParameters.put(JExcelApiExporterParameter.IS_DETECT_CELL_TYPE, true);
-      exporter.setParameters(exportParameters);
-      exporter.exportReport();
-    } else {
-      throw new JRException("Report type not supported");
-    }
-
-  }
-
-  /**
    * Forwards request to the referrer servlet to perform operations like "auto-save" Note: The
    * referrer servlet should have a hidden input field with mappingName (e.g.
    * /PurchaOrder/Header_Edition.html) to be able to get a RequestDispatcher
--- a/src/org/openbravo/erpCommon/ad_process/JasperProcess.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpCommon/ad_process/JasperProcess.java	Wed May 06 18:24:45 2015 +0200
@@ -1,6 +1,5 @@
 package org.openbravo.erpCommon.ad_process;
 
-import java.sql.Connection;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
 import java.util.HashMap;
@@ -9,25 +8,14 @@
 import javax.servlet.ServletException;
 import javax.servlet.ServletOutputStream;
 
-import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JRExporterParameter;
-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.JasperReport;
-import net.sf.jasperreports.engine.export.JExcelApiExporter;
-import net.sf.jasperreports.engine.export.JExcelApiExporterParameter;
-import net.sf.jasperreports.engine.export.JRHtmlExporter;
-import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
-
 import org.apache.log4j.Logger;
 import org.openbravo.base.ConfigParameters;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
+import org.openbravo.client.application.report.ReportingUtils.ExportType;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.JRFieldProviderDataSource;
-import org.openbravo.erpCommon.utility.JRFormatFactory;
 import org.openbravo.erpCommon.utility.PrintJRData;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.scheduling.Process;
@@ -84,17 +72,9 @@
     // FIXME: os is never assigned, but used leading to an NPE
     ServletOutputStream os = null;
     try {
-      JasperReport jasperReport = Utility.getTranslatedJasperReport(connection, strReportName,
-          strLanguage, strBaseDesign);
-
       if (designParameters == null)
         designParameters = new HashMap<String, Object>();
 
-      Boolean pagination = true;
-      if (strOutputType.equals("pdf"))
-        pagination = false;
-
-      designParameters.put("IS_IGNORE_PAGINATION", pagination);
       // designParameters.put("BASE_WEB", strReplaceWithFull);
       designParameters.put("BASE_DESIGN", strBaseDesign);
       designParameters.put("ATTACH", strAttach);
@@ -110,79 +90,15 @@
           vars.getSessionValue("#AD_ReportNumberFormat"), dfs);
       designParameters.put("NUMBERFORMAT", numberFormat);
 
-      if (log4j.isDebugEnabled())
-        log4j.debug("creating the format factory: " + vars.getJavaDateFormat());
-      JRFormatFactory jrFormatFactory = new JRFormatFactory();
-      jrFormatFactory.setDatePattern(vars.getJavaDateFormat());
-      designParameters.put(JRParameter.REPORT_FORMAT_FACTORY, jrFormatFactory);
-
-      JasperPrint jasperPrint;
-      Connection conn = null;
-      try {
-        conn = connection.getTransactionConnection();
-        if (data != null) {
-          designParameters.put("REPORT_CONNECTION", conn);
-          jasperPrint = JasperFillManager.fillReport(jasperReport, designParameters,
-              new JRFieldProviderDataSource(data, vars.getJavaDateFormat()));
-        } else {
-          jasperPrint = JasperFillManager.fillReport(jasperReport, designParameters, conn);
-        }
-      } catch (Exception e) {
-        throw new ServletException(e.getMessage());
-      } finally {
-        connection.releaseRollbackConnection(conn);
-      }
-
       if (exportParameters == null)
         exportParameters = new HashMap<Object, Object>();
       if (strOutputType == null || strOutputType.equals(""))
         strOutputType = "html";
-      if (strOutputType.equals("html")) {
-        if (log4j.isDebugEnabled())
-          log4j.debug("JR: Print HTML");
-        // response.setHeader( "Content-disposition", "inline" +
-        // "; filename=" + strFileName + "." +strOutputType);
-        JRHtmlExporter exporter = new JRHtmlExporter();
-        exportParameters.put(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
-        exportParameters.put(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
-        exportParameters.put(JRHtmlExporterParameter.SIZE_UNIT,
-            JRHtmlExporterParameter.SIZE_UNIT_POINT);
-        exportParameters.put(JRHtmlExporterParameter.OUTPUT_STREAM, os);
-        exporter.setParameters(exportParameters);
-        exporter.exportReport();
-
-      } else if (strOutputType.equals("pdf")) {
-        // response.setContentType("application/pdf");
-        // response.setHeader( "Content-disposition", "attachment" +
-        // "; filename=" + strFileName + "." +strOutputType);
-        JasperExportManager.exportReportToPdfStream(jasperPrint, os);
-
-      } else if (strOutputType.equals("xls")) {
-        // response.setContentType("application/vnd.ms-excel");
-        // response.setHeader( "Content-disposition", "attachment" +
-        // "; filename=" + strFileName + "." +strOutputType);
-        JExcelApiExporter exporter = new JExcelApiExporter();
-        exportParameters.put(JRExporterParameter.JASPER_PRINT, jasperPrint);
-        exportParameters.put(JRExporterParameter.OUTPUT_STREAM, os);
-        exportParameters.put(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
-        exportParameters.put(JExcelApiExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
-            Boolean.TRUE);
-
-        exporter.setParameters(exportParameters);
-        exporter.exportReport();
-
-      } else {
-        throw new ServletException("Output format no supported");
-      }
-    } catch (JRException e) {
-      if (log4j.isDebugEnabled())
-        log4j.debug("JR: Error: " + e);
-      e.printStackTrace();
-      throw new ServletException(e.getMessage());
-
+      final ExportType expType = ExportType.getExportType(strOutputType.toUpperCase());
+      ReportingUtils.exportJR(strReportName, expType, designParameters, os, false, connection,
+          new JRFieldProviderDataSource(data, vars.getJavaDateFormat()), exportParameters);
     } catch (Exception e) {
       throw new ServletException(e.getMessage());
-
     } finally {
       try {
         os.close();
--- a/src/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast.java	Wed May 06 18:24:45 2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2015 Openbravo SLU 
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -29,13 +29,11 @@
 import javax.servlet.http.HttpServletResponse;
 
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperReport;
-import net.sf.jasperreports.engine.design.JasperDesign;
-import net.sf.jasperreports.engine.xml.JRXmlLoader;
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
 import org.openbravo.erpCommon.businessUtility.WindowTabs;
 import org.openbravo.erpCommon.utility.LeftTabsBar;
 import org.openbravo.erpCommon.utility.NavigationBar;
@@ -104,9 +102,8 @@
       String strBaseDesign = getBaseDesignPath(strLanguage);
       JasperReport jasperReportLines;
       try {
-        JasperDesign jasperDesignLines = (JRXmlLoader.load(strBaseDesign
-            + "/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast_sub.jrxml"));
-        jasperReportLines = JasperCompileManager.compileReport(jasperDesignLines);
+        jasperReportLines = ReportingUtils.compileReport(strBaseDesign
+            + "/org/openbravo/erpCommon/ad_reports/ReportCashflowForecast_sub.jrxml");
       } catch (JRException e) {
         log4j.error("Error Compiling report ", e);
         throw new ServletException(e.getMessage());
--- a/src/org/openbravo/erpCommon/ad_reports/ReportProductionJR.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportProductionJR.java	Wed May 06 18:24:45 2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2015 Openbravo SLU 
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -28,13 +28,11 @@
 import javax.servlet.http.HttpServletResponse;
 
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperReport;
-import net.sf.jasperreports.engine.design.JasperDesign;
-import net.sf.jasperreports.engine.xml.JRXmlLoader;
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
 import org.openbravo.erpCommon.businessUtility.WindowTabs;
 import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.erpCommon.utility.LeftTabsBar;
@@ -166,9 +164,8 @@
 
     JasperReport jasperReportLines;
     try {
-      JasperDesign jasperDesignLines = JRXmlLoader.load(strBaseDesign
+      jasperReportLines = ReportingUtils.compileReport(strBaseDesign
           + "/org/openbravo/erpCommon/ad_reports/productionSubReport.jrxml");
-      jasperReportLines = JasperCompileManager.compileReport(jasperDesignLines);
     } catch (JRException e) {
       e.printStackTrace();
       throw new ServletException(e.getMessage());
--- a/src/org/openbravo/erpCommon/ad_reports/ReportStandardCostJR.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpCommon/ad_reports/ReportStandardCostJR.java	Wed May 06 18:24:45 2015 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2001-2010 Openbravo SLU
+ * All portions are Copyright (C) 2001-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -29,13 +29,11 @@
 import javax.servlet.http.HttpServletResponse;
 
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperReport;
-import net.sf.jasperreports.engine.design.JasperDesign;
-import net.sf.jasperreports.engine.xml.JRXmlLoader;
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
 import org.openbravo.erpCommon.businessUtility.WindowTabs;
 import org.openbravo.erpCommon.utility.ComboTableData;
 import org.openbravo.erpCommon.utility.LeftTabsBar;
@@ -178,12 +176,10 @@
     JasperReport jasperReportCost;
     JasperReport jasperReportProduced;
     try {
-      JasperDesign jasperDesignCost = JRXmlLoader.load(strBaseDesign
+      jasperReportCost = ReportingUtils.compileReport(strBaseDesign
           + "/org/openbravo/erpCommon/ad_reports/ReportStandardCostsJR_srptcosts.jrxml");
-      JasperDesign jasperDesignProduced = JRXmlLoader.load(strBaseDesign
+      jasperReportProduced = ReportingUtils.compileReport(strBaseDesign
           + "/org/openbravo/erpCommon/ad_reports/ReportStandardCostsJR_subreport0.jrxml");
-      jasperReportCost = JasperCompileManager.compileReport(jasperDesignCost);
-      jasperReportProduced = JasperCompileManager.compileReport(jasperDesignProduced);
     } catch (JRException e) {
       e.printStackTrace();
       throw new ServletException(e.getMessage());
--- a/src/org/openbravo/erpCommon/utility/GridBO.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpCommon/utility/GridBO.java	Wed May 06 18:24:45 2015 +0200
@@ -11,127 +11,57 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2007-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2007-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.erpCommon.utility;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.Map;
 
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JRExporterParameter;
-import net.sf.jasperreports.engine.JasperCompileManager;
-import net.sf.jasperreports.engine.JasperExportManager;
-import net.sf.jasperreports.engine.JasperFillManager;
 import net.sf.jasperreports.engine.JasperPrint;
-import net.sf.jasperreports.engine.JasperReport;
-import net.sf.jasperreports.engine.design.JasperDesign;
-import net.sf.jasperreports.engine.export.JExcelApiExporter;
-import net.sf.jasperreports.engine.export.JExcelApiExporterParameter;
-import net.sf.jasperreports.engine.export.JRCsvExporter;
-import net.sf.jasperreports.engine.export.JRHtmlExporter;
-import net.sf.jasperreports.engine.export.JRHtmlExporterParameter;
-import net.sf.jasperreports.engine.xml.JRXmlLoader;
 
-import org.apache.log4j.Logger;
+import org.openbravo.client.application.report.ReportingUtils;
+import org.openbravo.client.application.report.ReportingUtils.ExportType;
 
 class GridBO {
-  private static Logger log4j = Logger.getLogger("org.openbravo.erpCommon.utility.GridBO");
-
   public static void createHTMLReport(InputStream reportFile, GridReportVO gridReportVO,
       String path, String fileName) throws JRException, IOException {
     gridReportVO.setPagination(false);
-    JasperPrint jasperPrint = createJasperPrint(reportFile, gridReportVO);
-    JRHtmlExporter exporter = new JRHtmlExporter();
-    Map<JRExporterParameter, Object> p = new HashMap<JRExporterParameter, Object>();
-    p.put(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
-    p.put(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
-    p.put(JRHtmlExporterParameter.OUTPUT_FILE_NAME, path + "/" + fileName);
-    exporter.setParameters(p);
-    exporter.exportReport();
-
-  }
-
-  private static JasperDesign createJasperDesign(InputStream reportFile, GridReportVO gridReportVO)
-      throws JRException {
-    JasperDesign jasperDesign = JRXmlLoader.load(reportFile);
-    if (log4j.isDebugEnabled())
-      log4j.debug("Create JasperDesign");
-    ReportDesignBO designBO = new ReportDesignBO(jasperDesign, gridReportVO);
-    designBO.define();
-    if (log4j.isDebugEnabled())
-      log4j.debug("JasperDesign created, pageWidth: " + jasperDesign.getPageWidth()
-          + " left margin: " + jasperDesign.getLeftMargin() + " right margin: "
-          + jasperDesign.getRightMargin());
-    return jasperDesign;
-  }
-
-  private static JasperPrint createJasperPrint(InputStream reportFile, GridReportVO gridReportVO)
-      throws JRException, IOException {
-    JasperDesign jasperDesign = createJasperDesign(reportFile, gridReportVO);
-    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
-    Map<String, Object> parameters = new HashMap<String, Object>();
-    parameters.put("BaseDir", gridReportVO.getContext());
-    parameters.put("IS_IGNORE_PAGINATION", gridReportVO.getPagination());
-
-    JasperPrint jasperPrint = JasperFillManager
-        .fillReport(
-            jasperReport,
-            parameters,
-            new JRFieldProviderDataSource(gridReportVO.getFieldProvider(), gridReportVO
-                .getDateFormat()));
-    return jasperPrint;
+    JasperPrint jasperPrint = ReportingUtils.createJasperPrint(reportFile, gridReportVO);
+    ReportingUtils.saveReport(jasperPrint, ExportType.HTML, null, new File(path + "/" + fileName));
   }
 
   public static void createPDFReport(InputStream reportFile, GridReportVO gridReportVO,
       String path, String fileName) throws JRException, IOException {
     gridReportVO.setPagination(false);
-    JasperPrint jasperPrint = createJasperPrint(reportFile, gridReportVO);
-    JasperExportManager.exportReportToPdfFile(jasperPrint, path + "/" + fileName);
+    JasperPrint jasperPrint = ReportingUtils.createJasperPrint(reportFile, gridReportVO);
+    ReportingUtils.saveReport(jasperPrint, ExportType.PDF, null, new File(path + "/" + fileName));
   }
 
   public static void createXLSReport(InputStream reportFile, GridReportVO gridReportVO,
       String path, String fileName) throws JRException, IOException {
     gridReportVO.setPagination(true);
-    JasperPrint jasperPrint = createJasperPrint(reportFile, gridReportVO);
-    JExcelApiExporter exporter = new JExcelApiExporter();
-    Map<JRExporterParameter, Object> p = new HashMap<JRExporterParameter, Object>();
-
-    p.put(JRExporterParameter.JASPER_PRINT, jasperPrint);
-    p.put(JRExporterParameter.OUTPUT_FILE_NAME, path + "/" + fileName);
-    p.put(JExcelApiExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
-    p.put(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
-    p.put(JExcelApiExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
-
-    exporter.setParameters(p);
-    exporter.exportReport();
+    JasperPrint jasperPrint = ReportingUtils.createJasperPrint(reportFile, gridReportVO);
+    ReportingUtils.saveReport(jasperPrint, ExportType.XLS, null, new File(path + "/" + fileName));
   }
 
   public static void createCSVReport(InputStream reportFile, GridReportVO gridReportVO,
       String path, String fileName) throws JRException, IOException {
     gridReportVO.setPagination(true);
-    JasperPrint jasperPrint = createJasperPrint(reportFile, gridReportVO);
-    JRCsvExporter exporter = new JRCsvExporter();
-    Map<JRExporterParameter, Object> p = new HashMap<JRExporterParameter, Object>();
-
-    p.put(JRExporterParameter.JASPER_PRINT, jasperPrint);
-    p.put(JRExporterParameter.OUTPUT_FILE_NAME, path + "/" + fileName);
-
-    exporter.setParameters(p);
-    exporter.exportReport();
+    JasperPrint jasperPrint = ReportingUtils.createJasperPrint(reportFile, gridReportVO);
+    ReportingUtils.saveReport(jasperPrint, ExportType.CSV, null, new File(path + "/" + fileName));
   }
 
   public static void createXMLReport(InputStream reportFile, GridReportVO gridReportVO,
       OutputStream os) throws JRException, IOException {
     gridReportVO.setPagination(true);
-    JasperPrint jasperPrint = createJasperPrint(reportFile, gridReportVO);
-    JasperExportManager.exportReportToXmlStream(jasperPrint, os);
+    JasperPrint jasperPrint = ReportingUtils.createJasperPrint(reportFile, gridReportVO);
+    ReportingUtils.saveReport(jasperPrint, ExportType.XML, null, os);
   }
-
 }
--- a/src/org/openbravo/erpCommon/utility/GridReportVO.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpCommon/utility/GridReportVO.java	Wed May 06 18:24:45 2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2007-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2007-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -23,7 +23,7 @@
 
 import org.openbravo.data.FieldProvider;
 
-class GridReportVO {
+public class GridReportVO {
   private String jrxmlTemplate;
   private String sql;
   private String title;
--- a/src/org/openbravo/erpCommon/utility/PrintJR.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpCommon/utility/PrintJR.java	Wed May 06 18:24:45 2015 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2007-2010 Openbravo SLU
+ * All portions are Copyright (C) 2007-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -28,13 +28,11 @@
 
 import net.sf.jasperreports.engine.JRException;
 import net.sf.jasperreports.engine.JRParameter;
-import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperReport;
-import net.sf.jasperreports.engine.design.JasperDesign;
-import net.sf.jasperreports.engine.xml.JRXmlLoader;
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
 import org.openbravo.data.Sqlc;
 import org.openbravo.reference.Reference;
 import org.openbravo.reference.ui.UIReference;
@@ -80,8 +78,7 @@
           Replace.replace(strReportName, "@basedesign@", strBaseDesign), "@attach@", strAttach);
 
       try {
-        JasperDesign jasperDesign = JRXmlLoader.load(strReportName);
-        jasperReport = JasperCompileManager.compileReport(jasperDesign);
+        jasperReport = ReportingUtils.compileReport(strReportName);
       } catch (JRException e) {
         if (log4j.isDebugEnabled())
           log4j.debug("JR: Error: " + e);
--- a/src/org/openbravo/erpCommon/utility/ReportDesignBO.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpCommon/utility/ReportDesignBO.java	Wed May 06 18:24:45 2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2007-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2007-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -33,7 +33,7 @@
 
 import org.apache.log4j.Logger;
 
-class ReportDesignBO {
+public class ReportDesignBO {
   public static Logger log4j = Logger.getLogger("org.openbravo.erpCommon.utility.GridBO");
   private int px = 0;
 
--- a/src/org/openbravo/erpCommon/utility/reporting/ReportManager.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpCommon/utility/reporting/ReportManager.java	Wed May 06 18:24:45 2015 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Business Momentum b.v.
- * All portions are Copyright (C) 2007-2013 Openbravo SLU 
+ * All portions are Copyright (C) 2007-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  Business Momentum b.v. (http://www.businessmomentum.eu).
  *************************************************************************
@@ -21,30 +21,21 @@
 import java.io.File;
 import java.io.IOException;
 import java.sql.Connection;
-import java.sql.SQLException;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Locale;
 
 import net.sf.jasperreports.engine.JRException;
-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.JasperReport;
-import net.sf.jasperreports.engine.design.JRDesignParameter;
-import net.sf.jasperreports.engine.design.JasperDesign;
-import net.sf.jasperreports.engine.xml.JRXmlLoader;
 
 import org.apache.log4j.Logger;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
+import org.openbravo.client.application.report.ReportingUtils.ExportType;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.businessUtility.TabAttachments;
 import org.openbravo.erpCommon.businessUtility.TabAttachmentsData;
-import org.openbravo.erpCommon.utility.JRFormatFactory;
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.utils.Replace;
@@ -87,7 +78,6 @@
     setTargetDirectory(report);
     language = variables.getLanguage();
     final String baseDesignPath = _prefix + "/" + _strBaseDesignPath + "/" + _strDefaultDesignPath;
-    final Locale locale = new Locale(language.substring(0, 2), language.substring(3, 5));
 
     String templateLocation = report.getTemplateInfo().getTemplateLocation();
     templateLocation = Replace.replace(
@@ -100,56 +90,21 @@
     designParameters.put("TEMPLATE_LOCATION", templateLocation);
     JasperPrint jasperPrint = null;
 
+    String salesOrder = report.getCheckSalesOrder();
+    if (salesOrder != null && salesOrder.equals("Y")) {
+      designParameters.put(
+          "DOCUMENT_NAME",
+          Utility.messageBD(_connectionProvider, "Sales", language) + " "
+              + Utility.messageBD(_connectionProvider, "Invoice", language));
+    } else {
+      designParameters.put(
+          "DOCUMENT_NAME",
+          Utility.messageBD(_connectionProvider, "Purchase", language) + " "
+              + Utility.messageBD(_connectionProvider, "Invoice", language));
+    }
     try {
-      JasperDesign jasperDesign = JRXmlLoader.load(templateFile);
-
-      Object[] parameters = jasperDesign.getParametersList().toArray();
-      String parameterName = "";
-      String subReportName = "";
-      Collection<String> subreportList = new ArrayList<String>();
-
-      /*
-       * TODO: At present this process assumes the subreport is a .jrxml file. Need to handle the
-       * possibility that this subreport file could be a .jasper file.
-       */
-      for (int i = 0; i < parameters.length; i++) {
-        final JRDesignParameter parameter = (JRDesignParameter) parameters[i];
-        if (parameter.getName().startsWith("SUBREP_")) {
-          parameterName = parameter.getName();
-          subreportList.add(parameterName);
-          subReportName = Replace.replace(parameterName, "SUBREP_", "") + ".jrxml";
-          JasperReport jasperReportLines = createSubReport(templateLocation, subReportName,
-              baseDesignPath);
-          designParameters.put(parameterName, jasperReportLines);
-        }
-      }
-
-      JasperReport jasperReport = Utility.getTranslatedJasperReport(_connectionProvider,
-          templateFile, language, baseDesignPath);
-
-      if (log4j.isDebugEnabled())
-        log4j.debug("creating the format factory: " + variables.getJavaDateFormat());
-      JRFormatFactory jrFormatFactory = new JRFormatFactory();
-      jrFormatFactory.setDatePattern(variables.getJavaDateFormat());
-      designParameters.put(JRParameter.REPORT_FORMAT_FACTORY, jrFormatFactory);
-      String salesOrder = report.getCheckSalesOrder();
-      if (salesOrder != null && salesOrder.equals("Y")) {
-        designParameters.put(
-            "DOCUMENT_NAME",
-            Utility.messageBD(_connectionProvider, "Sales", language) + " "
-                + Utility.messageBD(_connectionProvider, "Invoice", language));
-      } else {
-        designParameters.put(
-            "DOCUMENT_NAME",
-            Utility.messageBD(_connectionProvider, "Purchase", language) + " "
-                + Utility.messageBD(_connectionProvider, "Invoice", language));
-      }
-      jasperPrint = fillReport(designParameters, jasperReport);
-
-    } catch (final JRException exception) {
-      log4j.error(exception.getMessage());
-      exception.printStackTrace();
-      throw new ReportingException(exception);
+      jasperPrint = ReportingUtils.generateJasperPrint(templateFile, designParameters, true,
+          _connectionProvider, null);
     } catch (final Exception exception) {
       log4j.error(exception.getMessage());
       exception.getStackTrace();
@@ -192,43 +147,12 @@
     }
     final String target = report.getTargetDirectory() + separator + report.getFilename();
     try {
-      JasperExportManager.exportReportToPdfFile(jasperPrint, target);
+      ReportingUtils.saveReport(jasperPrint, ExportType.PDF, null, new File(target));
     } catch (final JRException e) {
       e.printStackTrace();
     }
   }
 
-  private JasperPrint fillReport(HashMap<String, Object> designParameters, JasperReport jasperReport)
-      throws ReportingException, SQLException {
-    JasperPrint jasperPrint = null;
-
-    Connection con = null;
-    try {
-      con = _connectionProvider.getTransactionConnection();
-      jasperPrint = JasperFillManager.fillReport(jasperReport, designParameters, con);
-    } catch (final Exception e) {
-      log4j.error(e.getMessage());
-      e.printStackTrace();
-      throw new ReportingException(e.getMessage());
-    } finally {
-      _connectionProvider.releaseRollbackConnection(con);
-    }
-    return jasperPrint;
-  }
-
-  private JasperReport createSubReport(String templateLocation, String subReportFileName,
-      String baseDesignPath) {
-    JasperReport jasperReportLines = null;
-    try {
-      jasperReportLines = Utility.getTranslatedJasperReport(_connectionProvider, templateLocation
-          + subReportFileName, language, baseDesignPath);
-    } catch (final JRException e1) {
-      log4j.error(e1.getMessage());
-      e1.printStackTrace();
-    }
-    return jasperReportLines;
-  }
-
   public File createAttachmentForReport(ConnectionProvider connectionProvider, Report report,
       String tableId, VariablesSecureApp vars) throws ReportingException, IOException {
     String path = null;
--- a/src/org/openbravo/erpCommon/utility/reporting/printing/PrintController.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpCommon/utility/reporting/printing/PrintController.java	Wed May 06 18:24:45 2015 +0200
@@ -8,7 +8,7 @@
  * either express or implied. See the License for the specific language
  * governing rights and limitations under the License. The Original Code is
  * Openbravo ERP. The Initial Developer of the Original Code is Openbravo SLU All
- * portions are Copyright (C) 2008-2014 Openbravo SLU All Rights Reserved.
+ * portions are Copyright (C) 2008-2015 Openbravo SLU All Rights Reserved.
  * Contributor(s): ______________________________________.
  */
 package org.openbravo.erpCommon.utility.reporting.printing;
@@ -28,8 +28,8 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Vector;
-import java.util.Map.Entry;
 import java.util.regex.Matcher;
 
 import javax.servlet.ServletConfig;
@@ -39,7 +39,6 @@
 import javax.servlet.http.HttpServletResponse;
 
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JasperExportManager;
 import net.sf.jasperreports.engine.JasperPrint;
 
 import org.apache.commons.fileupload.FileItem;
@@ -49,6 +48,8 @@
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.base.session.OBPropertiesProvider;
+import org.openbravo.client.application.report.ReportingUtils;
+import org.openbravo.client.application.report.ReportingUtils.ExportType;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
@@ -61,11 +62,11 @@
 import org.openbravo.erpCommon.utility.poc.EmailType;
 import org.openbravo.erpCommon.utility.reporting.DocumentType;
 import org.openbravo.erpCommon.utility.reporting.Report;
+import org.openbravo.erpCommon.utility.reporting.Report.OutputTypeEnum;
 import org.openbravo.erpCommon.utility.reporting.ReportManager;
 import org.openbravo.erpCommon.utility.reporting.ReportingException;
 import org.openbravo.erpCommon.utility.reporting.TemplateData;
 import org.openbravo.erpCommon.utility.reporting.TemplateInfo;
-import org.openbravo.erpCommon.utility.reporting.Report.OutputTypeEnum;
 import org.openbravo.erpCommon.utility.reporting.TemplateInfo.EmailDefinition;
 import org.openbravo.exception.NoConnectionAvailableException;
 import org.openbravo.model.ad.system.Language;
@@ -361,9 +362,8 @@
             }
 
             if (report == null)
-              throw new ServletException(Utility
-                  .messageBD(this, "NoDataReport", vars.getLanguage())
-                  + documentId);
+              throw new ServletException(
+                  Utility.messageBD(this, "NoDataReport", vars.getLanguage()) + documentId);
             // Check if the document is not in status 'draft'
             if (!report.isDraft()) {
               // Check if the report is already attached
@@ -390,8 +390,9 @@
                   log4j.debug("Document is not attached.");
               }
               final String senderAddress = vars.getStringParameter("fromEmail");
-              sendDocumentEmail(report, vars, (Vector<Object>) request.getSession().getAttribute(
-                  "files"), documentData, senderAddress, checks, documentType);
+              sendDocumentEmail(report, vars,
+                  (Vector<Object>) request.getSession().getAttribute("files"), documentData,
+                  senderAddress, checks, documentType);
               nrOfEmailsSend++;
             }
           }
@@ -464,8 +465,8 @@
       // Catching the exception here instead of throwing it to HSAS because this is used in multi
       // part request making the mechanism to detect popup not to work.
       log4j.error("Error captured: ", e);
-      bdErrorGeneralPopUp(request, response, "Error", Utility.translateError(this, vars,
-          vars.getLanguage(), e.getMessage()).getMessage());
+      bdErrorGeneralPopUp(request, response, "Error",
+          Utility.translateError(this, vars, vars.getLanguage(), e.getMessage()).getMessage());
     }
   }
 
@@ -485,7 +486,7 @@
         response.setHeader("Content-disposition", "attachment" + "; filename=" + filename);
         for (Iterator<JasperPrint> iterator = jrPrintReports.iterator(); iterator.hasNext();) {
           JasperPrint jasperPrint = (JasperPrint) iterator.next();
-          JasperExportManager.exportReportToPdfStream(jasperPrint, os);
+          ReportingUtils.saveReport(jasperPrint, ExportType.PDF, null, os);
         }
       } else {
         response.setContentType("application/pdf");
@@ -750,14 +751,14 @@
     emailSubject = emailSubject.replaceAll("@sal_nam@", Matcher.quoteReplacement(replyToName));
     emailSubject = emailSubject
         .replaceAll("@bp_nam@", Matcher.quoteReplacement(report.getBPName()));
-    emailSubject = emailSubject.replaceAll("@doc_date@", Matcher.quoteReplacement(report
-        .getDocDate()));
-    emailSubject = emailSubject.replaceAll("@doc_nextduedate@", Matcher.quoteReplacement(report
-        .getMinDueDate()));
-    emailSubject = emailSubject.replaceAll("@doc_lastduedate@", Matcher.quoteReplacement(report
-        .getMaxDueDate()));
-    emailSubject = emailSubject.replaceAll("@doc_desc@", Matcher.quoteReplacement(report
-        .getDocDescription()));
+    emailSubject = emailSubject.replaceAll("@doc_date@",
+        Matcher.quoteReplacement(report.getDocDate()));
+    emailSubject = emailSubject.replaceAll("@doc_nextduedate@",
+        Matcher.quoteReplacement(report.getMinDueDate()));
+    emailSubject = emailSubject.replaceAll("@doc_lastduedate@",
+        Matcher.quoteReplacement(report.getMaxDueDate()));
+    emailSubject = emailSubject.replaceAll("@doc_desc@",
+        Matcher.quoteReplacement(report.getDocDescription()));
 
     emailBody = emailBody.replaceAll("@cus_ref@", Matcher.quoteReplacement(cusReference));
     emailBody = emailBody.replaceAll("@our_ref@", Matcher.quoteReplacement(ourReference));
@@ -765,12 +766,12 @@
     emailBody = emailBody.replaceAll("@sal_nam@", Matcher.quoteReplacement(replyToName));
     emailBody = emailBody.replaceAll("@bp_nam@", Matcher.quoteReplacement(report.getBPName()));
     emailBody = emailBody.replaceAll("@doc_date@", Matcher.quoteReplacement(report.getDocDate()));
-    emailBody = emailBody.replaceAll("@doc_nextduedate@", Matcher.quoteReplacement(report
-        .getMinDueDate()));
-    emailBody = emailBody.replaceAll("@doc_lastduedate@", Matcher.quoteReplacement(report
-        .getMaxDueDate()));
-    emailBody = emailBody.replaceAll("@doc_desc@", Matcher.quoteReplacement(report
-        .getDocDescription()));
+    emailBody = emailBody.replaceAll("@doc_nextduedate@",
+        Matcher.quoteReplacement(report.getMinDueDate()));
+    emailBody = emailBody.replaceAll("@doc_lastduedate@",
+        Matcher.quoteReplacement(report.getMaxDueDate()));
+    emailBody = emailBody.replaceAll("@doc_desc@",
+        Matcher.quoteReplacement(report.getDocDescription()));
 
     String host = null;
     boolean auth = true;
@@ -845,11 +846,12 @@
       if (log4j.isDebugEnabled())
         log4j.debug("New email id: " + newEmailId);
 
-      EmailData.insertEmail(conn, this, newEmailId, vars.getClient(), report.getOrgId(), vars
-          .getUser(), EmailType.OUTGOING.getStringValue(), replyTo, recipientTO, recipientCC,
+      EmailData.insertEmail(conn, this, newEmailId, vars.getClient(), report.getOrgId(),
+          vars.getUser(), EmailType.OUTGOING.getStringValue(), replyTo, recipientTO, recipientCC,
           recipientBCC, Utility.formatDate(new Date(), "yyyyMMddHHmmss"), emailSubject, emailBody,
-          report.getBPartnerId(), ToolsData.getTableId(this, report.getDocumentType()
-              .getTableName()), documentData.documentId);
+          report.getBPartnerId(),
+          ToolsData.getTableId(this, report.getDocumentType().getTableName()),
+          documentData.documentId);
 
       releaseCommitConnection(conn);
     } catch (final NoConnectionAvailableException exception) {
--- a/src/org/openbravo/erpReports/RptC_Invoice.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpReports/RptC_Invoice.java	Wed May 06 18:24:45 2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -27,13 +27,11 @@
 import javax.servlet.http.HttpServletResponse;
 
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperReport;
-import net.sf.jasperreports.engine.design.JasperDesign;
-import net.sf.jasperreports.engine.xml.JRXmlLoader;
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
 import org.openbravo.erpCommon.utility.DateTimeData;
 
 public class RptC_Invoice extends HttpSecureAppServlet {
@@ -97,9 +95,8 @@
 
     JasperReport jasperReportLines;
     try {
-      JasperDesign jasperDesignLines = JRXmlLoader.load(strBaseDesign
+      jasperReportLines = ReportingUtils.compileReport(strBaseDesign
           + "/org/openbravo/erpReports/RptC_Invoice_Lines.jrxml");
-      jasperReportLines = JasperCompileManager.compileReport(jasperDesignLines);
     } catch (JRException e) {
       e.printStackTrace();
       throw new ServletException(e.getMessage());
@@ -107,9 +104,8 @@
     parameters.put("SR_LINES_1", jasperReportLines);
 
     try {
-      JasperDesign jasperDesignLines = JRXmlLoader.load(strBaseDesign
+      jasperReportLines = ReportingUtils.compileReport(strBaseDesign
           + "/org/openbravo/erpReports/RptC_Invoice_TaxLines.jrxml");
-      jasperReportLines = JasperCompileManager.compileReport(jasperDesignLines);
     } catch (JRException e) {
       e.printStackTrace();
       throw new ServletException(e.getMessage());
--- a/src/org/openbravo/erpReports/RptC_Order.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpReports/RptC_Order.java	Wed May 06 18:24:45 2015 +0200
@@ -9,7 +9,7 @@
  * either express or implied. See the License for the specific language
  * governing rights and limitations under the License. The Original Code is
  * Openbravo ERP. The Initial Developer of the Original Code is Openbravo SLU All
- * portions are Copyright (C) 2001-2010 Openbravo SLU All Rights Reserved.
+ * portions are Copyright (C) 2001-2015 Openbravo SLU All Rights Reserved.
  * Contributor(s): ______________________________________.
  */
 package org.openbravo.erpReports;
@@ -23,13 +23,11 @@
 import javax.servlet.http.HttpServletResponse;
 
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperReport;
-import net.sf.jasperreports.engine.design.JasperDesign;
-import net.sf.jasperreports.engine.xml.JRXmlLoader;
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
 
 public class RptC_Order extends HttpSecureAppServlet {
   private static final long serialVersionUID = 1L;
@@ -71,9 +69,8 @@
 
     JasperReport jasperReportLines;
     try {
-      JasperDesign jasperDesignLines = JRXmlLoader.load(strBaseDesign
+      jasperReportLines = ReportingUtils.compileReport(strBaseDesign
           + "/org/openbravo/erpReports/C_OrderLinesJR.jrxml");
-      jasperReportLines = JasperCompileManager.compileReport(jasperDesignLines);
     } catch (JRException e) {
       e.printStackTrace();
       throw new ServletException(e.getMessage());
--- a/src/org/openbravo/erpReports/RptC_OrderPO.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpReports/RptC_OrderPO.java	Wed May 06 18:24:45 2015 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2001-2010 Openbravo SLU
+ * All portions are Copyright (C) 2001-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -27,13 +27,11 @@
 import javax.servlet.http.HttpServletResponse;
 
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperReport;
-import net.sf.jasperreports.engine.design.JasperDesign;
-import net.sf.jasperreports.engine.xml.JRXmlLoader;
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
 
 public class RptC_OrderPO extends HttpSecureAppServlet {
   private static final long serialVersionUID = 1L;
@@ -68,9 +66,8 @@
     HashMap<String, Object> parameters = new HashMap<String, Object>();
     JasperReport jasperReportLines;
     try {
-      JasperDesign jasperDesignLines = JRXmlLoader.load(strBaseDesign
+      jasperReportLines = ReportingUtils.compileReport(strBaseDesign
           + "/org/openbravo/erpReports/RptC_OrderPO_Lines.jrxml");
-      jasperReportLines = JasperCompileManager.compileReport(jasperDesignLines);
     } catch (JRException e) {
       e.printStackTrace();
       throw new ServletException(e.getMessage());
--- a/src/org/openbravo/erpReports/RptC_ProposalJr.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpReports/RptC_ProposalJr.java	Wed May 06 18:24:45 2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -27,13 +27,11 @@
 import javax.servlet.http.HttpServletResponse;
 
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperReport;
-import net.sf.jasperreports.engine.design.JasperDesign;
-import net.sf.jasperreports.engine.xml.JRXmlLoader;
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
 import org.openbravo.erpCommon.utility.Utility;
 
 public class RptC_ProposalJr extends HttpSecureAppServlet {
@@ -69,9 +67,8 @@
 
     JasperReport jasperReportLines;
     try {
-      JasperDesign jasperDesignLines = JRXmlLoader.load(strBaseDesign
+      jasperReportLines = ReportingUtils.compileReport(strBaseDesign
           + "/org/openbravo/erpReports/SubreportLines.jrxml");
-      jasperReportLines = JasperCompileManager.compileReport(jasperDesignLines);
     } catch (JRException e) {
       e.printStackTrace();
       throw new ServletException(e.getMessage());
--- a/src/org/openbravo/erpReports/RptM_Requisition.java	Tue Apr 28 12:50:22 2015 +0530
+++ b/src/org/openbravo/erpReports/RptM_Requisition.java	Wed May 06 18:24:45 2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -27,13 +27,11 @@
 import javax.servlet.http.HttpServletResponse;
 
 import net.sf.jasperreports.engine.JRException;
-import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperReport;
-import net.sf.jasperreports.engine.design.JasperDesign;
-import net.sf.jasperreports.engine.xml.JRXmlLoader;
 
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.client.application.report.ReportingUtils;
 
 public class RptM_Requisition extends HttpSecureAppServlet {
   private static final long serialVersionUID = 1L;
@@ -67,9 +65,8 @@
     HashMap<String, Object> parameters = new HashMap<String, Object>();
     JasperReport jasperReportLines;
     try {
-      JasperDesign jasperDesignLines = JRXmlLoader.load(strBaseDesign
+      jasperReportLines = ReportingUtils.compileReport(strBaseDesign
           + "/org/openbravo/erpReports/RptM_Requisition_Lines.jrxml");
-      jasperReportLines = JasperCompileManager.compileReport(jasperDesignLines);
     } catch (JRException e) {
       e.printStackTrace();
       throw new ServletException(e.getMessage());