KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > view > xslt > XsltViewResolver


1 /*
2  * Copyright 2002-2006 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.xslt;
18
19 import org.springframework.util.Assert;
20 import org.springframework.util.xml.SimpleTransformErrorListener;
21 import org.springframework.web.servlet.view.AbstractUrlBasedView;
22 import org.springframework.web.servlet.view.UrlBasedViewResolver;
23
24 import javax.xml.transform.ErrorListener JavaDoc;
25 import javax.xml.transform.URIResolver JavaDoc;
26 import java.util.Properties JavaDoc;
27
28 /**
29  * {@link org.springframework.web.servlet.ViewResolver} implementation that
30  * resolves instances of {@link XsltView} by translating the supplied view name into
31  * the URL of the XSLT stylesheet.
32  *
33  * @author Rob Harrop
34  * @since 2.0
35  */

36 public class XsltViewResolver extends UrlBasedViewResolver {
37
38     private ErrorListener errorListener = new SimpleTransformErrorListener(logger);
39
40     private URIResolver JavaDoc uriResolver;
41
42     private boolean cacheTemplates = true;
43
44     private String JavaDoc sourceKey;
45
46     private Properties JavaDoc outputProperties;
47
48     private boolean indent = true;
49
50     public XsltViewResolver() {
51         setViewClass(XsltView.class);
52     }
53
54     /**
55      * @see XsltView#setCacheTemplates
56      */

57     public void setCacheTemplates(boolean cacheTemplates) {
58         this.cacheTemplates = cacheTemplates;
59     }
60
61     /**
62      * @see XsltView#setUriResolver
63      */

64     public void setUriResolver(URIResolver JavaDoc uriResolver) {
65         this.uriResolver = uriResolver;
66     }
67
68     /**
69      * @see XsltView#setErrorListener
70      */

71     public void setErrorListener(ErrorListener errorListener) {
72         Assert.notNull(errorListener, "'errorListener' cannot be null.");
73         this.errorListener = errorListener;
74     }
75
76     /**
77      * @see XsltView#setSourceKey
78      */

79     public void setSourceKey(String JavaDoc sourceKey) {
80         this.sourceKey = sourceKey;
81     }
82
83     /**
84      * @see XsltView#setOutputProperties
85      */

86     public void setOutputProperties(Properties JavaDoc outputProperties) {
87         this.outputProperties = outputProperties;
88     }
89
90     /**
91      * @see XsltView#setIndent(boolean)
92      */

93     public void setIndent(boolean indent) {
94         this.indent = indent;
95     }
96
97     protected Class JavaDoc requiredViewClass() {
98         return XsltView.class;
99     }
100
101     protected AbstractUrlBasedView buildView(String JavaDoc viewName) throws Exception JavaDoc {
102         XsltView view = (XsltView) super.buildView(viewName);
103         view.setUriResolver(this.uriResolver);
104         view.setErrorListener(this.errorListener);
105         view.setSourceKey(this.sourceKey);
106         view.setOutputProperties(this.outputProperties);
107         view.setIndent(this.indent);
108         return view;
109     }
110 }
111
Popular Tags