KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > view > jasperreports > JasperReportsViewResolver


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.servlet.view.jasperreports;
18
19 import java.util.HashMap JavaDoc;
20 import java.util.Map JavaDoc;
21 import java.util.Properties JavaDoc;
22
23 import javax.sql.DataSource JavaDoc;
24
25 import net.sf.jasperreports.engine.design.JRCompiler;
26
27 import org.springframework.web.servlet.view.AbstractUrlBasedView;
28 import org.springframework.web.servlet.view.UrlBasedViewResolver;
29
30 /**
31  * {@link org.springframework.web.servlet.ViewResolver} implementation that
32  * resolves instances of {@link AbstractJasperReportsView} by translating
33  * the supplied view name into the URL of the report file.
34  *
35  * @author Rob Harrop
36  * @since 1.2.6
37  */

38 public class JasperReportsViewResolver extends UrlBasedViewResolver {
39
40     private String JavaDoc reportDataKey;
41
42     private Properties JavaDoc subReportUrls;
43
44     private String JavaDoc[] subReportDataKeys;
45
46     private Properties JavaDoc headers;
47
48     private Map JavaDoc exporterParameters = new HashMap JavaDoc();
49
50     private DataSource JavaDoc jdbcDataSource;
51
52     private JRCompiler reportCompiler;
53
54
55     /**
56      * Requires the view class to be a subclass of {@link AbstractJasperReportsView}.
57      */

58     protected Class JavaDoc requiredViewClass() {
59         return AbstractJasperReportsView.class;
60     }
61
62     /**
63      * Set the <code>reportDataKey</code> the view class should use.
64      * @see AbstractJasperReportsView#setReportDataKey
65      */

66     public void setReportDataKey(String JavaDoc reportDataKey) {
67         this.reportDataKey = reportDataKey;
68     }
69
70     /**
71      * Set the <code>subReportUrls</code> the view class should use.
72      * @see AbstractJasperReportsView#setSubReportUrls
73      */

74     public void setSubReportUrls(Properties JavaDoc subReportUrls) {
75         this.subReportUrls = subReportUrls;
76     }
77
78     /**
79      * Set the <code>subReportDataKeys</code> the view class should use.
80      * @see AbstractJasperReportsView#setSubReportDataKeys
81      */

82     public void setSubReportDataKeys(String JavaDoc[] subReportDataKeys) {
83         this.subReportDataKeys = subReportDataKeys;
84     }
85
86     /**
87      * Set the <code>headers</code> the view class should use.
88      * @see AbstractJasperReportsView#setHeaders
89      */

90     public void setHeaders(Properties JavaDoc headers) {
91         this.headers = headers;
92     }
93
94     /**
95      * Set the <code>exporterParameters</code> the view class should use.
96      * @see AbstractJasperReportsView#setExporterParameters
97      */

98     public void setExporterParameters(Map JavaDoc exporterParameters) {
99         this.exporterParameters = exporterParameters;
100     }
101
102     /**
103      * Set the {@link DataSource} the view class should use.
104      * @see AbstractJasperReportsView#setJdbcDataSource
105      */

106     public void setJdbcDataSource(DataSource JavaDoc jdbcDataSource) {
107         this.jdbcDataSource = jdbcDataSource;
108     }
109
110     /**
111      * Set the {@link JRCompiler} the view class should use.
112      * @see AbstractJasperReportsView#setReportCompiler
113      */

114     public void setReportCompiler(JRCompiler reportCompiler) {
115         this.reportCompiler = reportCompiler;
116     }
117
118
119     protected AbstractUrlBasedView buildView(String JavaDoc viewName) throws Exception JavaDoc {
120         AbstractJasperReportsView view = (AbstractJasperReportsView) super.buildView(viewName);
121
122         view.setReportDataKey(this.reportDataKey);
123         view.setSubReportUrls(this.subReportUrls);
124         view.setSubReportDataKeys(this.subReportDataKeys);
125         view.setHeaders(this.headers);
126         view.setExporterParameters(this.exporterParameters);
127         view.setJdbcDataSource(this.jdbcDataSource);
128
129         if (this.reportCompiler != null) {
130             view.setReportCompiler(this.reportCompiler);
131         }
132
133         return view;
134     }
135
136 }
137
Popular Tags