KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > JasperRunManager


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine;
29
30 import java.io.File JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.io.OutputStream JavaDoc;
33 import java.sql.Connection JavaDoc;
34 import java.util.Map JavaDoc;
35
36 import net.sf.jasperreports.engine.util.JRLoader;
37
38
39 /**
40  * Fašade class for the JasperReports engine.
41  *
42  * @author Teodor Danciu (teodord@users.sourceforge.net)
43  * @version $Id: JasperRunManager.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
44  */

45 public class JasperRunManager
46 {
47
48
49     /**
50      * Fills a report and saves it directly into a PDF file.
51      * The intermediate JasperPrint object is not saved on disk.
52      */

53     public static String JavaDoc runReportToPdfFile(
54         String JavaDoc sourceFileName,
55         Map JavaDoc parameters,
56         Connection JavaDoc conn
57         ) throws JRException
58     {
59         File JavaDoc sourceFile = new File JavaDoc(sourceFileName);
60
61         /* */
62         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
63
64         /* */
65         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
66
67         /* */
68         File JavaDoc destFile = new File JavaDoc(sourceFile.getParent(), jasperPrint.getName() + ".pdf");
69         String JavaDoc destFileName = destFile.toString();
70
71         JasperExportManager.exportReportToPdfFile(jasperPrint, destFileName);
72         
73         return destFileName;
74     }
75
76
77     /**
78      * Fills a report and saves it directly into a PDF file.
79      * The intermediate JasperPrint object is not saved on disk.
80      *
81      * @param sourceFileName the name of the compiled report file
82      * @param parameters the parameters map
83      * @return the name of the generated PDF file
84      * @throws JRException
85      * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
86      */

87     public static String JavaDoc runReportToPdfFile(
88         String JavaDoc sourceFileName,
89         Map JavaDoc parameters
90         ) throws JRException
91     {
92         File JavaDoc sourceFile = new File JavaDoc(sourceFileName);
93
94         /* */
95         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
96
97         /* */
98         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);
99
100         /* */
101         File JavaDoc destFile = new File JavaDoc(sourceFile.getParent(), jasperPrint.getName() + ".pdf");
102         String JavaDoc destFileName = destFile.toString();
103
104         JasperExportManager.exportReportToPdfFile(jasperPrint, destFileName);
105         
106         return destFileName;
107     }
108
109     
110     /**
111      * Fills a report and saves it directly into a PDF file.
112      * The intermediate JasperPrint object is not saved on disk.
113      */

114     public static void runReportToPdfFile(
115         String JavaDoc sourceFileName,
116         String JavaDoc destFileName,
117         Map JavaDoc parameters,
118         Connection JavaDoc conn
119         ) throws JRException
120     {
121         /* */
122         JasperPrint jasperPrint = JasperFillManager.fillReport(sourceFileName, parameters, conn);
123
124         JasperExportManager.exportReportToPdfFile(jasperPrint, destFileName);
125     }
126
127
128     /**
129      * Fills a report and saves it directly into a PDF file.
130      * The intermediate JasperPrint object is not saved on disk.
131      *
132      * @param sourceFileName source file containing the compile report design
133      * @param destFileName PDF destination file name
134      * @param parameters report parameters map
135      * @throws JRException
136      * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
137      */

138     public static void runReportToPdfFile(
139         String JavaDoc sourceFileName,
140         String JavaDoc destFileName,
141         Map JavaDoc parameters
142         ) throws JRException
143     {
144         /* */
145         JasperPrint jasperPrint = JasperFillManager.fillReport(sourceFileName, parameters);
146
147         JasperExportManager.exportReportToPdfFile(jasperPrint, destFileName);
148     }
149
150     
151     /**
152      * Fills a report and sends it directly to an OutputStream in PDF format.
153      * The intermediate JasperPrint object is not saved on disk.
154      */

155     public static void runReportToPdfStream(
156         InputStream JavaDoc inputStream,
157         OutputStream JavaDoc outputStream,
158         Map JavaDoc parameters,
159         Connection JavaDoc conn
160         ) throws JRException
161     {
162         /* */
163         JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, parameters, conn);
164
165         JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
166     }
167
168
169     /**
170      * Fills a report and sends it directly to an OutputStream in PDF format.
171      * The intermediate JasperPrint object is not saved on disk.
172      *
173      * @param inputStream compiled report input stream
174      * @param outputStream PDF output stream
175      * @param parameters parameters map
176      * @throws JRException
177      * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
178      */

179     public static void runReportToPdfStream(
180         InputStream JavaDoc inputStream,
181         OutputStream JavaDoc outputStream,
182         Map JavaDoc parameters
183         ) throws JRException
184     {
185         /* */
186         JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, parameters);
187
188         JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
189     }
190
191     
192     /**
193      * Fills a report and returns byte array object containing the report in PDF format.
194      * The intermediate JasperPrint object is not saved on disk.
195      */

196     public static byte[] runReportToPdf(
197         String JavaDoc sourceFileName,
198         Map JavaDoc parameters,
199         Connection JavaDoc conn
200         ) throws JRException
201     {
202         /* */
203         JasperPrint jasperPrint = JasperFillManager.fillReport(sourceFileName, parameters, conn);
204
205         return JasperExportManager.exportReportToPdf(jasperPrint);
206     }
207
208
209     /**
210      * Fills a report and returns byte array object containing the report in PDF format.
211      * The intermediate JasperPrint object is not saved on disk.
212      *
213      * @param sourceFileName source file containing the compile report design
214      * @param parameters report parameters map
215      * @return binary PDF output
216      * @throws JRException
217      * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
218      */

219     public static byte[] runReportToPdf(
220         String JavaDoc sourceFileName,
221         Map JavaDoc parameters
222         ) throws JRException
223     {
224         /* */
225         JasperPrint jasperPrint = JasperFillManager.fillReport(sourceFileName, parameters);
226
227         return JasperExportManager.exportReportToPdf(jasperPrint);
228     }
229
230     
231     /**
232      * Fills a report and returns byte array object containing the report in PDF format.
233      * The intermediate JasperPrint object is not saved on disk.
234      */

235     public static byte[] runReportToPdf(
236         InputStream JavaDoc inputStream,
237         Map JavaDoc parameters,
238         Connection JavaDoc conn
239         ) throws JRException
240     {
241         /* */
242         JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, parameters, conn);
243
244         return JasperExportManager.exportReportToPdf(jasperPrint);
245     }
246
247
248     /**
249      * Fills a report and returns byte array object containing the report in PDF format.
250      * The intermediate JasperPrint object is not saved on disk.
251      *
252      * @param inputStream input stream to read the compiled report design object from
253      * @param parameters report parameters map
254      * @return binary PDF output
255      * @throws JRException
256      * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
257      */

258     public static byte[] runReportToPdf(
259         InputStream JavaDoc inputStream,
260         Map JavaDoc parameters
261         ) throws JRException
262     {
263         /* */
264         JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, parameters);
265
266         return JasperExportManager.exportReportToPdf(jasperPrint);
267     }
268
269     
270     /**
271      * Fills a report and returns byte array object containing the report in PDF format.
272      * The intermediate JasperPrint object is not saved on disk.
273      */

274     public static byte[] runReportToPdf(
275         JasperReport jasperReport,
276         Map JavaDoc parameters,
277         Connection JavaDoc conn
278         ) throws JRException
279     {
280         /* */
281         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
282
283         return JasperExportManager.exportReportToPdf(jasperPrint);
284     }
285
286
287     /**
288      * Fills a report and returns byte array object containing the report in PDF format.
289      * The intermediate JasperPrint object is not saved on disk.
290      *
291      * @param jasperReport the compiled report
292      * @param parameters the parameters map
293      * @return binary PDF output
294      * @throws JRException
295      * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
296      */

297     public static byte[] runReportToPdf(
298         JasperReport jasperReport,
299         Map JavaDoc parameters
300         ) throws JRException
301     {
302         /* */
303         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);
304
305         return JasperExportManager.exportReportToPdf(jasperPrint);
306     }
307
308     
309     /**
310      * Fills a report and saves it directly into a PDF file.
311      * The intermediate JasperPrint object is not saved on disk.
312      */

313     public static String JavaDoc runReportToPdfFile(
314         String JavaDoc sourceFileName,
315         Map JavaDoc parameters,
316         JRDataSource jrDataSource
317         ) throws JRException
318     {
319         File JavaDoc sourceFile = new File JavaDoc(sourceFileName);
320
321         /* */
322         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
323
324         /* */
325         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, jrDataSource);
326
327         /* */
328         File JavaDoc destFile = new File JavaDoc(sourceFile.getParent(), jasperPrint.getName() + ".pdf");
329         String JavaDoc destFileName = destFile.toString();
330
331         JasperExportManager.exportReportToPdfFile(jasperPrint, destFileName);
332         
333         return destFileName;
334     }
335
336     
337     /**
338      * Fills a report and saves it directly into a PDF file.
339      * The intermediate JasperPrint object is not saved on disk.
340      */

341     public static void runReportToPdfFile(
342         String JavaDoc sourceFileName,
343         String JavaDoc destFileName,
344         Map JavaDoc parameters,
345         JRDataSource jrDataSource
346         ) throws JRException
347     {
348         /* */
349         JasperPrint jasperPrint = JasperFillManager.fillReport(sourceFileName, parameters, jrDataSource);
350
351         /* */
352         JasperExportManager.exportReportToPdfFile(jasperPrint, destFileName);
353     }
354
355     
356     /**
357      * Fills a report and sends it directly to an OutputStream in PDF format.
358      * The intermediate JasperPrint object is not saved on disk.
359      */

360     public static void runReportToPdfStream(
361         InputStream JavaDoc inputStream,
362         OutputStream JavaDoc outputStream,
363         Map JavaDoc parameters,
364         JRDataSource jrDataSource
365         ) throws JRException
366     {
367         /* */
368         JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, parameters, jrDataSource);
369
370         JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
371     }
372
373     
374     /**
375      * Fills a report and sends it to an output stream in PDF format.
376      * The intermediate JasperPrint object is not saved on disk.
377      */

378     public static byte[] runReportToPdf(
379         String JavaDoc sourceFileName,
380         Map JavaDoc parameters,
381         JRDataSource jrDataSource
382         ) throws JRException
383     {
384         /* */
385         JasperPrint jasperPrint = JasperFillManager.fillReport(sourceFileName, parameters, jrDataSource);
386
387         return JasperExportManager.exportReportToPdf(jasperPrint);
388     }
389
390     
391     /**
392      * Fills a report and returns byte array object containing the report in PDF format.
393      * The intermediate JasperPrint object is not saved on disk.
394      */

395     public static byte[] runReportToPdf(
396         InputStream JavaDoc inputStream,
397         Map JavaDoc parameters,
398         JRDataSource jrDataSource
399         ) throws JRException
400     {
401         /* */
402         JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, parameters, jrDataSource);
403
404         return JasperExportManager.exportReportToPdf(jasperPrint);
405     }
406
407     
408     /**
409      * Fills a report and returns byte array object containing the report in PDF format.
410      * The intermediate JasperPrint object is not saved on disk.
411      */

412     public static byte[] runReportToPdf(
413         JasperReport jasperReport,
414         Map JavaDoc parameters,
415         JRDataSource jrDataSource
416         ) throws JRException
417     {
418         /* */
419         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, jrDataSource);
420
421         return JasperExportManager.exportReportToPdf(jasperPrint);
422     }
423
424
425     /**
426      * Fills a report and saves it directly into a HTML file.
427      * The intermediate JasperPrint object is not saved on disk.
428      */

429     public static String JavaDoc runReportToHtmlFile(
430         String JavaDoc sourceFileName,
431         Map JavaDoc parameters,
432         Connection JavaDoc conn
433         ) throws JRException
434     {
435         File JavaDoc sourceFile = new File JavaDoc(sourceFileName);
436
437         /* */
438         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
439
440         /* */
441         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
442
443         /* */
444         File JavaDoc destFile = new File JavaDoc(sourceFile.getParent(), jasperPrint.getName() + ".html");
445         String JavaDoc destFileName = destFile.toString();
446
447         JasperExportManager.exportReportToHtmlFile(jasperPrint, destFileName);
448         
449         return destFileName;
450     }
451
452
453     /**
454      * Fills a report and saves it directly into a HTML file.
455      * The intermediate JasperPrint object is not saved on disk.
456      *
457      * @param sourceFileName the name of the compiled report file
458      * @param parameters the parameters map
459      * @return the name of the generated HTML file
460      * @throws JRException
461      * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
462      */

463     public static String JavaDoc runReportToHtmlFile(
464         String JavaDoc sourceFileName,
465         Map JavaDoc parameters
466         ) throws JRException
467     {
468         File JavaDoc sourceFile = new File JavaDoc(sourceFileName);
469
470         /* */
471         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
472
473         /* */
474         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);
475
476         /* */
477         File JavaDoc destFile = new File JavaDoc(sourceFile.getParent(), jasperPrint.getName() + ".html");
478         String JavaDoc destFileName = destFile.toString();
479
480         JasperExportManager.exportReportToHtmlFile(jasperPrint, destFileName);
481         
482         return destFileName;
483     }
484
485     
486     /**
487      * Fills a report and saves it directly into a HTML file.
488      * The intermediate JasperPrint object is not saved on disk.
489      */

490     public static void runReportToHtmlFile(
491         String JavaDoc sourceFileName,
492         String JavaDoc destFileName,
493         Map JavaDoc parameters,
494         Connection JavaDoc conn
495         ) throws JRException
496     {
497         /* */
498         JasperPrint jasperPrint = JasperFillManager.fillReport(sourceFileName, parameters, conn);
499
500         JasperExportManager.exportReportToHtmlFile(jasperPrint, destFileName);
501     }
502
503
504     /**
505      * Fills a report and saves it directly into a HTML file.
506      * The intermediate JasperPrint object is not saved on disk.
507      *
508      * @param sourceFileName source file containing the compile report design
509      * @param destFileName name of the destination HTML file
510      * @param parameters report parameters map
511      * @throws JRException
512      * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
513      */

514     public static void runReportToHtmlFile(
515         String JavaDoc sourceFileName,
516         String JavaDoc destFileName,
517         Map JavaDoc parameters
518         ) throws JRException
519     {
520         /* */
521         JasperPrint jasperPrint = JasperFillManager.fillReport(sourceFileName, parameters);
522
523         JasperExportManager.exportReportToHtmlFile(jasperPrint, destFileName);
524     }
525
526
527     /**
528      * Fills a report and saves it directly into a HTML file.
529      * The intermediate JasperPrint object is not saved on disk.
530      */

531     public static String JavaDoc runReportToHtmlFile(
532         String JavaDoc sourceFileName,
533         Map JavaDoc parameters,
534         JRDataSource jrDataSource
535         ) throws JRException
536     {
537         File JavaDoc sourceFile = new File JavaDoc(sourceFileName);
538
539         /* */
540         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
541
542         /* */
543         JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, jrDataSource);
544
545         /* */
546         File JavaDoc destFile = new File JavaDoc(sourceFile.getParent(), jasperPrint.getName() + ".html");
547         String JavaDoc destFileName = destFile.toString();
548
549         JasperExportManager.exportReportToHtmlFile(jasperPrint, destFileName);
550         
551         return destFileName;
552     }
553
554     
555     /**
556      * Fills a report and saves it directly into a HTML file.
557      * The intermediate JasperPrint object is not saved on disk.
558      */

559     public static void runReportToHtmlFile(
560         String JavaDoc sourceFileName,
561         String JavaDoc destFileName,
562         Map JavaDoc parameters,
563         JRDataSource jrDataSource
564         ) throws JRException
565     {
566         /* */
567         JasperPrint jasperPrint = JasperFillManager.fillReport(sourceFileName, parameters, jrDataSource);
568
569         /* */
570         JasperExportManager.exportReportToHtmlFile(jasperPrint, destFileName);
571     }
572
573     
574 }
575
Popular Tags