1
24 package net.sf.jasperreports.engine.fill;
25
26 import java.sql.Connection;
27 import java.util.Locale;
28 import java.util.Map;
29 import java.util.TimeZone;
30
31 import net.sf.jasperreports.annotations.properties.Property;
32 import net.sf.jasperreports.annotations.properties.PropertyScope;
33 import net.sf.jasperreports.engine.JRDataSource;
34 import net.sf.jasperreports.engine.JRException;
35 import net.sf.jasperreports.engine.JRParameter;
36 import net.sf.jasperreports.engine.JRPropertiesUtil;
37 import net.sf.jasperreports.engine.JRRuntimeException;
38 import net.sf.jasperreports.engine.JasperPrint;
39 import net.sf.jasperreports.engine.JasperReport;
40 import net.sf.jasperreports.engine.JasperReportsContext;
41 import net.sf.jasperreports.engine.type.SectionTypeEnum;
42 import net.sf.jasperreports.properties.PropertyConstants;
43
44
45
48 public final class JRFiller
49 {
50
51 public static final String EXCEPTION_MESSAGE_KEY_THREAD_INTERRUPTED = "fill.common.filler.thread.interrupted";
52 public static final String EXCEPTION_MESSAGE_KEY_UNKNOWN_REPORT_SECTION_TYPE = "fill.common.filler.unknown.report.section.type";
53
54
64 @Property(
65 category = PropertyConstants.CATEGORY_FILL,
66 valueType = Locale.class,
67 defaultValue = "system locale",
68 scopes = {PropertyScope.CONTEXT, PropertyScope.REPORT},
69 sinceVersion = PropertyConstants.VERSION_5_2_0
70 )
71 public static final String PROPERTY_DEFAULT_LOCALE = JRPropertiesUtil.PROPERTY_PREFIX + "default.locale";
72
73
74
84 @Property(
85 category = PropertyConstants.CATEGORY_FILL,
86 valueType = TimeZone.class,
87 defaultValue = "system time zone",
88 scopes = {PropertyScope.CONTEXT, PropertyScope.REPORT},
89 sinceVersion = PropertyConstants.VERSION_5_2_0
90 )
91 public static final String PROPERTY_DEFAULT_TIMEZONE = JRPropertiesUtil.PROPERTY_PREFIX + "default.timezone";
92
93
96 public static JasperPrint fill(
97 JasperReportsContext jasperReportsContext,
98 JasperReport jasperReport,
99 Map<String,Object> parameters,
100 Connection conn
101 ) throws JRException
102 {
103 return fill(jasperReportsContext, SimpleJasperReportSource.from(jasperReport),
104 parameters, conn);
105 }
106
107 public static JasperPrint fill(
108 JasperReportsContext jasperReportsContext,
109 JasperReportSource reportSource,
110 Map<String,Object> parameters,
111 Connection conn
112 ) throws JRException
113 {
114 ReportFiller filler = createReportFiller(jasperReportsContext, reportSource);
115
116 JasperPrint jasperPrint = null;
117
118 try
119 {
120 jasperPrint = filler.fill(parameters, conn);
121 }
122 catch(JRFillInterruptedException e)
123 {
124 throw
125 new JRException(
126 EXCEPTION_MESSAGE_KEY_THREAD_INTERRUPTED,
127 null,
128 e);
129 }
130
131 return jasperPrint;
132 }
133
134
135
138 public static JasperPrint fill(
139 JasperReportsContext jasperReportsContext,
140 JasperReport jasperReport,
141 Map<String,Object> parameters,
142 JRDataSource dataSource
143 ) throws JRException
144 {
145 return fill(jasperReportsContext, SimpleJasperReportSource.from(jasperReport),
146 parameters, dataSource);
147 }
148
149 public static JasperPrint fill(
150 JasperReportsContext jasperReportsContext,
151 JasperReportSource reportSource,
152 Map<String,Object> parameters,
153 JRDataSource dataSource
154 ) throws JRException
155 {
156 ReportFiller filler = createReportFiller(jasperReportsContext, reportSource);
157
158 JasperPrint jasperPrint = null;
159
160 try
161 {
162 jasperPrint = filler.fill(parameters, dataSource);
163 }
164 catch(JRFillInterruptedException e)
165 {
166 throw
167 new JRException(
168 EXCEPTION_MESSAGE_KEY_THREAD_INTERRUPTED,
169 null,
170 e);
171 }
172
173 return jasperPrint;
174 }
175
176
177
194 public static JasperPrint fill(
195 JasperReportsContext jasperReportsContext,
196 JasperReport jasperReport,
197 Map<String,Object> parameters
198 ) throws JRException
199 {
200 return fill(jasperReportsContext, SimpleJasperReportSource.from(jasperReport),
201 parameters);
202 }
203
204 public static JasperPrint fill(
205 JasperReportsContext jasperReportsContext,
206 JasperReportSource reportSource,
207 Map<String,Object> parameters
208 ) throws JRException
209 {
210 ReportFiller filler = createReportFiller(jasperReportsContext, reportSource);
211
212 try
213 {
214 JasperPrint jasperPrint = filler.fill(parameters);
215
216 return jasperPrint;
217 }
218 catch (JRFillInterruptedException e)
219 {
220 throw
221 new JRException(
222 EXCEPTION_MESSAGE_KEY_THREAD_INTERRUPTED,
223 null,
224 e);
225 }
226 }
227
228
229
232
233 public static JRBaseFiller createFiller(JasperReportsContext jasperReportsContext, JasperReport jasperReport) throws JRException
234 {
235 return createBandReportFiller(jasperReportsContext, SimpleJasperReportSource.from(jasperReport));
236 }
237
238 protected static JRBaseFiller createBandReportFiller(JasperReportsContext jasperReportsContext, JasperReportSource reportSource) throws JRException
239 {
240 JRBaseFiller filler = null;
241
242 switch (reportSource.getReport().getPrintOrderValue())
243 {
244 case HORIZONTAL :
245 {
246 filler = new JRHorizontalFiller(jasperReportsContext, reportSource, null);
247 break;
248 }
249 case VERTICAL :
250 {
251 filler = new JRVerticalFiller(jasperReportsContext, reportSource, null);
252 break;
253 }
254 }
255 return filler;
256 }
257
258 public static ReportFiller createReportFiller(JasperReportsContext jasperReportsContext, JasperReport jasperReport) throws JRException
259 {
260 return createReportFiller(jasperReportsContext, SimpleJasperReportSource.from(jasperReport));
261 }
262
263 public static ReportFiller createReportFiller(JasperReportsContext jasperReportsContext,
264 JasperReportSource reportSource) throws JRException
265 {
266 ReportFiller filler;
267 SectionTypeEnum sectionType = reportSource.getReport().getSectionType();
268 sectionType = sectionType == null ? SectionTypeEnum.BAND : sectionType;
269 switch (sectionType)
270 {
271 case BAND:
272 filler = createBandReportFiller(jasperReportsContext, reportSource);
273 break;
274 case PART:
275 {
276 filler = new PartReportFiller(jasperReportsContext, reportSource, null);
277 break;
278 }
279 default:
280 throw
281 new JRRuntimeException(
282 EXCEPTION_MESSAGE_KEY_UNKNOWN_REPORT_SECTION_TYPE,
283 new Object[]{reportSource.getReport().getSectionType()}
284 );
285 }
286 return filler;
287 }
288
289
290 private JRFiller()
291 {
292 }
293 }
294