Index: src/com/servoy/plugins/jasperreports/IJasperReportRunner.java =================================================================== --- src/com/servoy/plugins/jasperreports/IJasperReportRunner.java (revision 12) +++ src/com/servoy/plugins/jasperreports/IJasperReportRunner.java (working copy) @@ -32,6 +32,8 @@ import java.rmi.RemoteException; import java.util.Map; +import org.mozilla.javascript.Function; + import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperPrint; @@ -40,5 +42,5 @@ */ public interface IJasperReportRunner { - public JasperPrint getJasperPrint(String clientID, Object source, String report, Map parameters, String repdir, String extraDirs) throws RemoteException, Exception; + public JasperPrint getJasperPrint(String clientID, Object source, String report, Map parameters, String repdir, String extraDirs, Function fillProgressCallback) throws RemoteException, Exception; } Index: src/com/servoy/plugins/jasperreports/IJasperReportsService.java =================================================================== --- src/com/servoy/plugins/jasperreports/IJasperReportsService.java (revision 12) +++ src/com/servoy/plugins/jasperreports/IJasperReportsService.java (working copy) @@ -34,6 +34,8 @@ import java.rmi.RemoteException; import java.util.Map; +import org.mozilla.javascript.Function; + import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; @@ -64,7 +66,7 @@ public JasperReport getJasperReport(String clientID, String report, String repdir) throws RemoteException, Exception; - public byte[] getJasperBytes(String clientID, String type, JasperPrint jasperPrint, String extraDirs, Map exporterParameters) throws RemoteException, Exception; + public byte[] getJasperBytes(String clientID, String type, JasperPrint jasperPrint, String extraDirs, Map exporterParameters, Function fillProgressCallback, Function exportProgressCallback) throws RemoteException, Exception; public byte[] loadImage(String clientID, String image) throws RemoteException, Exception; Index: src/com/servoy/plugins/jasperreports/JasperReportRunner.java =================================================================== --- src/com/servoy/plugins/jasperreports/JasperReportRunner.java (revision 12) +++ src/com/servoy/plugins/jasperreports/JasperReportRunner.java (working copy) @@ -39,6 +39,8 @@ import java.util.Iterator; import java.util.Map; +import net.servoyforge.plugins.jasperreports.JasperReportsExportProgressMonitor; +import net.servoyforge.plugins.jasperreports.JasperReportsDefaultScriptlet; import net.sf.jasperreports.engine.JRDataSource; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRExporter; @@ -48,6 +50,7 @@ import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.export.JRCsvExporter; +import net.sf.jasperreports.engine.export.JRExportProgressMonitor; import net.sf.jasperreports.engine.export.JRHtmlExporter; import net.sf.jasperreports.engine.export.JRPdfExporter; import net.sf.jasperreports.engine.export.JRRtfExporter; @@ -61,16 +64,15 @@ import net.sf.jasperreports.engine.export.oasis.JROdsExporter; import net.sf.jasperreports.engine.export.oasis.JROdtExporter; import net.sf.jasperreports.engine.export.ooxml.JRDocxExporter; -import net.sf.jasperreports.engine.util.JRImageLoader; -import net.sf.jasperreports.engine.util.JRLoader; -import net.sf.jasperreports.engine.util.JRSaver; -import net.sf.jasperreports.engine.util.SimpleFileResolver; - import net.sf.jasperreports.engine.fill.JRAbstractLRUVirtualizer; import net.sf.jasperreports.engine.fill.JRFileVirtualizer; import net.sf.jasperreports.engine.fill.JRGzipVirtualizer; import net.sf.jasperreports.engine.fill.JRSwapFileVirtualizer; +import net.sf.jasperreports.engine.util.JRSaver; import net.sf.jasperreports.engine.util.JRSwapFile; +import net.sf.jasperreports.engine.util.SimpleFileResolver; + +import org.mozilla.javascript.Function; import com.servoy.j2db.util.Debug; @@ -84,12 +86,12 @@ private static final String VIRTUALIZER_GZIP = "gZip"; private final IJasperReportsService jasperReportsService; - + public JasperReportRunner(IJasperReportsService jasperReportsService) { this.jasperReportsService = jasperReportsService; } - public JasperPrint getJasperPrint(String clientID, Object source, String report, Map parameters, String repdir, String extraDirs) throws RemoteException, Exception { + public JasperPrint getJasperPrint(String clientID, Object source, String report, Map parameters, String repdir, String extraDirs, Function fillProgressCallback) throws RemoteException, Exception { if (source == null) { throw new IllegalArgumentException("no data source"); } @@ -106,18 +108,17 @@ JasperReport jasperReport = jasperReportsService.getJasperReport(clientID, report, repdir); - return getJasperPrint(jasperReport, null, (JRDataSource) source, parameters, repdir, extraDirs); + return getJasperPrint(jasperReport, null, (JRDataSource) source, parameters, repdir, extraDirs, fillProgressCallback); } - public static byte[] getJasperBytes(String type, JasperPrint jasperPrint, String extraDirs, Map exporterParameters) throws IOException, JRException { + public static byte[] getJasperBytes(String type, JasperPrint jasperPrint, String extraDirs, Map exporterParameters, Function exportProgressCallback) throws IOException, JRException { // exporting the report if (type.equalsIgnoreCase(OUTPUT_FORMAT.JRPRINT)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); JRSaver.saveObject(jasperPrint, baos); return baos.toByteArray(); } - JRExporter exporter; if (type.equalsIgnoreCase(OUTPUT_FORMAT.PDF)) { exporter = new JRPdfExporter(); @@ -181,7 +182,13 @@ exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); - + + // Export Progress Monitor + if(exportProgressCallback instanceof Function) { + JRExportProgressMonitor epm = new JasperReportsExportProgressMonitor(jasperPrint.getPages().size(), exportProgressCallback); + exporter.setParameter(JRExporterParameter.PROGRESS_MONITOR, epm); + } + if (exporterParameters != null) { if (exporterParameters.containsKey(EXPORTER_PARAMETERS.PAGE_INDEX))exporter.setParameter(JRExporterParameter.PAGE_INDEX, (Integer)exporterParameters.get(EXPORTER_PARAMETERS.PAGE_INDEX)); @@ -206,7 +213,8 @@ return baos.toByteArray(); } - public static JasperPrint getJasperPrint(JasperReport jasperReport, Connection connection, JRDataSource jrDataSource, Map parameters, String repdir, String extraDirs) throws JRException { + @SuppressWarnings("unchecked") + public static JasperPrint getJasperPrint(JasperReport jasperReport, Connection connection, JRDataSource jrDataSource, Map parameters, String repdir, String extraDirs, Function fillProgressCallback) throws JRException { // client - fill (the compiled) report Debug.trace("JasperTrace: Directory: " + repdir); @@ -283,6 +291,11 @@ parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer); } + // Scriptlet for monitoring fill progress + if(fillProgressCallback instanceof Function) { + JasperReportsDefaultScriptlet scr = new JasperReportsDefaultScriptlet(fillProgressCallback); + parameters.put(JRParameter.REPORT_SCRIPTLET, scr); + } JRParameter[] params = jasperReport.getParameters(); // Check to see if the report has parameters that should be prompted Index: src/com/servoy/plugins/jasperreports/JasperReportsProvider.java =================================================================== --- src/com/servoy/plugins/jasperreports/JasperReportsProvider.java (revision 12) +++ src/com/servoy/plugins/jasperreports/JasperReportsProvider.java (working copy) @@ -48,6 +48,8 @@ import javax.print.PrintService; +import org.mozilla.javascript.Function; + import net.sf.jasperreports.engine.JRDataSource; import net.sf.jasperreports.engine.JRPrintElement; import net.sf.jasperreports.engine.JRPrintPage; @@ -95,7 +97,7 @@ "reportFileName ", "exportFileName / boolean showPrintDialog / printerName", "outputFormat", "parameters", "[locale]", - "[moveTableOfContents]" }, { "Execute a Report" }, + "[moveTableOfContents]", "[fillProgressCallback]", "[exportProgressCallback]" }, { "Execute a Report" }, {} }, { { "writeFileToReportsDir" }, @@ -266,6 +268,54 @@ retval.append("// var ds = foundset.getDataSource();\n"); retval.append("// var d = ds.split('/);\n"); retval.append("// var myServer = d[1]; \n"); + retval.append("\n"); + retval.append("/*Monitoring Progress\n"); + retval.append("\n"); + retval.append("The JasperReports plugin has support for monitoring the progress of report\n"); + retval.append("filling and report exporting via callback methods. The runReport method now\n"); + retval.append("optionally allows for the passing of two new parameters: fillProgressMonitor\n"); + retval.append("and/or exportProgressMonitor.\n"); + retval.append("\n"); + retval.append("Both fillProgressMonitor and exportProgressMonitor should be of type\n"); + retval.append("org.mozilla.javascript.Function. That is to say that you need to pass an actual\n"); + retval.append("Servoy function (without \"()\"), and not a string function name. Functions should\n"); + retval.append("be globally or form scoped, and may not be subroutines. Meaning you can't pass a\n"); + retval.append("function that is defined within another function block. Neither progress monitor\n"); + retval.append("is required; they may be specified together or individually.\n"); + retval.append("\n"); + retval.append("The callback function for fillProgressMonitor should be defined to accept one\n"); + retval.append("parameter. Passed into this parameter from the plugin will be the page number of\n"); + retval.append("the page that just finished filling; after each page is finished filling. No other\n"); + retval.append("information will be passed.\n"); + retval.append("\n"); + retval.append("Note: The fill process is indeterminate in nature. That means that JasperReports\n"); + retval.append("does not know the total number of pages that will comprise a report until after all\n"); + retval.append("of the pages have been filled. This is why the fillProgressMonitor callback function\n"); + retval.append("only accepts a single parameter.\n"); + retval.append("\n"); + retval.append("The callback function for exportProgressMonitor should be defined to accept two\n"); + retval.append("parameters. Passed into these parameters from the plugin will be the current page\n"); + retval.append("that has been exported, and the total number of pages of the report. Using this\n"); + retval.append("information you can build a progress meter, that is not indeterminate (unlike\n"); + retval.append("filling).\n"); + retval.append("\n"); + retval.append("It pays to point out that not all output formats use an exporter. For example the\n"); + retval.append("viewer does not use an exporter, and so specifying a callback for\n"); + retval.append("exportProgressMonitor and choosing the output type view will not yield any results.\n"); + retval.append("\n"); + retval.append("It also pays to point out that generally speaking exporting is much quicker than\n"); + retval.append("filling, so you can expect that the fill process to take quite a while longer than\n"); + retval.append("exporting.\n"); + retval.append("*/\n"); + retval.append("//plugins.jasperPluginRMI.runReport(forms.customers.controller.getServerName(),'myCustomerReport.jasper','c:/myReport.xml',OUTPUT_FORMAT.XML,{pcustomerid: forms.customers.customer_id}, null, false, fillProgressMonitor, exportProgressMonitor);\n"); + retval.append("\n"); + retval.append("//function fillProgressMonitor(page) {\n"); + retval.append("//\tapplication.output(\"Filled page \" page);\n"); + retval.append("//}\n"); + retval.append("\n"); + retval.append("//function exportProgressMonitor(page, pageCount) {\n"); + retval.append("//\tapplication.output(\\\"Exported pag \" + page + \" of\" + pageCount);\n"); + retval.append("//}"); return retval.toString(); } else { String[] as = getProperty(methodName, EXAMPLE); @@ -366,13 +416,27 @@ public byte[] js_runReport(Object source, String report, Object arg, String type, Object parameters, String localeString, Boolean moveTableOfContent) throws Exception { + return js_runReport(source, report, arg, type, parameters, localeString, + moveTableOfContent, null); + } + + public byte[] js_runReport(Object source, String report, Object arg, + String type, Object parameters, String localeString, + Boolean moveTableOfContent, Function fillProgressCallback) throws Exception { + return runReport(source, report, arg, type, parameters, localeString, + moveTableOfContent, fillProgressCallback, null); + } + + public byte[] js_runReport(Object source, String report, Object arg, + String type, Object parameters, String localeString, + Boolean moveTableOfContent, Function fillProgressCallback, Function exportProgressCallback) throws Exception { return runReport(source, report, arg, type, parameters, localeString, - moveTableOfContent); + moveTableOfContent, fillProgressCallback, exportProgressCallback); } private byte[] runReport(Object source, String report, Object arg, String type, Object parameters, String localeString, - Boolean moveTableOfContent) throws Exception { + Boolean moveTableOfContent, Function fillProgressCallback, Function exportProgressCallback) throws Exception { // Check if the directory.jasper.report setting has not yet been set. String pluginReportsDirectory = plugin.getJasperReportsDirectory(); @@ -466,7 +530,7 @@ // Also modify the JasperPrint in case you want to move the // table of contents. JasperPrint jp = jasperReportRunner.getJasperPrint(plugin.getIClientPluginAccess().getClientID(), source, - report, params, plugin.getJasperReportsDirectory(), plugin.getJasperExtraDirectories()); + report, params, plugin.getJasperReportsDirectory(), plugin.getJasperExtraDirectories(), fillProgressCallback); if (moveTableOfContent) { int iP = getInsertPage(jp); jp = moveTableOfContents(jp, iP); @@ -511,10 +575,10 @@ } if (type.equals(OUTPUT_FORMAT.VIEW) || type.equals(OUTPUT_FORMAT.PRINT)) { - jsp = JasperReportRunner.getJasperBytes("pdf", jp, plugin.getJasperExtraDirectories(),exporterParams); + jsp = JasperReportRunner.getJasperBytes("pdf", jp, plugin.getJasperExtraDirectories(),exporterParams, exportProgressCallback); JasperReportsWebViewer.show(plugin.getIClientPluginAccess(), jsp, file, "pdf", mimeType); } else { - jsp = JasperReportRunner.getJasperBytes(type, jp, plugin.getJasperExtraDirectories(),exporterParams); + jsp = JasperReportRunner.getJasperBytes(type, jp, plugin.getJasperExtraDirectories(),exporterParams, exportProgressCallback); if (nooutput) { JasperReportsWebViewer.show(plugin.getIClientPluginAccess(), jsp, file, type, mimeType); } else { @@ -586,7 +650,7 @@ } else { if (!nooutput) { jsp = jasperReportService.getJasperBytes(plugin.getIClientPluginAccess().getClientID(), - type, jp, plugin.getJasperExtraDirectories(), exporterParams); + type, jp, plugin.getJasperExtraDirectories(), exporterParams, fillProgressCallback, exportProgressCallback); saveByteArrayToFile(file, jsp); } } Index: src/com/servoy/plugins/jasperreports/JasperReportsServer.java =================================================================== --- src/com/servoy/plugins/jasperreports/JasperReportsServer.java (revision 12) +++ src/com/servoy/plugins/jasperreports/JasperReportsServer.java (working copy) @@ -49,6 +49,8 @@ import java.util.Map; import java.util.Properties; +import org.mozilla.javascript.Function; + import net.sf.jasperreports.engine.JRDataSource; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRParameter; @@ -182,7 +184,7 @@ return jasperReport; } - public byte[] getJasperBytes(String clientID, String type, JasperPrint jasperPrint, String extraDirs, Map exporterParams) throws Exception { + public byte[] getJasperBytes(String clientID, String type, JasperPrint jasperPrint, String extraDirs, Map exporterParams, Function fillProgressCallback, Function exportProgressCallback) throws Exception { if (!hasAccess(clientID)) return null; @@ -200,7 +202,7 @@ } try { - return JasperReportRunner.getJasperBytes(type, jasperPrint, extraDirs, exporterParams); + return JasperReportRunner.getJasperBytes(type, jasperPrint, extraDirs, exporterParams, exportProgressCallback); } finally { if (serviceSet) { @@ -212,7 +214,7 @@ } } - public JasperPrint getJasperPrint(String clientID, Object source, String report, Map parameters, String repdir, String extraDirs) throws Exception { + public JasperPrint getJasperPrint(String clientID, Object source, String report, Map parameters, String repdir, String extraDirs, Function fillProgressCallback) throws Exception { String dbalias = null; JRDataSource jrds = null; @@ -259,7 +261,7 @@ JasperReport jasperReport = getJasperReport(clientID, report, repdir); - return JasperReportRunner.getJasperPrint(jasperReport, conn, jrds, parameters, repdir, extraDirs); + return JasperReportRunner.getJasperPrint(jasperReport, conn, jrds, parameters, repdir, extraDirs, fillProgressCallback); } finally { if (conn != null) Index: src/com/servoy/plugins/jasperreports/images/jasper16x16.gif =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: src/net/servoyforge/plugins/jasperreports/JasperReportsDefaultScriptlet.java =================================================================== --- src/net/servoyforge/plugins/jasperreports/JasperReportsDefaultScriptlet.java (revision 0) +++ src/net/servoyforge/plugins/jasperreports/JasperReportsDefaultScriptlet.java (revision 0) @@ -0,0 +1,146 @@ +/* + Software License Agreement (FreeBSD License) + Copyright (c) 2011, Jeff Bader + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following + conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.servoyforge.plugins.jasperreports; + +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Function; +import org.mozilla.javascript.Scriptable; + +import com.servoy.j2db.scripting.FunctionDefinition; +import com.servoy.j2db.util.Debug; + +import net.sf.jasperreports.engine.JRAbstractScriptlet; +import net.sf.jasperreports.engine.JRScriptletException; + +/** + * @author Jeff Bader + * + */ +public class JasperReportsDefaultScriptlet extends JRAbstractScriptlet { + + private Function fn; + private FunctionDefinition def; + private String methodString; + + public JasperReportsDefaultScriptlet(Function fillProgressCallback) { + this.fn = fillProgressCallback; + this.def = new FunctionDefinition(fillProgressCallback); + this.methodString = def.toMethodString(); + } + + /* (non-Javadoc) + * @see net.sf.jasperreports.engine.JRAbstractScriptlet#afterColumnInit() + */ + @Override + public void afterColumnInit() throws JRScriptletException { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see net.sf.jasperreports.engine.JRAbstractScriptlet#afterDetailEval() + */ + @Override + public void afterDetailEval() throws JRScriptletException { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see net.sf.jasperreports.engine.JRAbstractScriptlet#afterGroupInit(java.lang.String) + */ + @Override + public void afterGroupInit(String arg0) throws JRScriptletException { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see net.sf.jasperreports.engine.JRAbstractScriptlet#afterPageInit() + */ + @Override + public void afterPageInit() throws JRScriptletException { + String s = ""; + String formName = def.getFormName(); + if(formName != null) { + s = "forms." + methodString; + } + else { + s = methodString; + } + Context cx = Context.enter(); + cx.evaluateString((Scriptable)fn, s + "(" + this.getVariableValue("PAGE_NUMBER") + ")", "MySource", 1, null); + } + + /* (non-Javadoc) + * @see net.sf.jasperreports.engine.JRAbstractScriptlet#afterReportInit() + */ + @Override + public void afterReportInit() throws JRScriptletException { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see net.sf.jasperreports.engine.JRAbstractScriptlet#beforeColumnInit() + */ + @Override + public void beforeColumnInit() throws JRScriptletException { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see net.sf.jasperreports.engine.JRAbstractScriptlet#beforeDetailEval() + */ + @Override + public void beforeDetailEval() throws JRScriptletException { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see net.sf.jasperreports.engine.JRAbstractScriptlet#beforeGroupInit(java.lang.String) + */ + @Override + public void beforeGroupInit(String arg0) throws JRScriptletException { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see net.sf.jasperreports.engine.JRAbstractScriptlet#beforePageInit() + */ + @Override + public void beforePageInit() throws JRScriptletException { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see net.sf.jasperreports.engine.JRAbstractScriptlet#beforeReportInit() + */ + @Override + public void beforeReportInit() throws JRScriptletException { + // TODO Auto-generated method stub + + } + +} Index: src/net/servoyforge/plugins/jasperreports/JasperReportsExportProgressMonitor.java =================================================================== --- src/net/servoyforge/plugins/jasperreports/JasperReportsExportProgressMonitor.java (revision 0) +++ src/net/servoyforge/plugins/jasperreports/JasperReportsExportProgressMonitor.java (revision 0) @@ -0,0 +1,74 @@ +/* + Software License Agreement (FreeBSD License) + Copyright (c) 2011, Jeff Bader + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following + conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer + in the documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.servoyforge.plugins.jasperreports; + +import net.sf.jasperreports.engine.export.JRExportProgressMonitor; + +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Function; +import org.mozilla.javascript.Scriptable; + +import com.servoy.j2db.scripting.FunctionDefinition; +import com.servoy.j2db.util.Debug; + + +/** + * @author Jeff Bader + * + */ +public class JasperReportsExportProgressMonitor implements JRExportProgressMonitor { + + private Integer pageCount; + private Integer page = 1; + private Function fn; + private FunctionDefinition def; + private String methodString; + + + /** + * @param pageCount + * @param exportProgressCallback + */ + public JasperReportsExportProgressMonitor(Integer pageCount, Function exportProgressCallback) { + this.pageCount = pageCount; + this.fn = exportProgressCallback; + this.def = new FunctionDefinition(exportProgressCallback); + this.methodString = def.toMethodString(); + } + + /* (non-Javadoc) + * @see net.sf.jasperreports.engine.export.JRExportProgressMonitor#afterPageExport() + */ + @Override + public void afterPageExport() { + String s = ""; + String formName = def.getFormName(); + if(formName != null) { + s = "forms." + methodString; + } + else { + s = methodString; + } + Context cx = Context.enter(); + cx.evaluateString((Scriptable)fn, s + "(" + page + ", " + pageCount + ")", "MySource", 1, null); + page++; + } + +}