001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine;
029:
030: import java.io.File;
031: import java.io.InputStream;
032: import java.io.OutputStream;
033: import java.sql.Connection;
034: import java.util.Map;
035:
036: import net.sf.jasperreports.engine.util.JRLoader;
037:
038: /**
039: * Façade class for the JasperReports engine.
040: *
041: * @author Teodor Danciu (teodord@users.sourceforge.net)
042: * @version $Id: JasperRunManager.java 1229 2006-04-19 10:27:35Z teodord $
043: */
044: public class JasperRunManager {
045:
046: /**
047: * Fills a report and saves it directly into a PDF file.
048: * The intermediate JasperPrint object is not saved on disk.
049: */
050: public static String runReportToPdfFile(String sourceFileName,
051: Map parameters, Connection conn) throws JRException {
052: File sourceFile = new File(sourceFileName);
053:
054: /* */
055: JasperReport jasperReport = (JasperReport) JRLoader
056: .loadObject(sourceFile);
057:
058: /* */
059: JasperPrint jasperPrint = JasperFillManager.fillReport(
060: jasperReport, parameters, conn);
061:
062: /* */
063: File destFile = new File(sourceFile.getParent(), jasperPrint
064: .getName()
065: + ".pdf");
066: String destFileName = destFile.toString();
067:
068: JasperExportManager.exportReportToPdfFile(jasperPrint,
069: destFileName);
070:
071: return destFileName;
072: }
073:
074: /**
075: * Fills a report and saves it directly into a PDF file.
076: * The intermediate JasperPrint object is not saved on disk.
077: *
078: * @param sourceFileName the name of the compiled report file
079: * @param parameters the parameters map
080: * @return the name of the generated PDF file
081: * @throws JRException
082: * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
083: */
084: public static String runReportToPdfFile(String sourceFileName,
085: Map parameters) throws JRException {
086: File sourceFile = new File(sourceFileName);
087:
088: /* */
089: JasperReport jasperReport = (JasperReport) JRLoader
090: .loadObject(sourceFile);
091:
092: /* */
093: JasperPrint jasperPrint = JasperFillManager.fillReport(
094: jasperReport, parameters);
095:
096: /* */
097: File destFile = new File(sourceFile.getParent(), jasperPrint
098: .getName()
099: + ".pdf");
100: String destFileName = destFile.toString();
101:
102: JasperExportManager.exportReportToPdfFile(jasperPrint,
103: destFileName);
104:
105: return destFileName;
106: }
107:
108: /**
109: * Fills a report and saves it directly into a PDF file.
110: * The intermediate JasperPrint object is not saved on disk.
111: */
112: public static void runReportToPdfFile(String sourceFileName,
113: String destFileName, Map parameters, Connection conn)
114: throws JRException {
115: /* */
116: JasperPrint jasperPrint = JasperFillManager.fillReport(
117: sourceFileName, parameters, conn);
118:
119: JasperExportManager.exportReportToPdfFile(jasperPrint,
120: destFileName);
121: }
122:
123: /**
124: * Fills a report and saves it directly into a PDF file.
125: * The intermediate JasperPrint object is not saved on disk.
126: *
127: * @param sourceFileName source file containing the compile report design
128: * @param destFileName PDF destination file name
129: * @param parameters report parameters map
130: * @throws JRException
131: * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
132: */
133: public static void runReportToPdfFile(String sourceFileName,
134: String destFileName, Map parameters) throws JRException {
135: /* */
136: JasperPrint jasperPrint = JasperFillManager.fillReport(
137: sourceFileName, parameters);
138:
139: JasperExportManager.exportReportToPdfFile(jasperPrint,
140: destFileName);
141: }
142:
143: /**
144: * Fills a report and sends it directly to an OutputStream in PDF format.
145: * The intermediate JasperPrint object is not saved on disk.
146: */
147: public static void runReportToPdfStream(InputStream inputStream,
148: OutputStream outputStream, Map parameters, Connection conn)
149: throws JRException {
150: /* */
151: JasperPrint jasperPrint = JasperFillManager.fillReport(
152: inputStream, parameters, conn);
153:
154: JasperExportManager.exportReportToPdfStream(jasperPrint,
155: outputStream);
156: }
157:
158: /**
159: * Fills a report and sends it directly to an OutputStream in PDF format.
160: * The intermediate JasperPrint object is not saved on disk.
161: *
162: * @param inputStream compiled report input stream
163: * @param outputStream PDF output stream
164: * @param parameters parameters map
165: * @throws JRException
166: * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
167: */
168: public static void runReportToPdfStream(InputStream inputStream,
169: OutputStream outputStream, Map parameters)
170: throws JRException {
171: /* */
172: JasperPrint jasperPrint = JasperFillManager.fillReport(
173: inputStream, parameters);
174:
175: JasperExportManager.exportReportToPdfStream(jasperPrint,
176: outputStream);
177: }
178:
179: /**
180: * Fills a report and returns byte array object containing the report in PDF format.
181: * The intermediate JasperPrint object is not saved on disk.
182: */
183: public static byte[] runReportToPdf(String sourceFileName,
184: Map parameters, Connection conn) throws JRException {
185: /* */
186: JasperPrint jasperPrint = JasperFillManager.fillReport(
187: sourceFileName, parameters, conn);
188:
189: return JasperExportManager.exportReportToPdf(jasperPrint);
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: * @param sourceFileName source file containing the compile report design
197: * @param parameters report parameters map
198: * @return binary PDF output
199: * @throws JRException
200: * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
201: */
202: public static byte[] runReportToPdf(String sourceFileName,
203: Map parameters) throws JRException {
204: /* */
205: JasperPrint jasperPrint = JasperFillManager.fillReport(
206: sourceFileName, parameters);
207:
208: return JasperExportManager.exportReportToPdf(jasperPrint);
209: }
210:
211: /**
212: * Fills a report and returns byte array object containing the report in PDF format.
213: * The intermediate JasperPrint object is not saved on disk.
214: */
215: public static byte[] runReportToPdf(InputStream inputStream,
216: Map parameters, Connection conn) throws JRException {
217: /* */
218: JasperPrint jasperPrint = JasperFillManager.fillReport(
219: inputStream, parameters, conn);
220:
221: return JasperExportManager.exportReportToPdf(jasperPrint);
222: }
223:
224: /**
225: * Fills a report and returns byte array object containing the report in PDF format.
226: * The intermediate JasperPrint object is not saved on disk.
227: *
228: * @param inputStream input stream to read the compiled report design object from
229: * @param parameters report parameters map
230: * @return binary PDF output
231: * @throws JRException
232: * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
233: */
234: public static byte[] runReportToPdf(InputStream inputStream,
235: Map parameters) throws JRException {
236: /* */
237: JasperPrint jasperPrint = JasperFillManager.fillReport(
238: inputStream, parameters);
239:
240: return JasperExportManager.exportReportToPdf(jasperPrint);
241: }
242:
243: /**
244: * Fills a report and returns byte array object containing the report in PDF format.
245: * The intermediate JasperPrint object is not saved on disk.
246: */
247: public static byte[] runReportToPdf(JasperReport jasperReport,
248: Map parameters, Connection conn) throws JRException {
249: /* */
250: JasperPrint jasperPrint = JasperFillManager.fillReport(
251: jasperReport, parameters, conn);
252:
253: return JasperExportManager.exportReportToPdf(jasperPrint);
254: }
255:
256: /**
257: * Fills a report and returns byte array object containing the report in PDF format.
258: * The intermediate JasperPrint object is not saved on disk.
259: *
260: * @param jasperReport the compiled report
261: * @param parameters the parameters map
262: * @return binary PDF output
263: * @throws JRException
264: * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
265: */
266: public static byte[] runReportToPdf(JasperReport jasperReport,
267: Map parameters) throws JRException {
268: /* */
269: JasperPrint jasperPrint = JasperFillManager.fillReport(
270: jasperReport, parameters);
271:
272: return JasperExportManager.exportReportToPdf(jasperPrint);
273: }
274:
275: /**
276: * Fills a report and saves it directly into a PDF file.
277: * The intermediate JasperPrint object is not saved on disk.
278: */
279: public static String runReportToPdfFile(String sourceFileName,
280: Map parameters, JRDataSource jrDataSource)
281: throws JRException {
282: File sourceFile = new File(sourceFileName);
283:
284: /* */
285: JasperReport jasperReport = (JasperReport) JRLoader
286: .loadObject(sourceFile);
287:
288: /* */
289: JasperPrint jasperPrint = JasperFillManager.fillReport(
290: jasperReport, parameters, jrDataSource);
291:
292: /* */
293: File destFile = new File(sourceFile.getParent(), jasperPrint
294: .getName()
295: + ".pdf");
296: String destFileName = destFile.toString();
297:
298: JasperExportManager.exportReportToPdfFile(jasperPrint,
299: destFileName);
300:
301: return destFileName;
302: }
303:
304: /**
305: * Fills a report and saves it directly into a PDF file.
306: * The intermediate JasperPrint object is not saved on disk.
307: */
308: public static void runReportToPdfFile(String sourceFileName,
309: String destFileName, Map parameters,
310: JRDataSource jrDataSource) throws JRException {
311: /* */
312: JasperPrint jasperPrint = JasperFillManager.fillReport(
313: sourceFileName, parameters, jrDataSource);
314:
315: /* */
316: JasperExportManager.exportReportToPdfFile(jasperPrint,
317: destFileName);
318: }
319:
320: /**
321: * Fills a report and sends it directly to an OutputStream in PDF format.
322: * The intermediate JasperPrint object is not saved on disk.
323: */
324: public static void runReportToPdfStream(InputStream inputStream,
325: OutputStream outputStream, Map parameters,
326: JRDataSource jrDataSource) throws JRException {
327: /* */
328: JasperPrint jasperPrint = JasperFillManager.fillReport(
329: inputStream, parameters, jrDataSource);
330:
331: JasperExportManager.exportReportToPdfStream(jasperPrint,
332: outputStream);
333: }
334:
335: /**
336: * Fills a report and sends it to an output stream in PDF format.
337: * The intermediate JasperPrint object is not saved on disk.
338: */
339: public static byte[] runReportToPdf(String sourceFileName,
340: Map parameters, JRDataSource jrDataSource)
341: throws JRException {
342: /* */
343: JasperPrint jasperPrint = JasperFillManager.fillReport(
344: sourceFileName, parameters, jrDataSource);
345:
346: return JasperExportManager.exportReportToPdf(jasperPrint);
347: }
348:
349: /**
350: * Fills a report and returns byte array object containing the report in PDF format.
351: * The intermediate JasperPrint object is not saved on disk.
352: */
353: public static byte[] runReportToPdf(InputStream inputStream,
354: Map parameters, JRDataSource jrDataSource)
355: throws JRException {
356: /* */
357: JasperPrint jasperPrint = JasperFillManager.fillReport(
358: inputStream, parameters, jrDataSource);
359:
360: return JasperExportManager.exportReportToPdf(jasperPrint);
361: }
362:
363: /**
364: * Fills a report and returns byte array object containing the report in PDF format.
365: * The intermediate JasperPrint object is not saved on disk.
366: */
367: public static byte[] runReportToPdf(JasperReport jasperReport,
368: Map parameters, JRDataSource jrDataSource)
369: throws JRException {
370: /* */
371: JasperPrint jasperPrint = JasperFillManager.fillReport(
372: jasperReport, parameters, jrDataSource);
373:
374: return JasperExportManager.exportReportToPdf(jasperPrint);
375: }
376:
377: /**
378: * Fills a report and saves it directly into a HTML file.
379: * The intermediate JasperPrint object is not saved on disk.
380: */
381: public static String runReportToHtmlFile(String sourceFileName,
382: Map parameters, Connection conn) throws JRException {
383: File sourceFile = new File(sourceFileName);
384:
385: /* */
386: JasperReport jasperReport = (JasperReport) JRLoader
387: .loadObject(sourceFile);
388:
389: /* */
390: JasperPrint jasperPrint = JasperFillManager.fillReport(
391: jasperReport, parameters, conn);
392:
393: /* */
394: File destFile = new File(sourceFile.getParent(), jasperPrint
395: .getName()
396: + ".html");
397: String destFileName = destFile.toString();
398:
399: JasperExportManager.exportReportToHtmlFile(jasperPrint,
400: destFileName);
401:
402: return destFileName;
403: }
404:
405: /**
406: * Fills a report and saves it directly into a HTML file.
407: * The intermediate JasperPrint object is not saved on disk.
408: *
409: * @param sourceFileName the name of the compiled report file
410: * @param parameters the parameters map
411: * @return the name of the generated HTML file
412: * @throws JRException
413: * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
414: */
415: public static String runReportToHtmlFile(String sourceFileName,
416: Map parameters) throws JRException {
417: File sourceFile = new File(sourceFileName);
418:
419: /* */
420: JasperReport jasperReport = (JasperReport) JRLoader
421: .loadObject(sourceFile);
422:
423: /* */
424: JasperPrint jasperPrint = JasperFillManager.fillReport(
425: jasperReport, parameters);
426:
427: /* */
428: File destFile = new File(sourceFile.getParent(), jasperPrint
429: .getName()
430: + ".html");
431: String destFileName = destFile.toString();
432:
433: JasperExportManager.exportReportToHtmlFile(jasperPrint,
434: destFileName);
435:
436: return destFileName;
437: }
438:
439: /**
440: * Fills a report and saves it directly into a HTML file.
441: * The intermediate JasperPrint object is not saved on disk.
442: */
443: public static void runReportToHtmlFile(String sourceFileName,
444: String destFileName, Map parameters, Connection conn)
445: throws JRException {
446: /* */
447: JasperPrint jasperPrint = JasperFillManager.fillReport(
448: sourceFileName, parameters, conn);
449:
450: JasperExportManager.exportReportToHtmlFile(jasperPrint,
451: destFileName);
452: }
453:
454: /**
455: * Fills a report and saves it directly into a HTML file.
456: * The intermediate JasperPrint object is not saved on disk.
457: *
458: * @param sourceFileName source file containing the compile report design
459: * @param destFileName name of the destination HTML file
460: * @param parameters report parameters map
461: * @throws JRException
462: * @see net.sf.jasperreports.engine.fill.JRFiller#fillReport(JasperReport, Map)
463: */
464: public static void runReportToHtmlFile(String sourceFileName,
465: String destFileName, Map parameters) throws JRException {
466: /* */
467: JasperPrint jasperPrint = JasperFillManager.fillReport(
468: sourceFileName, parameters);
469:
470: JasperExportManager.exportReportToHtmlFile(jasperPrint,
471: destFileName);
472: }
473:
474: /**
475: * Fills a report and saves it directly into a HTML file.
476: * The intermediate JasperPrint object is not saved on disk.
477: */
478: public static String runReportToHtmlFile(String sourceFileName,
479: Map parameters, JRDataSource jrDataSource)
480: throws JRException {
481: File sourceFile = new File(sourceFileName);
482:
483: /* */
484: JasperReport jasperReport = (JasperReport) JRLoader
485: .loadObject(sourceFile);
486:
487: /* */
488: JasperPrint jasperPrint = JasperFillManager.fillReport(
489: jasperReport, parameters, jrDataSource);
490:
491: /* */
492: File destFile = new File(sourceFile.getParent(), jasperPrint
493: .getName()
494: + ".html");
495: String destFileName = destFile.toString();
496:
497: JasperExportManager.exportReportToHtmlFile(jasperPrint,
498: destFileName);
499:
500: return destFileName;
501: }
502:
503: /**
504: * Fills a report and saves it directly into a HTML file.
505: * The intermediate JasperPrint object is not saved on disk.
506: */
507: public static void runReportToHtmlFile(String sourceFileName,
508: String destFileName, Map parameters,
509: JRDataSource jrDataSource) throws JRException {
510: /* */
511: JasperPrint jasperPrint = JasperFillManager.fillReport(
512: sourceFileName, parameters, jrDataSource);
513:
514: /* */
515: JasperExportManager.exportReportToHtmlFile(jasperPrint,
516: destFileName);
517: }
518:
519: }
|