1 /*
2  * JasperReports - Free Java Reporting Library.
3  * Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
4  * http://www.jaspersoft.com
5  *
6  * Unless you have purchased a commercial license agreement from Jaspersoft,
7  * the following license terms apply:
8  *
9  * This program is part of JasperReports.
10  *
11  * JasperReports is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * JasperReports is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
23  */

24 package net.sf.jasperreports.engine;
25
26 import java.io.File;
27 import java.io.InputStream;
28 import java.io.OutputStream;
29 import java.sql.Connection;
30 import java.util.Arrays;
31 import java.util.Map;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 import net.sf.jasperreports.annotations.properties.Property;
37 import net.sf.jasperreports.annotations.properties.PropertyScope;
38 import net.sf.jasperreports.engine.fill.JRFiller;
39 import net.sf.jasperreports.engine.fill.JasperReportSource;
40 import net.sf.jasperreports.engine.fill.SimpleJasperReportSource;
41 import net.sf.jasperreports.engine.util.JRLoader;
42 import net.sf.jasperreports.engine.util.JRSaver;
43 import net.sf.jasperreports.properties.PropertyConstants;
44 import net.sf.jasperreports.repo.RepositoryResourceContext;
45 import net.sf.jasperreports.repo.RepositoryUtil;
46 import net.sf.jasperreports.repo.ResourceInfo;
47 import net.sf.jasperreports.repo.SimpleRepositoryResourceContext;
48
49
50 /**
51  * Facade class for filling compiled report designs with data from report data sources, 
52  * in order to produce page-oriented documents, ready-to-print.
53  * <p>
54  * It exposes a variety of methods that receive a report template in the form of an object, file,
55  * or input stream, and also produces a document in various output forms (object, file, or
56  * output stream).
57  * <p>
58  * All methods receive a Map object that should contain the values for the report parameters.
59  * These values are retrieved by the engine using the corresponding report parameter name as the key. 
60  * <p>
61  * There are two types of method signatures with regards to the data source
62  * provided for filling the report:
63  * <ul>
64  * <li>Methods that receive an instance of the {@link net.sf.jasperreports.engine.JRDataSource} interface
65  * and use it directly for retrieving report data;
66  * <li>Methods that receive an instance of the <code>java.sql.Connection</code> interface and retrieve
67  * the report data by executing the report internal SQL query through this JDBC connection and wrapping 
68  * the returned <code>java.sql.ResultSet</code> object inside a {@link net.sf.jasperreports.engine.JRResultSetDataSource}
69  * instance. 
70  * </ul>
71  * 
72  * @see net.sf.jasperreports.engine.JasperReport
73  * @see net.sf.jasperreports.engine.JRDataSource
74  * @see net.sf.jasperreports.engine.fill.JRFiller
75  * @see net.sf.jasperreports.engine.JasperPrint
76  * @author Teodor Danciu (teodord@users.sourceforge.net)
77  */

78 public final class JasperFillManager
79 {
80     
81     private static final Log log = LogFactory.getLog(JasperFillManager.class);
82     
83     /**
84      * Property that determines whether resource paths in subreports, style templates and data adapters 
85      * should be interpreted as relative to the master report location.
86      * <br/>
87      * Starting with version 6.6.0, relative paths in subreports, style templates and data adapters are
88      * resolved as relative to the resource that contains them.
89      * Prior to version 6.6.0, relative paths in subreports, style templates and data adapters were 
90      * resolved as relative to the master report resource.
91      * This property can be set to <code>true</code> to restore the pre 6.6.0 functionality.
92      * <br/>
93      * The default value of the property is <code>false</code>.
94      * <br/>
95      * 
96      * @deprecated The property should only be set when upgrading from a version older than 6.6.0 with a repository
97      * that relied on the fact that paths were relative to the master report.
98      * The property might be removed at some point in the future.
99      */

100     @Property(
101             category = PropertyConstants.CATEGORY_REPOSITORY,
102             defaultValue = PropertyConstants.BOOLEAN_FALSE,
103             scopes = {PropertyScope.CONTEXT, PropertyScope.REPORT},
104             sinceVersion = PropertyConstants.VERSION_6_6_0,
105             valueType = Boolean.class
106             )
107     @Deprecated
108     public static final String PROPERTY_LEGACY_RELATIVE_PATH_ENABLED = JRPropertiesUtil.PROPERTY_PREFIX
109             + "legacy.relative.path.enabled";
110     
111     private final JasperReportsContext jasperReportsContext;
112
113
114     /**
115      *
116      */

117     private JasperFillManager(JasperReportsContext jasperReportsContext)
118     {
119         this.jasperReportsContext = jasperReportsContext;
120     }
121     
122     
123     /**
124      *
125      */

126     private static JasperFillManager getDefaultInstance()
127     {
128         return new JasperFillManager(DefaultJasperReportsContext.getInstance());
129     }
130     
131     
132     /**
133      *
134      */

135     public static JasperFillManager getInstance(JasperReportsContext jasperReportsContext)
136     {
137         return new JasperFillManager(jasperReportsContext);
138     }
139     
140     
141     /**
142      * Fills the compiled report design loaded from the specified file.
143      * The result of this operation is another file that will contain the serialized  
144      * {@link JasperPrint} object representing the generated document,
145      * having the same name as the report design as declared in the source file, 
146      * plus the <code>*.jrprint</code> extension, located in the same directory as the source file. 
147      * 
148      * @param sourceFileName source file containing the compiled report design
149      * @param params     report parameters map
150      * @param connection     JDBC connection object to use for executing the report internal SQL query
151      */

152     public String fillToFile(
153         String sourceFileName, 
154         Map<String,Object> params,
155         Connection connection
156         ) throws JRException
157     {
158         File sourceFile = new File(sourceFileName);
159
160         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
161
162         File destFile = new File(sourceFile.getParent(), jasperReport.getName() + ".jrprint");
163         String destFileName = destFile.toString();
164
165         JasperPrint jasperPrint = JRFiller.fill(jasperReportsContext, 
166                 getReportSource(sourceFile, jasperReport), 
167                 params, connection);
168         
169         JRSaver.saveObject(jasperPrint, destFileName);
170         
171         return destFileName;
172     }
173
174
175     /**
176      * Fills the compiled report design loaded from the specified file.
177      * The result of this operation is another file that will contain the serialized  
178      * {@link JasperPrint} object representing the generated document,
179      * having the same name as the report design as declared in the source file, 
180      * plus the <code>*.jrprint</code> extension, located in the same directory as the source file. 
181      * 
182      * @param sourceFileName source file containing the compiled report design
183      * @param params     report parameters map
184      * @see JRFiller#fill(JasperReportsContext, JasperReport, Map)
185      */

186     public String fillToFile(
187         String sourceFileName, 
188         Map<String,Object> params
189         ) throws JRException
190     {
191         File sourceFile = new File(sourceFileName);
192
193         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
194
195         File destFile = new File(sourceFile.getParent(), jasperReport.getName() + ".jrprint");
196         String destFileName = destFile.toString();
197
198         JasperPrint jasperPrint = JRFiller.fill(jasperReportsContext, 
199                 getReportSource(sourceFile, jasperReport), 
200                 params);
201
202         JRSaver.saveObject(jasperPrint, destFileName);
203
204         return destFileName;
205     }
206
207     
208     /**
209      * Fills the compiled report design loaded from the file received as the first parameter
210      * and places the result in the file specified by the second parameter.
211      * 
212      * @param sourceFileName source file containing the compiled report design
213      * @param destFileName   file name to place the generated report into
214      * @param params     report parameters map
215      * @param connection     JDBC connection object to use for executing the report internal SQL query
216      */

217     public void fillToFile(
218         String sourceFileName, 
219         String destFileName, 
220         Map<String,Object> params,
221         Connection connection
222         ) throws JRException
223     {
224         File sourceFile = new File(sourceFileName);
225
226         JasperPrint jasperPrint = JRFiller.fill(jasperReportsContext, 
227                 getReportSource(sourceFile), 
228                 params, connection);
229         
230         JRSaver.saveObject(jasperPrint, destFileName);
231     }
232
233     
234     /**
235      * Fills the compiled report design loaded from the file received as the first parameter
236      * and places the result in the file specified by the second parameter.
237      * 
238      * @param sourceFileName source file containing the compiled report design
239      * @param destFileName   file name to place the generated report into
240      * @param params     report parameters map
241      * @see JRFiller#fill(JasperReportsContext, JasperReport, Map)
242      */

243     public void fillToFile(
244         String sourceFileName, 
245         String destFileName, 
246         Map<String,Object> params
247         ) throws JRException
248     {
249         File sourceFile = new File(sourceFileName);
250
251         JasperPrint jasperPrint = JRFiller.fill(jasperReportsContext, 
252                 getReportSource(sourceFile), 
253                 params);
254
255         JRSaver.saveObject(jasperPrint, destFileName);
256     }
257
258     
259     /**
260      * Fills the compiled report design received as the first parameter
261      * and places the result in the file specified by the second parameter.
262      * 
263      * @param jasperReport compiled report design object to use for filling
264      * @param destFileName file name to place the generated report into
265      * @param parameters   report parameters map
266      * @param connection   JDBC connection object to use for executing the report internal SQL query
267      */

268     public void fillToFile(
269         JasperReport jasperReport, 
270         String destFileName, 
271         Map<String,Object> parameters,
272         Connection connection
273         ) throws JRException
274     {
275         JasperPrint jasperPrint = fill(jasperReport, parameters, connection);
276
277         JRSaver.saveObject(jasperPrint, destFileName);
278     }
279
280     
281     /**
282      * Fills the compiled report design received as the first parameter
283      * and places the result in the file specified by the second parameter.
284      * 
285      * @param jasperReport compiled report design object to use for filling
286      * @param destFileName file name to place the generated report into
287      * @param parameters   report parameters map
288      * @see JRFiller#fill(JasperReportsContext, JasperReport, Map)
289      */

290     public void fillToFile(
291         JasperReport jasperReport, 
292         String destFileName, 
293         Map<String,Object> parameters
294         ) throws JRException
295     {
296         JasperPrint jasperPrint = fill(jasperReport, parameters);
297
298         JRSaver.saveObject(jasperPrint, destFileName);
299     }
300
301     
302     /**
303      * Fills the compiled report design loaded from the specified file and returns
304      * the generated report object.
305      * 
306      * @param sourceFileName source file containing the compiled report design
307      * @param params     report parameters map
308      * @param connection     JDBC connection object to use for executing the report internal SQL query
309      * @return generated report object
310      */

311     public JasperPrint fill(
312         String sourceFileName, 
313         Map<String,Object> params,
314         Connection connection
315         ) throws JRException
316     {
317         File sourceFile = new File(sourceFileName);
318
319         return JRFiller.fill(jasperReportsContext, 
320                 getReportSource(sourceFile), 
321                 params, connection);
322     }
323
324     
325     /**
326      * Fills the compiled report design loaded from the specified file and returns
327      * the generated report object.
328      * 
329      * @param reportLocation the repository location of the compiled report
330      * @param params     report parameters map
331      * @param connection     JDBC connection object to use for executing the report internal SQL query
332      * @return generated report object
333      */

334     public JasperPrint fillFromRepo(
335         String reportLocation, 
336         Map<String,Object> params,
337         Connection connection
338         ) throws JRException
339     {
340         return JRFiller.fill(jasperReportsContext, 
341                 getReportSource(reportLocation), 
342                 params, connection);
343     }
344
345     
346     /**
347      * Fills the compiled report design loaded from the specified file and returns
348      * the generated report object.
349      * 
350      * @param sourceFileName source file containing the compiled report design
351      * @param params     report parameters map
352      * @return generated report object
353      * @see JRFiller#fill(JasperReportsContext, JasperReport, Map)
354      */

355     public JasperPrint fill(
356         String sourceFileName, 
357         Map<String,Object> params
358         ) throws JRException
359     {
360         File sourceFile = new File(sourceFileName);
361
362         return JRFiller.fill(jasperReportsContext, 
363                 getReportSource(sourceFile), 
364                 params);
365     }
366
367     
368     /**
369      * Fills the compiled report design loaded from the specified file and returns
370      * the generated report object.
371      * 
372      * @param reportLocation the repository location of the compiled report
373      * @param params     report parameters map
374      * @return generated report object
375      * @see JRFiller#fill(JasperReportsContext, JasperReport, Map)
376      */

377     public JasperPrint fillFromRepo(
378         String reportLocation, 
379         Map<String,Object> params
380         ) throws JRException
381     {
382         return JRFiller.fill(jasperReportsContext, 
383                 getReportSource(reportLocation), 
384                 params);
385     }
386
387     
388     /**
389      * Fills the compiled report design loaded from the supplied input stream and writes
390      * the generated report object to the output stream specified by the second parameter.
391      * 
392      * @param inputStream  input stream to read the compiled report design object from
393      * @param outputStream output stream to write the generated report object to
394      * @param parameters   report parameters map
395      * @param connection   JDBC connection object to use for executing the report internal SQL query
396      */

397     public void fillToStream(
398         InputStream inputStream, 
399         OutputStream outputStream, 
400         Map<String,Object> parameters,
401         Connection connection
402         ) throws JRException
403     {
404         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream);
405
406         fillToStream(jasperReport, outputStream, parameters, connection);
407     }
408
409     
410     /**
411      * Fills the compiled report design loaded from the supplied input stream and writes
412      * the generated report object to the output stream specified by the second parameter.
413      * 
414      * @param inputStream  input stream to read the compiled report design object from
415      * @param outputStream output stream to write the generated report object to
416      * @param parameters   report parameters map
417      * @see JRFiller#fill(JasperReportsContext, JasperReport, Map)
418      */

419     public void fillToStream(
420         InputStream inputStream, 
421         OutputStream outputStream, 
422         Map<String,Object> parameters
423         ) throws JRException
424     {
425         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream);
426
427         fillToStream(jasperReport, outputStream, parameters);
428     }
429
430     
431     /**
432      * Fills the compiled report design supplied as the first parameter and writes
433      * the generated report object to the output stream specified by the second parameter.
434      * 
435      * @param jasperReport compiled report design object to use for filling
436      * @param outputStream output stream to write the generated report object to
437      * @param parameters   report parameters map
438      * @param connection   JDBC connection object to use for executing the report internal SQL query
439      */

440     public void fillToStream(
441         JasperReport jasperReport, 
442         OutputStream outputStream, 
443         Map<String,Object> parameters,
444         Connection connection
445         ) throws JRException
446     {
447         JasperPrint jasperPrint = fill(jasperReport, parameters, connection);
448
449         JRSaver.saveObject(jasperPrint, outputStream);
450     }
451
452     
453     /**
454      * Fills the compiled report design supplied as the first parameter and writes
455      * the generated report object to the output stream specified by the second parameter.
456      * 
457      * @param jasperReport compiled report design object to use for filling
458      * @param outputStream output stream to write the generated report object to
459      * @param parameters   report parameters map
460      * @see JRFiller#fill(JasperReportsContext, JasperReport, Map)
461      */

462     public void fillToStream(
463         JasperReport jasperReport, 
464         OutputStream outputStream, 
465         Map<String,Object> parameters
466         ) throws JRException
467     {
468         JasperPrint jasperPrint = fill(jasperReport, parameters);
469
470         JRSaver.saveObject(jasperPrint, outputStream);
471     }
472
473     
474     /**
475      * Fills the compiled report design loaded from the supplied input stream and returns
476      * the generated report object.
477      * 
478      * @param inputStream  input stream to read the compiled report design object from
479      * @param parameters   report parameters map
480      * @param connection   JDBC connection object to use for executing the report internal SQL query
481      * @return generated report object
482      */

483     public JasperPrint fill(
484         InputStream inputStream, 
485         Map<String,Object> parameters,
486         Connection connection
487         ) throws JRException
488     {
489         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream);
490
491         return fill(jasperReport, parameters, connection);
492     }
493
494     
495     /**
496      * Fills the compiled report design loaded from the supplied input stream and returns
497      * the generated report object.
498      * 
499      * @param inputStream  input stream to read the compiled report design object from
500      * @param parameters   report parameters map
501      * @return generated report object
502      * @see JRFiller#fill(JasperReportsContext, JasperReport, Map)
503      */

504     public JasperPrint fill(
505         InputStream inputStream, 
506         Map<String,Object> parameters
507         ) throws JRException
508     {
509         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream);
510
511         return fill(jasperReport, parameters);
512     }
513
514     
515     /**
516      * Fills the compiled report design supplied as the first parameter and returns
517      * the generated report object.
518      * 
519      * @param jasperReport compiled report design object to use for filling
520      * @param parameters   report parameters map
521      * @param connection   JDBC connection object to use for executing the report internal SQL query
522      * @return generated report object
523      */

524     public JasperPrint fill(
525         JasperReport jasperReport, 
526         Map<String,Object> parameters, 
527         Connection connection
528         ) throws JRException
529     {
530         return JRFiller.fill(jasperReportsContext, jasperReport, parameters, connection);
531     }
532
533     
534     /**
535      * Fills the compiled report design supplied as the first parameter and returns
536      * the generated report object.
537      * 
538      * @param jasperReport compiled report design object to use for filling
539      * @param parameters   report parameters map
540      * @return generated report object
541      * @see JRFiller#fill(JasperReportsContext, JasperReport, Map)
542      */

543     public JasperPrint fill(
544         JasperReport jasperReport, 
545         Map<String,Object> parameters 
546         ) throws JRException
547     {
548         return JRFiller.fill(jasperReportsContext, jasperReport, parameters);
549     }
550
551     
552     /**
553      * Fills the compiled report design loaded from the specified file.
554      * The result of this operation is another file that will contain the serialized  
555      * {@link JasperPrint} object representing the generated document,
556      * having the same name as the report design as declared in the source file, 
557      * plus the <code>*.jrprint</code> extension, located in the same directory as the source file. 
558      * 
559      * @param sourceFileName source file containing the compiled report design
560      * @param params     report parameters map
561      * @param dataSource     data source object
562      */

563     public String fillToFile(
564         String sourceFileName, 
565         Map<String,Object> params,
566         JRDataSource dataSource
567         ) throws JRException
568     {
569         File sourceFile = new File(sourceFileName);
570
571         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile);
572
573         File destFile = new File(sourceFile.getParent(), jasperReport.getName() + ".jrprint");
574         String destFileName = destFile.toString();
575
576         JasperPrint jasperPrint = JRFiller.fill(jasperReportsContext, 
577                 getReportSource(sourceFile, jasperReport), 
578                 params, dataSource);
579
580         JRSaver.saveObject(jasperPrint, destFileName);
581         
582         return destFileName;
583     }
584
585     
586     /**
587      * Fills the compiled report design loaded from the file received as the first parameter
588      * and places the result in the file specified by the second parameter.
589      * 
590      * @param sourceFileName source file containing the compiled report design
591      * @param destFileName   file name to place the generated report into
592      * @param params     report parameters map
593      * @param dataSource     data source object
594      */

595     public void fillToFile(
596         String sourceFileName, 
597         String destFileName, 
598         Map<String,Object> params,
599         JRDataSource dataSource
600         ) throws JRException
601     {
602         File sourceFile = new File(sourceFileName);
603
604         JasperPrint jasperPrint = JRFiller.fill(jasperReportsContext, 
605                 getReportSource(sourceFile), 
606                 params, dataSource);
607
608         JRSaver.saveObject(jasperPrint, destFileName);
609     }
610
611     
612     /**
613      * Fills the compiled report design received as the first parameter
614      * and places the result in the file specified by the second parameter.
615      * 
616      * @param jasperReport compiled report design object to use for filling
617      * @param destFileName file name to place the generated report into
618      * @param parameters   report parameters map
619      * @param dataSource   data source object
620      */

621     public void fillToFile(
622         JasperReport jasperReport, 
623         String destFileName, 
624         Map<String,Object> parameters,
625         JRDataSource dataSource
626         ) throws JRException
627     {
628         JasperPrint jasperPrint = fill(jasperReport, parameters, dataSource);
629
630         JRSaver.saveObject(jasperPrint, destFileName);
631     }
632
633     
634     /**
635      * Fills the compiled report design loaded from the specified file and returns
636      * the generated report object.
637      * 
638      * @param sourceFileName source file containing the compiled report design
639      * @param params     report parameters map
640      * @param dataSource     data source object
641      * @return generated report object
642      */

643     public JasperPrint fill(
644         String sourceFileName, 
645         Map<String,Object> params,
646         JRDataSource dataSource
647         ) throws JRException
648     {
649         File sourceFile = new File(sourceFileName);
650
651         return JRFiller.fill(jasperReportsContext, 
652                 getReportSource(sourceFile), 
653                 params, dataSource);
654     }
655
656     
657     /**
658      * Fills the compiled report design loaded from the specified file and returns
659      * the generated report object.
660      * 
661      * @param reportLocation the repository location of the compiled report
662      * @param params     report parameters map
663      * @param dataSource     data source object
664      * @return generated report object
665      */

666     public JasperPrint fillFromRepo(
667         String reportLocation, 
668         Map<String,Object> params,
669         JRDataSource dataSource
670         ) throws JRException
671     {
672         return JRFiller.fill(jasperReportsContext, 
673                 getReportSource(reportLocation), 
674                 params, dataSource);
675     }
676
677     
678     /**
679      * Fills the compiled report design loaded from the supplied input stream and writes
680      * the generated report object to the output stream specified by the second parameter.
681      * 
682      * @param inputStream  input stream to read the compiled report design object from
683      * @param outputStream output stream to write the generated report object to
684      * @param parameters   report parameters map
685      * @param dataSource   data source object
686      */

687     public void fillToStream(
688         InputStream inputStream, 
689         OutputStream outputStream, 
690         Map<String,Object> parameters,
691         JRDataSource dataSource
692         ) throws JRException
693     {
694         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream);
695
696         fillToStream(jasperReport, outputStream, parameters, dataSource);
697     }
698
699     
700     /**
701      * Fills the compiled report design supplied as the first parameter and writes
702      * the generated report object to the output stream specified by the second parameter.
703      * 
704      * @param jasperReport compiled report design object to use for filling
705      * @param outputStream output stream to write the generated report object to
706      * @param parameters   report parameters map
707      * @param dataSource   data source object
708      */

709     public void fillToStream(
710         JasperReport jasperReport, 
711         OutputStream outputStream, 
712         Map<String,Object> parameters,
713         JRDataSource dataSource
714         ) throws JRException
715     {
716         JasperPrint jasperPrint = fill(jasperReport, parameters, dataSource);
717
718         JRSaver.saveObject(jasperPrint, outputStream);
719     }
720
721     
722     /**
723      * Fills the compiled report design loaded from the supplied input stream and returns
724      * the generated report object.
725      * 
726      * @param inputStream  input stream to read the compiled report design object from
727      * @param parameters   report parameters map
728      * @param dataSource   data source object
729      * @return generated report object
730      */

731     public JasperPrint fill(
732         InputStream inputStream, 
733         Map<String,Object> parameters,
734         JRDataSource dataSource
735         ) throws JRException
736     {
737         JasperReport jasperReport = (JasperReport)JRLoader.loadObject(inputStream);
738
739         return fill(jasperReport, parameters, dataSource);
740     }
741
742     
743     /**
744      * Fills the compiled report design supplied as the first parameter and returns
745      * the generated report object.
746      * 
747      * @param jasperReport compiled report design object to use for filling
748      * @param parameters   report parameters map
749      * @param dataSource   data source object
750      * @return generated report object
751      */

752     public JasperPrint fill(
753         JasperReport jasperReport, 
754         Map<String,Object> parameters, 
755         JRDataSource dataSource
756         ) throws JRException
757     {
758         return JRFiller.fill(jasperReportsContext, jasperReport, parameters, dataSource);
759     }
760     
761     
762     /**
763      * @see #fillToFile(String, Map, Connection)
764      */

765     public static String fillReportToFile(
766         String sourceFileName, 
767         Map<String,Object> params,
768         Connection connection
769         ) throws JRException
770     {
771         return getDefaultInstance().fillToFile(sourceFileName, params, connection);
772     }
773
774
775     /**
776      * @see #fillToFile(String, Map)
777      */

778     public static String fillReportToFile(
779         String sourceFileName, 
780         Map<String,Object> params
781         ) throws JRException
782     {
783         return getDefaultInstance().fillToFile(sourceFileName, params);
784     }
785
786     
787     /**
788      * @see #fillToFile(String, String, Map, Connection)
789      */

790     public static void fillReportToFile(
791         String sourceFileName, 
792         String destFileName, 
793         Map<String,Object> params,
794         Connection connection
795         ) throws JRException
796     {
797         getDefaultInstance().fillToFile(sourceFileName, destFileName, params, connection);
798     }
799
800     
801     /**
802      * @see #fillToFile(String, String, Map)
803      */

804     public static void fillReportToFile(
805         String sourceFileName, 
806         String destFileName, 
807         Map<String,Object> params
808         ) throws JRException
809     {
810         getDefaultInstance().fillToFile(sourceFileName, destFileName, params);
811     }
812
813     
814     /**
815      * @see #fillToFile(JasperReport, String, Map, Connection)
816      */

817     public static void fillReportToFile(
818         JasperReport jasperReport, 
819         String destFileName, 
820         Map<String,Object> parameters,
821         Connection connection
822         ) throws JRException
823     {
824         getDefaultInstance().fillToFile(jasperReport, destFileName, parameters, connection);
825     }
826
827     
828     /**
829      * @see #fillToFile(JasperReport, String, Map)
830      */

831     public static void fillReportToFile(
832         JasperReport jasperReport, 
833         String destFileName, 
834         Map<String,Object> parameters
835         ) throws JRException
836     {
837         getDefaultInstance().fillToFile(jasperReport, destFileName, parameters);
838     }
839
840     
841     /**
842      * @see #fill(String, Map, Connection)
843      */

844     public static JasperPrint fillReport(
845         String sourceFileName, 
846         Map<String,Object> params,
847         Connection connection
848         ) throws JRException
849     {
850         return getDefaultInstance().fill(sourceFileName, params, connection);
851     }
852
853     
854     /**
855      * @see #fill(String, Map)
856      */

857     public static JasperPrint fillReport(
858         String sourceFileName, 
859         Map<String,Object> params
860         ) throws JRException
861     {
862         return getDefaultInstance().fill(sourceFileName, params);
863     }
864
865     
866     /**
867      * @see #fillToStream(InputStream, OutputStream, Map, Connection)
868      */

869     public static void fillReportToStream(
870         InputStream inputStream, 
871         OutputStream outputStream, 
872         Map<String,Object> parameters,
873         Connection connection
874         ) throws JRException
875     {
876         getDefaultInstance().fillToStream(inputStream, outputStream, parameters, connection);
877     }
878
879     
880     /**
881      * @see #fillToStream(InputStream, OutputStream, Map)
882      */

883     public static void fillReportToStream(
884         InputStream inputStream, 
885         OutputStream outputStream, 
886         Map<String,Object> parameters
887         ) throws JRException
888     {
889         getDefaultInstance().fillToStream(inputStream, outputStream, parameters);
890     }
891
892     
893     /**
894      * @see #fillToStream(JasperReport, OutputStream, Map, Connection)
895      */

896     public static void fillReportToStream(
897         JasperReport jasperReport, 
898         OutputStream outputStream, 
899         Map<String,Object> parameters,
900         Connection connection
901         ) throws JRException
902     {
903         getDefaultInstance().fillToStream(jasperReport, outputStream, parameters, connection);
904     }
905
906     
907     /**
908      * @see #fillToStream(JasperReport, OutputStream, Map)
909      */

910     public static void fillReportToStream(
911         JasperReport jasperReport, 
912         OutputStream outputStream, 
913         Map<String,Object> parameters
914         ) throws JRException
915     {
916         getDefaultInstance().fillToStream(jasperReport, outputStream, parameters);
917     }
918
919     
920     /**
921      * @see #fill(InputStream, Map, Connection)
922      */

923     public static JasperPrint fillReport(
924         InputStream inputStream, 
925         Map<String,Object> parameters,
926         Connection connection
927         ) throws JRException
928     {
929         return getDefaultInstance().fill(inputStream, parameters, connection);
930     }
931
932     
933     /**
934      * @see #fill(InputStream, Map)
935      */

936     public static JasperPrint fillReport(
937         InputStream inputStream, 
938         Map<String,Object> parameters
939         ) throws JRException
940     {
941         return getDefaultInstance().fill(inputStream, parameters);
942     }
943
944     
945     /**
946      * @see #fill(JasperReport, Map, Connection)
947      */

948     public static JasperPrint fillReport(
949         JasperReport jasperReport, 
950         Map<String,Object> parameters, 
951         Connection connection
952         ) throws JRException
953     {
954         return getDefaultInstance().fill(jasperReport, parameters, connection);
955     }
956
957     
958     /**
959      * @see #fill(JasperReport, Map)
960      */

961     public static JasperPrint fillReport(
962         JasperReport jasperReport, 
963         Map<String,Object> parameters 
964         ) throws JRException
965     {
966         return getDefaultInstance().fill(jasperReport, parameters);
967     }
968
969     
970     /**
971      * @see #fillToFile(String, Map, JRDataSource)
972      */

973     public static String fillReportToFile(
974         String sourceFileName, 
975         Map<String,Object> params,
976         JRDataSource dataSource
977         ) throws JRException
978     {
979         return getDefaultInstance().fillToFile(sourceFileName, params, dataSource);
980     }
981
982     
983     /**
984      * @see #fillToFile(String, String, Map, JRDataSource)
985      */

986     public static void fillReportToFile(
987         String sourceFileName, 
988         String destFileName, 
989         Map<String,Object> params,
990         JRDataSource dataSource
991         ) throws JRException
992     {
993         getDefaultInstance().fillToFile(sourceFileName, destFileName, params, dataSource);
994     }
995
996     
997     /**
998      * @see #fillToFile(JasperReport, String, Map, JRDataSource)
999      */

1000     public static void fillReportToFile(
1001         JasperReport jasperReport, 
1002         String destFileName, 
1003         Map<String,Object> parameters,
1004         JRDataSource dataSource
1005         ) throws JRException
1006     {
1007         getDefaultInstance().fillToFile(jasperReport, destFileName, parameters, dataSource);
1008     }
1009
1010     
1011     /**
1012      * @see #fill(String, Map, JRDataSource)
1013      */

1014     public static JasperPrint fillReport(
1015         String sourceFileName, 
1016         Map<String,Object> params,
1017         JRDataSource dataSource
1018         ) throws JRException
1019     {
1020         return getDefaultInstance().fill(sourceFileName, params, dataSource);
1021     }
1022
1023     
1024     /**
1025      * @see #fillToStream(InputStream, OutputStream, Map, JRDataSource)
1026      */

1027     public static void fillReportToStream(
1028         InputStream inputStream, 
1029         OutputStream outputStream, 
1030         Map<String,Object> parameters,
1031         JRDataSource dataSource
1032         ) throws JRException
1033     {
1034         getDefaultInstance().fillToStream(inputStream, outputStream, parameters, dataSource);
1035     }
1036
1037     
1038     /**
1039      * @see #fillToStream(JasperReport, OutputStream, Map, JRDataSource)
1040      */

1041     public static void fillReportToStream(
1042         JasperReport jasperReport, 
1043         OutputStream outputStream, 
1044         Map<String,Object> parameters,
1045         JRDataSource dataSource
1046         ) throws JRException
1047     {
1048         getDefaultInstance().fillToStream(jasperReport, outputStream, parameters, dataSource);
1049     }
1050
1051     
1052     /**
1053      * @see #fill(InputStream, Map, JRDataSource)
1054      */

1055     public static JasperPrint fillReport(
1056         InputStream inputStream, 
1057         Map<String,Object> parameters,
1058         JRDataSource dataSource
1059         ) throws JRException
1060     {
1061         return getDefaultInstance().fill(inputStream, parameters, dataSource);
1062     }
1063
1064     
1065     /**
1066      * @see #fill(JasperReport, Map, JRDataSource)
1067      */

1068     public static JasperPrint fillReport(
1069         JasperReport jasperReport, 
1070         Map<String,Object> parameters, 
1071         JRDataSource dataSource
1072         ) throws JRException
1073     {
1074         return getDefaultInstance().fill(jasperReport, parameters, dataSource);
1075     }
1076
1077
1078     /**
1079      * @deprecated replaced by {@link JasperReportSource}
1080      */

1081     @Deprecated
1082     protected JasperReportsContext getLocalJasperReportsContext(File file)
1083     {
1084         net.sf.jasperreports.engine.util.SimpleFileResolver fileResolver =
1085             new net.sf.jasperreports.engine.util.SimpleFileResolver(
1086                 Arrays.asList(new File[]{file.getParentFile(), new File(".")})
1087                 );
1088         fileResolver.setResolveAbsolutePath(true);
1089         
1090         net.sf.jasperreports.engine.util.LocalJasperReportsContext localJasperReportsContext = 
1091             new net.sf.jasperreports.engine.util.LocalJasperReportsContext(jasperReportsContext);
1092         localJasperReportsContext.setFileResolver(fileResolver);
1093         return localJasperReportsContext;
1094     }
1095     
1096     protected static JasperReportSource getReportSource(JasperReportsContext jasperReportsContext, 
1097             File reportFile) throws JRException
1098     {
1099         JasperFillManager manager = getInstance(jasperReportsContext);
1100         return manager.getReportSource(reportFile);
1101     }
1102     
1103     protected JasperReportSource getReportSource(File reportFile) throws JRException
1104     {
1105         JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportFile);
1106         return getReportSource(reportFile, jasperReport);
1107     }
1108
1109     protected JasperReportSource getReportSource(File reportFile, JasperReport jasperReport)
1110     {
1111         //attempting resolve absolute paths as relative, that's what SimpleFileResolver(".") did
1112         RepositoryResourceContext fallbackContext = SimpleRepositoryResourceContext.of(".");
1113         SimpleRepositoryResourceContext reportContext = SimpleRepositoryResourceContext.of(
1114                 reportFile.getParent(), fallbackContext);
1115         
1116         boolean legacyRelativePath = JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(jasperReport, 
1117                 PROPERTY_LEGACY_RELATIVE_PATH_ENABLED, false);
1118         if (legacyRelativePath)
1119         {
1120             //attempt to resolve paths as relative to the master report for backward compatibility
1121             reportContext.setSelfAsDerivedFallback(true);
1122         }
1123         
1124         return SimpleJasperReportSource.from(jasperReport, reportFile.getPath(), reportContext);
1125     }
1126     
1127     protected JasperReportSource getReportSource(String location) throws JRException
1128     {
1129         RepositoryUtil repository = RepositoryUtil.getInstance(jasperReportsContext);
1130         ResourceInfo resourceInfo = repository.getResourceInfo(location);
1131         JasperReportSource source;
1132         if (resourceInfo == null)
1133         {
1134             JasperReport report = repository.getReport(null, location);
1135             source = SimpleJasperReportSource.from(report, location, null);
1136         }
1137         else
1138         {
1139             String reportLocation = resourceInfo.getRepositoryResourceLocation();
1140             String contextLocation = resourceInfo.getRepositoryContextLocation();
1141             if (log.isDebugEnabled())
1142             {
1143                 log.debug("report location " + location + " resolved to " + reportLocation
1144                         + ", context " + contextLocation);
1145             }
1146             
1147             JasperReport report = repository.getReport(null, reportLocation);
1148             source = SimpleJasperReportSource.from(report, reportLocation, 
1149                     SimpleRepositoryResourceContext.of(contextLocation));
1150         }
1151         return source;
1152     }
1153 }
1154