Feature #232 » patch.diff
src/com/servoy/plugins/jasperreports/IJasperReportRunner.java (working copy) | ||
---|---|---|
32 | 32 |
import java.rmi.RemoteException; |
33 | 33 |
import java.util.Map; |
34 | 34 | |
35 |
import org.mozilla.javascript.Function; |
|
36 | ||
35 | 37 |
import net.sf.jasperreports.engine.JRException; |
36 | 38 |
import net.sf.jasperreports.engine.JasperPrint; |
37 | 39 | |
... | ... | |
40 | 42 |
*/ |
41 | 43 |
public interface IJasperReportRunner { |
42 | 44 | |
43 |
public JasperPrint getJasperPrint(String clientID, Object source, String report, Map parameters, String repdir, String extraDirs) throws RemoteException, Exception; |
|
45 |
public JasperPrint getJasperPrint(String clientID, Object source, String report, Map parameters, String repdir, String extraDirs, Function fillProgressCallback) throws RemoteException, Exception;
|
|
44 | 46 |
} |
src/com/servoy/plugins/jasperreports/IJasperReportsService.java (working copy) | ||
---|---|---|
34 | 34 |
import java.rmi.RemoteException; |
35 | 35 |
import java.util.Map; |
36 | 36 | |
37 |
import org.mozilla.javascript.Function; |
|
38 | ||
37 | 39 |
import net.sf.jasperreports.engine.JasperPrint; |
38 | 40 |
import net.sf.jasperreports.engine.JasperReport; |
39 | 41 | |
... | ... | |
64 | 66 | |
65 | 67 |
public JasperReport getJasperReport(String clientID, String report, String repdir) throws RemoteException, Exception; |
66 | 68 |
|
67 |
public byte[] getJasperBytes(String clientID, String type, JasperPrint jasperPrint, String extraDirs, Map exporterParameters) throws RemoteException, Exception; |
|
69 |
public byte[] getJasperBytes(String clientID, String type, JasperPrint jasperPrint, String extraDirs, Map exporterParameters, Function fillProgressCallback, Function exportProgressCallback) throws RemoteException, Exception;
|
|
68 | 70 | |
69 | 71 |
public byte[] loadImage(String clientID, String image) throws RemoteException, Exception; |
70 | 72 |
src/com/servoy/plugins/jasperreports/JasperReportRunner.java (working copy) | ||
---|---|---|
39 | 39 |
import java.util.Iterator; |
40 | 40 |
import java.util.Map; |
41 | 41 | |
42 |
import net.servoyforge.plugins.jasperreports.JasperReportsExportProgressMonitor; |
|
43 |
import net.servoyforge.plugins.jasperreports.JasperReportsDefaultScriptlet; |
|
42 | 44 |
import net.sf.jasperreports.engine.JRDataSource; |
43 | 45 |
import net.sf.jasperreports.engine.JRException; |
44 | 46 |
import net.sf.jasperreports.engine.JRExporter; |
... | ... | |
48 | 50 |
import net.sf.jasperreports.engine.JasperPrint; |
49 | 51 |
import net.sf.jasperreports.engine.JasperReport; |
50 | 52 |
import net.sf.jasperreports.engine.export.JRCsvExporter; |
53 |
import net.sf.jasperreports.engine.export.JRExportProgressMonitor; |
|
51 | 54 |
import net.sf.jasperreports.engine.export.JRHtmlExporter; |
52 | 55 |
import net.sf.jasperreports.engine.export.JRPdfExporter; |
53 | 56 |
import net.sf.jasperreports.engine.export.JRRtfExporter; |
... | ... | |
61 | 64 |
import net.sf.jasperreports.engine.export.oasis.JROdsExporter; |
62 | 65 |
import net.sf.jasperreports.engine.export.oasis.JROdtExporter; |
63 | 66 |
import net.sf.jasperreports.engine.export.ooxml.JRDocxExporter; |
64 |
import net.sf.jasperreports.engine.util.JRImageLoader; |
|
65 |
import net.sf.jasperreports.engine.util.JRLoader; |
|
66 |
import net.sf.jasperreports.engine.util.JRSaver; |
|
67 |
import net.sf.jasperreports.engine.util.SimpleFileResolver; |
|
68 | ||
69 | 67 |
import net.sf.jasperreports.engine.fill.JRAbstractLRUVirtualizer; |
70 | 68 |
import net.sf.jasperreports.engine.fill.JRFileVirtualizer; |
71 | 69 |
import net.sf.jasperreports.engine.fill.JRGzipVirtualizer; |
72 | 70 |
import net.sf.jasperreports.engine.fill.JRSwapFileVirtualizer; |
71 |
import net.sf.jasperreports.engine.util.JRSaver; |
|
73 | 72 |
import net.sf.jasperreports.engine.util.JRSwapFile; |
73 |
import net.sf.jasperreports.engine.util.SimpleFileResolver; |
|
74 | ||
75 |
import org.mozilla.javascript.Function; |
|
74 | 76 | |
75 | 77 |
import com.servoy.j2db.util.Debug; |
76 | 78 | |
... | ... | |
84 | 86 |
private static final String VIRTUALIZER_GZIP = "gZip"; |
85 | 87 | |
86 | 88 |
private final IJasperReportsService jasperReportsService; |
87 | ||
89 |
|
|
88 | 90 |
public JasperReportRunner(IJasperReportsService jasperReportsService) { |
89 | 91 |
this.jasperReportsService = jasperReportsService; |
90 | 92 |
} |
91 | 93 | |
92 |
public JasperPrint getJasperPrint(String clientID, Object source, String report, Map parameters, String repdir, String extraDirs) throws RemoteException, Exception { |
|
94 |
public JasperPrint getJasperPrint(String clientID, Object source, String report, Map parameters, String repdir, String extraDirs, Function fillProgressCallback) throws RemoteException, Exception {
|
|
93 | 95 |
if (source == null) { |
94 | 96 |
throw new IllegalArgumentException("no data source"); |
95 | 97 |
} |
... | ... | |
106 | 108 |
|
107 | 109 |
JasperReport jasperReport = jasperReportsService.getJasperReport(clientID, report, repdir); |
108 | 110 | |
109 |
return getJasperPrint(jasperReport, null, (JRDataSource) source, parameters, repdir, extraDirs); |
|
111 |
return getJasperPrint(jasperReport, null, (JRDataSource) source, parameters, repdir, extraDirs, fillProgressCallback);
|
|
110 | 112 |
} |
111 | 113 | |
112 | 114 |
|
113 |
public static byte[] getJasperBytes(String type, JasperPrint jasperPrint, String extraDirs, Map exporterParameters) throws IOException, JRException { |
|
115 |
public static byte[] getJasperBytes(String type, JasperPrint jasperPrint, String extraDirs, Map exporterParameters, Function exportProgressCallback) throws IOException, JRException {
|
|
114 | 116 |
// exporting the report |
115 | 117 |
if (type.equalsIgnoreCase(OUTPUT_FORMAT.JRPRINT)) { |
116 | 118 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
117 | 119 |
JRSaver.saveObject(jasperPrint, baos); |
118 | 120 |
return baos.toByteArray(); |
119 | 121 |
} |
120 |
|
|
121 | 122 |
JRExporter exporter; |
122 | 123 |
if (type.equalsIgnoreCase(OUTPUT_FORMAT.PDF)) { |
123 | 124 |
exporter = new JRPdfExporter(); |
... | ... | |
181 | 182 |
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); |
182 | 183 |
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos); |
183 | 184 |
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); |
184 |
|
|
185 |
|
|
186 |
// Export Progress Monitor |
|
187 |
if(exportProgressCallback instanceof Function) { |
|
188 |
JRExportProgressMonitor epm = new JasperReportsExportProgressMonitor(jasperPrint.getPages().size(), exportProgressCallback); |
|
189 |
exporter.setParameter(JRExporterParameter.PROGRESS_MONITOR, epm); |
|
190 |
} |
|
191 |
|
|
185 | 192 |
if (exporterParameters != null) |
186 | 193 |
{ |
187 | 194 |
if (exporterParameters.containsKey(EXPORTER_PARAMETERS.PAGE_INDEX))exporter.setParameter(JRExporterParameter.PAGE_INDEX, (Integer)exporterParameters.get(EXPORTER_PARAMETERS.PAGE_INDEX)); |
... | ... | |
206 | 213 |
return baos.toByteArray(); |
207 | 214 |
} |
208 | 215 |
|
209 |
public static JasperPrint getJasperPrint(JasperReport jasperReport, Connection connection, JRDataSource jrDataSource, Map parameters, String repdir, String extraDirs) throws JRException { |
|
216 |
@SuppressWarnings("unchecked") |
|
217 |
public static JasperPrint getJasperPrint(JasperReport jasperReport, Connection connection, JRDataSource jrDataSource, Map parameters, String repdir, String extraDirs, Function fillProgressCallback) throws JRException { |
|
210 | 218 |
// client - fill (the compiled) report |
211 | 219 |
Debug.trace("JasperTrace: Directory: " + repdir); |
212 | 220 |
|
... | ... | |
283 | 291 |
parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer); |
284 | 292 |
} |
285 | 293 |
|
294 |
// Scriptlet for monitoring fill progress |
|
295 |
if(fillProgressCallback instanceof Function) { |
|
296 |
JasperReportsDefaultScriptlet scr = new JasperReportsDefaultScriptlet(fillProgressCallback); |
|
297 |
parameters.put(JRParameter.REPORT_SCRIPTLET, scr); |
|
298 |
} |
|
286 | 299 | |
287 | 300 |
JRParameter[] params = jasperReport.getParameters(); |
288 | 301 |
// Check to see if the report has parameters that should be prompted |
src/com/servoy/plugins/jasperreports/JasperReportsProvider.java (working copy) | ||
---|---|---|
48 | 48 | |
49 | 49 |
import javax.print.PrintService; |
50 | 50 | |
51 |
import org.mozilla.javascript.Function; |
|
52 | ||
51 | 53 |
import net.sf.jasperreports.engine.JRDataSource; |
52 | 54 |
import net.sf.jasperreports.engine.JRPrintElement; |
53 | 55 |
import net.sf.jasperreports.engine.JRPrintPage; |
... | ... | |
95 | 97 |
"reportFileName ", |
96 | 98 |
"exportFileName / boolean showPrintDialog / printerName", |
97 | 99 |
"outputFormat", "parameters", "[locale]", |
98 |
"[moveTableOfContents]" }, { "Execute a Report" }, |
|
100 |
"[moveTableOfContents]", "[fillProgressCallback]", "[exportProgressCallback]" }, { "Execute a Report" },
|
|
99 | 101 |
{} }, |
100 | 102 |
{ |
101 | 103 |
{ "writeFileToReportsDir" }, |
... | ... | |
266 | 268 |
retval.append("// var ds = foundset.getDataSource();\n"); |
267 | 269 |
retval.append("// var d = ds.split('/);\n"); |
268 | 270 |
retval.append("// var myServer = d[1]; \n"); |
271 |
retval.append("\n"); |
|
272 |
retval.append("/*Monitoring Progress\n"); |
|
273 |
retval.append("\n"); |
|
274 |
retval.append("The JasperReports plugin has support for monitoring the progress of report\n"); |
|
275 |
retval.append("filling and report exporting via callback methods. The runReport method now\n"); |
|
276 |
retval.append("optionally allows for the passing of two new parameters: fillProgressMonitor\n"); |
|
277 |
retval.append("and/or exportProgressMonitor.\n"); |
|
278 |
retval.append("\n"); |
|
279 |
retval.append("Both fillProgressMonitor and exportProgressMonitor should be of type\n"); |
|
280 |
retval.append("org.mozilla.javascript.Function. That is to say that you need to pass an actual\n"); |
|
281 |
retval.append("Servoy function (without \"()\"), and not a string function name. Functions should\n"); |
|
282 |
retval.append("be globally or form scoped, and may not be subroutines. Meaning you can't pass a\n"); |
|
283 |
retval.append("function that is defined within another function block. Neither progress monitor\n"); |
|
284 |
retval.append("is required; they may be specified together or individually.\n"); |
|
285 |
retval.append("\n"); |
|
286 |
retval.append("The callback function for fillProgressMonitor should be defined to accept one\n"); |
|
287 |
retval.append("parameter. Passed into this parameter from the plugin will be the page number of\n"); |
|
288 |
retval.append("the page that just finished filling; after each page is finished filling. No other\n"); |
|
289 |
retval.append("information will be passed.\n"); |
|
290 |
retval.append("\n"); |
|
291 |
retval.append("Note: The fill process is indeterminate in nature. That means that JasperReports\n"); |
|
292 |
retval.append("does not know the total number of pages that will comprise a report until after all\n"); |
|
293 |
retval.append("of the pages have been filled. This is why the fillProgressMonitor callback function\n"); |
|
294 |
retval.append("only accepts a single parameter.\n"); |
|
295 |
retval.append("\n"); |
|
296 |
retval.append("The callback function for exportProgressMonitor should be defined to accept two\n"); |
|
297 |
retval.append("parameters. Passed into these parameters from the plugin will be the current page\n"); |
|
298 |
retval.append("that has been exported, and the total number of pages of the report. Using this\n"); |
|
299 |
retval.append("information you can build a progress meter, that is not indeterminate (unlike\n"); |
|
300 |
retval.append("filling).\n"); |
|
301 |
retval.append("\n"); |
|
302 |
retval.append("It pays to point out that not all output formats use an exporter. For example the\n"); |
|
303 |
retval.append("viewer does not use an exporter, and so specifying a callback for\n"); |
|
304 |
retval.append("exportProgressMonitor and choosing the output type view will not yield any results.\n"); |
|
305 |
retval.append("\n"); |
|
306 |
retval.append("It also pays to point out that generally speaking exporting is much quicker than\n"); |
|
307 |
retval.append("filling, so you can expect that the fill process to take quite a while longer than\n"); |
|
308 |
retval.append("exporting.\n"); |
|
309 |
retval.append("*/\n"); |
|
310 |
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"); |
|
311 |
retval.append("\n"); |
|
312 |
retval.append("//function fillProgressMonitor(page) {\n"); |
|
313 |
retval.append("//\tapplication.output(\"Filled page \" page);\n"); |
|
314 |
retval.append("//}\n"); |
|
315 |
retval.append("\n"); |
|
316 |
retval.append("//function exportProgressMonitor(page, pageCount) {\n"); |
|
317 |
retval.append("//\tapplication.output(\\\"Exported pag \" + page + \" of\" + pageCount);\n"); |
|
318 |
retval.append("//}"); |
|
269 | 319 |
return retval.toString(); |
270 | 320 |
} else { |
271 | 321 |
String[] as = getProperty(methodName, EXAMPLE); |
... | ... | |
366 | 416 |
public byte[] js_runReport(Object source, String report, Object arg, |
367 | 417 |
String type, Object parameters, String localeString, |
368 | 418 |
Boolean moveTableOfContent) throws Exception { |
419 |
return js_runReport(source, report, arg, type, parameters, localeString, |
|
420 |
moveTableOfContent, null); |
|
421 |
} |
|
422 |
|
|
423 |
public byte[] js_runReport(Object source, String report, Object arg, |
|
424 |
String type, Object parameters, String localeString, |
|
425 |
Boolean moveTableOfContent, Function fillProgressCallback) throws Exception { |
|
426 |
return runReport(source, report, arg, type, parameters, localeString, |
|
427 |
moveTableOfContent, fillProgressCallback, null); |
|
428 |
} |
|
429 |
|
|
430 |
public byte[] js_runReport(Object source, String report, Object arg, |
|
431 |
String type, Object parameters, String localeString, |
|
432 |
Boolean moveTableOfContent, Function fillProgressCallback, Function exportProgressCallback) throws Exception { |
|
369 | 433 |
return runReport(source, report, arg, type, parameters, localeString, |
370 |
moveTableOfContent); |
|
434 |
moveTableOfContent, fillProgressCallback, exportProgressCallback);
|
|
371 | 435 |
} |
372 | 436 | |
373 | 437 |
private byte[] runReport(Object source, String report, Object arg, |
374 | 438 |
String type, Object parameters, String localeString, |
375 |
Boolean moveTableOfContent) throws Exception { |
|
439 |
Boolean moveTableOfContent, Function fillProgressCallback, Function exportProgressCallback) throws Exception {
|
|
376 | 440 | |
377 | 441 |
// Check if the directory.jasper.report setting has not yet been set. |
378 | 442 |
String pluginReportsDirectory = plugin.getJasperReportsDirectory(); |
... | ... | |
466 | 530 |
// Also modify the JasperPrint in case you want to move the |
467 | 531 |
// table of contents. |
468 | 532 |
JasperPrint jp = jasperReportRunner.getJasperPrint(plugin.getIClientPluginAccess().getClientID(), source, |
469 |
report, params, plugin.getJasperReportsDirectory(), plugin.getJasperExtraDirectories()); |
|
533 |
report, params, plugin.getJasperReportsDirectory(), plugin.getJasperExtraDirectories(), fillProgressCallback);
|
|
470 | 534 |
if (moveTableOfContent) { |
471 | 535 |
int iP = getInsertPage(jp); |
472 | 536 |
jp = moveTableOfContents(jp, iP); |
... | ... | |
511 | 575 |
} |
512 | 576 | |
513 | 577 |
if (type.equals(OUTPUT_FORMAT.VIEW) || type.equals(OUTPUT_FORMAT.PRINT)) { |
514 |
jsp = JasperReportRunner.getJasperBytes("pdf", jp, plugin.getJasperExtraDirectories(),exporterParams); |
|
578 |
jsp = JasperReportRunner.getJasperBytes("pdf", jp, plugin.getJasperExtraDirectories(),exporterParams, exportProgressCallback);
|
|
515 | 579 |
JasperReportsWebViewer.show(plugin.getIClientPluginAccess(), jsp, file, "pdf", mimeType); |
516 | 580 |
} else { |
517 |
jsp = JasperReportRunner.getJasperBytes(type, jp, plugin.getJasperExtraDirectories(),exporterParams); |
|
581 |
jsp = JasperReportRunner.getJasperBytes(type, jp, plugin.getJasperExtraDirectories(),exporterParams, exportProgressCallback);
|
|
518 | 582 |
if (nooutput) { |
519 | 583 |
JasperReportsWebViewer.show(plugin.getIClientPluginAccess(), jsp, file, type, mimeType); |
520 | 584 |
} else { |
... | ... | |
586 | 650 |
} else { |
587 | 651 |
if (!nooutput) { |
588 | 652 |
jsp = jasperReportService.getJasperBytes(plugin.getIClientPluginAccess().getClientID(), |
589 |
type, jp, plugin.getJasperExtraDirectories(), exporterParams); |
|
653 |
type, jp, plugin.getJasperExtraDirectories(), exporterParams, fillProgressCallback, exportProgressCallback);
|
|
590 | 654 |
saveByteArrayToFile(file, jsp); |
591 | 655 |
} |
592 | 656 |
} |
src/com/servoy/plugins/jasperreports/JasperReportsServer.java (working copy) | ||
---|---|---|
49 | 49 |
import java.util.Map; |
50 | 50 |
import java.util.Properties; |
51 | 51 | |
52 |
import org.mozilla.javascript.Function; |
|
53 | ||
52 | 54 |
import net.sf.jasperreports.engine.JRDataSource; |
53 | 55 |
import net.sf.jasperreports.engine.JRException; |
54 | 56 |
import net.sf.jasperreports.engine.JRParameter; |
... | ... | |
182 | 184 |
return jasperReport; |
183 | 185 |
} |
184 | 186 | |
185 |
public byte[] getJasperBytes(String clientID, String type, JasperPrint jasperPrint, String extraDirs, Map exporterParams) throws Exception { |
|
187 |
public byte[] getJasperBytes(String clientID, String type, JasperPrint jasperPrint, String extraDirs, Map exporterParams, Function fillProgressCallback, Function exportProgressCallback) throws Exception {
|
|
186 | 188 |
|
187 | 189 |
if (!hasAccess(clientID)) return null; |
188 | 190 |
|
... | ... | |
200 | 202 |
} |
201 | 203 |
|
202 | 204 |
try { |
203 |
return JasperReportRunner.getJasperBytes(type, jasperPrint, extraDirs, exporterParams); |
|
205 |
return JasperReportRunner.getJasperBytes(type, jasperPrint, extraDirs, exporterParams, exportProgressCallback);
|
|
204 | 206 |
} finally { |
205 | 207 |
|
206 | 208 |
if (serviceSet) { |
... | ... | |
212 | 214 |
} |
213 | 215 |
} |
214 | 216 |
|
215 |
public JasperPrint getJasperPrint(String clientID, Object source, String report, Map parameters, String repdir, String extraDirs) throws Exception { |
|
217 |
public JasperPrint getJasperPrint(String clientID, Object source, String report, Map parameters, String repdir, String extraDirs, Function fillProgressCallback) throws Exception {
|
|
216 | 218 |
|
217 | 219 |
String dbalias = null; |
218 | 220 |
JRDataSource jrds = null; |
... | ... | |
259 | 261 |
|
260 | 262 |
JasperReport jasperReport = getJasperReport(clientID, report, repdir); |
261 | 263 |
|
262 |
return JasperReportRunner.getJasperPrint(jasperReport, conn, jrds, parameters, repdir, extraDirs); |
|
264 |
return JasperReportRunner.getJasperPrint(jasperReport, conn, jrds, parameters, repdir, extraDirs, fillProgressCallback);
|
|
263 | 265 | |
264 | 266 |
} finally { |
265 | 267 |
if (conn != null) |
src/net/servoyforge/plugins/jasperreports/JasperReportsDefaultScriptlet.java (revision 0) | ||
---|---|---|
1 |
/* |
|
2 |
Software License Agreement (FreeBSD License) |
|
3 |
Copyright (c) 2011, Jeff Bader |
|
4 |
All rights reserved. |
|
5 | ||
6 |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following |
|
7 |
conditions are met: |
|
8 | ||
9 |
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
|
10 |
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer |
|
11 |
in the documentation and/or other materials provided with the distribution. |
|
12 | ||
13 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT |
|
14 |
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
|
15 |
THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
16 |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
17 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
|
18 |
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
19 |
*/ |
|
20 |
package net.servoyforge.plugins.jasperreports; |
|
21 | ||
22 |
import org.mozilla.javascript.Context; |
|
23 |
import org.mozilla.javascript.Function; |
|
24 |
import org.mozilla.javascript.Scriptable; |
|
25 | ||
26 |
import com.servoy.j2db.scripting.FunctionDefinition; |
|
27 |
import com.servoy.j2db.util.Debug; |
|
28 | ||
29 |
import net.sf.jasperreports.engine.JRAbstractScriptlet; |
|
30 |
import net.sf.jasperreports.engine.JRScriptletException; |
|
31 | ||
32 |
/** |
|
33 |
* @author Jeff Bader |
|
34 |
* |
|
35 |
*/ |
|
36 |
public class JasperReportsDefaultScriptlet extends JRAbstractScriptlet { |
|
37 | ||
38 |
private Function fn; |
|
39 |
private FunctionDefinition def; |
|
40 |
private String methodString; |
|
41 |
|
|
42 |
public JasperReportsDefaultScriptlet(Function fillProgressCallback) { |
|
43 |
this.fn = fillProgressCallback; |
|
44 |
this.def = new FunctionDefinition(fillProgressCallback); |
|
45 |
this.methodString = def.toMethodString(); |
|
46 |
} |
|
47 | ||
48 |
/* (non-Javadoc) |
|
49 |
* @see net.sf.jasperreports.engine.JRAbstractScriptlet#afterColumnInit() |
|
50 |
*/ |
|
51 |
@Override |
|
52 |
public void afterColumnInit() throws JRScriptletException { |
|
53 |
// TODO Auto-generated method stub |
|
54 | ||
55 |
} |
|
56 | ||
57 |
/* (non-Javadoc) |
|
58 |
* @see net.sf.jasperreports.engine.JRAbstractScriptlet#afterDetailEval() |
|
59 |
*/ |
|
60 |
@Override |
|
61 |
public void afterDetailEval() throws JRScriptletException { |
|
62 |
// TODO Auto-generated method stub |
|
63 | ||
64 |
} |
|
65 | ||
66 |
/* (non-Javadoc) |
|
67 |
* @see net.sf.jasperreports.engine.JRAbstractScriptlet#afterGroupInit(java.lang.String) |
|
68 |
*/ |
|
69 |
@Override |
|
70 |
public void afterGroupInit(String arg0) throws JRScriptletException { |
|
71 |
// TODO Auto-generated method stub |
|
72 | ||
73 |
} |
|
74 | ||
75 |
/* (non-Javadoc) |
|
76 |
* @see net.sf.jasperreports.engine.JRAbstractScriptlet#afterPageInit() |
|
77 |
*/ |
|
78 |
@Override |
|
79 |
public void afterPageInit() throws JRScriptletException { |
|
80 |
String s = ""; |
|
81 |
String formName = def.getFormName(); |
|
82 |
if(formName != null) { |
|
83 |
s = "forms." + methodString; |
|
84 |
} |
|
85 |
else { |
|
86 |
s = methodString; |
|
87 |
} |
|
88 |
Context cx = Context.enter(); |
|
89 |
cx.evaluateString((Scriptable)fn, s + "(" + this.getVariableValue("PAGE_NUMBER") + ")", "MySource", 1, null); |
|
90 |
} |
|
91 | ||
92 |
/* (non-Javadoc) |
|
93 |
* @see net.sf.jasperreports.engine.JRAbstractScriptlet#afterReportInit() |
|
94 |
*/ |
|
95 |
@Override |
|
96 |
public void afterReportInit() throws JRScriptletException { |
|
97 |
// TODO Auto-generated method stub |
|
98 | ||
99 |
} |
|
100 | ||
101 |
/* (non-Javadoc) |
|
102 |
* @see net.sf.jasperreports.engine.JRAbstractScriptlet#beforeColumnInit() |
|
103 |
*/ |
|
104 |
@Override |
|
105 |
public void beforeColumnInit() throws JRScriptletException { |
|
106 |
// TODO Auto-generated method stub |
|
107 | ||
108 |
} |
|
109 | ||
110 |
/* (non-Javadoc) |
|
111 |
* @see net.sf.jasperreports.engine.JRAbstractScriptlet#beforeDetailEval() |
|
112 |
*/ |
|
113 |
@Override |
|
114 |
public void beforeDetailEval() throws JRScriptletException { |
|
115 |
// TODO Auto-generated method stub |
|
116 | ||
117 |
} |
|
118 | ||
119 |
/* (non-Javadoc) |
|
120 |
* @see net.sf.jasperreports.engine.JRAbstractScriptlet#beforeGroupInit(java.lang.String) |
|
121 |
*/ |
|
122 |
@Override |
|
123 |
public void beforeGroupInit(String arg0) throws JRScriptletException { |
|
124 |
// TODO Auto-generated method stub |
|
125 | ||
126 |
} |
|
127 | ||
128 |
/* (non-Javadoc) |
|
129 |
* @see net.sf.jasperreports.engine.JRAbstractScriptlet#beforePageInit() |
|
130 |
*/ |
|
131 |
@Override |
|
132 |
public void beforePageInit() throws JRScriptletException { |
|
133 |
// TODO Auto-generated method stub |
|
134 |
|
|
135 |
} |
|
136 | ||
137 |
/* (non-Javadoc) |
|
138 |
* @see net.sf.jasperreports.engine.JRAbstractScriptlet#beforeReportInit() |
|
139 |
*/ |
|
140 |
@Override |
|
141 |
public void beforeReportInit() throws JRScriptletException { |
|
142 |
// TODO Auto-generated method stub |
|
143 | ||
144 |
} |
|
145 | ||
146 |
} |
src/net/servoyforge/plugins/jasperreports/JasperReportsExportProgressMonitor.java (revision 0) | ||
---|---|---|
1 |
/* |
|
2 |
Software License Agreement (FreeBSD License) |
|
3 |
Copyright (c) 2011, Jeff Bader |
|
4 |
All rights reserved. |
|
5 | ||
6 |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following |
|
7 |
conditions are met: |
|
8 | ||
9 |
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
|
10 |
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer |
|
11 |
in the documentation and/or other materials provided with the distribution. |
|
12 | ||
13 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT |
|
14 |
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
|
15 |
THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
16 |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
17 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
|
18 |
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
19 |
*/ |
|
20 |
package net.servoyforge.plugins.jasperreports; |
|
21 | ||
22 |
import net.sf.jasperreports.engine.export.JRExportProgressMonitor; |
|
23 | ||
24 |
import org.mozilla.javascript.Context; |
|
25 |
import org.mozilla.javascript.Function; |
|
26 |
import org.mozilla.javascript.Scriptable; |
|
27 | ||
28 |
import com.servoy.j2db.scripting.FunctionDefinition; |
|
29 |
import com.servoy.j2db.util.Debug; |
|
30 | ||
31 | ||
32 |
/** |
|
33 |
* @author Jeff Bader |
|
34 |
* |
|
35 |
*/ |
|
36 |
public class JasperReportsExportProgressMonitor implements JRExportProgressMonitor { |
|
37 | ||
38 |
private Integer pageCount; |
|
39 |
private Integer page = 1; |
|
40 |
private Function fn; |
|
41 |
private FunctionDefinition def; |
|
42 |
private String methodString; |
|
43 |
|
|
44 | ||
45 |
/** |
|
46 |
* @param pageCount |
|
47 |
* @param exportProgressCallback |
|
48 |
*/ |
|
49 |
public JasperReportsExportProgressMonitor(Integer pageCount, Function exportProgressCallback) { |
|
50 |
this.pageCount = pageCount; |
|
51 |
this.fn = exportProgressCallback; |
|
52 |
this.def = new FunctionDefinition(exportProgressCallback); |
|
53 |
this.methodString = def.toMethodString(); |
|
54 |
} |
|
55 | ||
56 |
/* (non-Javadoc) |
|
57 |
* @see net.sf.jasperreports.engine.export.JRExportProgressMonitor#afterPageExport() |
|
58 |
*/ |
|
59 |
@Override |
|
60 |
public void afterPageExport() { |
|
61 |
String s = ""; |
|
62 |
String formName = def.getFormName(); |
|
63 |
if(formName != null) { |
|
64 |
s = "forms." + methodString; |
|
65 |
} |
|
66 |
else { |
|
67 |
s = methodString; |
|
68 |
} |
|
69 |
Context cx = Context.enter(); |
|
70 |
cx.evaluateString((Scriptable)fn, s + "(" + page + ", " + pageCount + ")", "MySource", 1, null); |
|
71 |
page++; |
|
72 |
} |
|
73 | ||
74 |
} |