001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.web.servlet.view.jasperreports;
018:
019: import java.util.HashMap;
020: import java.util.Map;
021: import java.util.Properties;
022:
023: import javax.sql.DataSource;
024:
025: import net.sf.jasperreports.engine.design.JRCompiler;
026:
027: import org.springframework.web.servlet.view.AbstractUrlBasedView;
028: import org.springframework.web.servlet.view.UrlBasedViewResolver;
029:
030: /**
031: * {@link org.springframework.web.servlet.ViewResolver} implementation that
032: * resolves instances of {@link AbstractJasperReportsView} by translating
033: * the supplied view name into the URL of the report file.
034: *
035: * @author Rob Harrop
036: * @since 1.2.6
037: */
038: public class JasperReportsViewResolver extends UrlBasedViewResolver {
039:
040: private String reportDataKey;
041:
042: private Properties subReportUrls;
043:
044: private String[] subReportDataKeys;
045:
046: private Properties headers;
047:
048: private Map exporterParameters = new HashMap();
049:
050: private DataSource jdbcDataSource;
051:
052: private JRCompiler reportCompiler;
053:
054: /**
055: * Requires the view class to be a subclass of {@link AbstractJasperReportsView}.
056: */
057: protected Class requiredViewClass() {
058: return AbstractJasperReportsView.class;
059: }
060:
061: /**
062: * Set the <code>reportDataKey</code> the view class should use.
063: * @see AbstractJasperReportsView#setReportDataKey
064: */
065: public void setReportDataKey(String reportDataKey) {
066: this .reportDataKey = reportDataKey;
067: }
068:
069: /**
070: * Set the <code>subReportUrls</code> the view class should use.
071: * @see AbstractJasperReportsView#setSubReportUrls
072: */
073: public void setSubReportUrls(Properties subReportUrls) {
074: this .subReportUrls = subReportUrls;
075: }
076:
077: /**
078: * Set the <code>subReportDataKeys</code> the view class should use.
079: * @see AbstractJasperReportsView#setSubReportDataKeys
080: */
081: public void setSubReportDataKeys(String[] subReportDataKeys) {
082: this .subReportDataKeys = subReportDataKeys;
083: }
084:
085: /**
086: * Set the <code>headers</code> the view class should use.
087: * @see AbstractJasperReportsView#setHeaders
088: */
089: public void setHeaders(Properties headers) {
090: this .headers = headers;
091: }
092:
093: /**
094: * Set the <code>exporterParameters</code> the view class should use.
095: * @see AbstractJasperReportsView#setExporterParameters
096: */
097: public void setExporterParameters(Map exporterParameters) {
098: this .exporterParameters = exporterParameters;
099: }
100:
101: /**
102: * Set the {@link DataSource} the view class should use.
103: * @see AbstractJasperReportsView#setJdbcDataSource
104: */
105: public void setJdbcDataSource(DataSource jdbcDataSource) {
106: this .jdbcDataSource = jdbcDataSource;
107: }
108:
109: /**
110: * Set the {@link JRCompiler} the view class should use.
111: * @see AbstractJasperReportsView#setReportCompiler
112: */
113: public void setReportCompiler(JRCompiler reportCompiler) {
114: this .reportCompiler = reportCompiler;
115: }
116:
117: protected AbstractUrlBasedView buildView(String viewName)
118: throws Exception {
119: AbstractJasperReportsView view = (AbstractJasperReportsView) super
120: .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: }
|