KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > view > JstlView


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;
18
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20
21 import org.springframework.context.MessageSource;
22 import org.springframework.web.servlet.support.JstlUtils;
23
24 /**
25  * Specialization of InternalResourceView for JSTL pages,
26  * i.e. JSP pages that use the JSP Standard Tag Library.
27  *
28  * <p>Exposes JSTL-specific request attributes specifying locale
29  * and resource bundle for JSTL's formatting and message tags,
30  * using Spring's locale and message source.
31  *
32  * <p>Typical usage with InternalResourceViewResolver would look as follows,
33  * from the perspective of the DispatcherServlet context definition:
34  *
35  * <pre>
36  * &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
37  * &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/&gt;
38  * &lt;property name="prefix" value="/WEB-INF/jsp/"/&gt;
39  * &lt;property name="suffix" value=".jsp"/&gt;
40  * &lt;/bean&gt;
41  *
42  * &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"&gt;
43  * &lt;property name="basename" value="messages"/&gt;
44  * &lt;/bean&gt;</pre>
45  *
46  * Every view name returned from a handler will be translated to a JSP
47  * resource (for example: "myView" -> "/WEB-INF/jsp/myView.jsp"), using
48  * this view class to enable explicit JSTL support.
49  *
50  * <p>The specified MessageSource loads messages from "messages.properties" etc
51  * files in the class path. This will automatically be exposed to views as
52  * JSTL localization context, which the JSTL fmt tags (message etc) will use.
53  * Consider using Spring's ReloadableResourceBundleMessageSource instead of
54  * the standard ResourceBundleMessageSource for more sophistication.
55  * Of course, any other Spring components can share the same MessageSource.
56  *
57  * <p>This is a separate class mainly to avoid JSTL dependencies in
58  * InternalResourceView itself. JSTL has not been part of standard
59  * J2EE up until J2EE 1.4, so we can't assume the JSTL API jar to be
60  * available on the class path.
61  *
62  * @author Juergen Hoeller
63  * @since 27.02.2003
64  * @see org.springframework.web.servlet.support.JstlUtils#exposeLocalizationContext
65  * @see InternalResourceViewResolver
66  * @see org.springframework.context.support.ResourceBundleMessageSource
67  * @see org.springframework.context.support.ReloadableResourceBundleMessageSource
68  */

69 public class JstlView extends InternalResourceView {
70
71     private MessageSource jstlAwareMessageSource;
72
73
74     protected void initApplicationContext() {
75         super.initApplicationContext();
76         this.jstlAwareMessageSource =
77                 JstlUtils.getJstlAwareMessageSource(getServletContext(), getApplicationContext());
78     }
79
80     protected void exposeHelpers(HttpServletRequest JavaDoc request) throws Exception JavaDoc {
81         JstlUtils.exposeLocalizationContext(request, this.jstlAwareMessageSource);
82     }
83
84 }
85
Popular Tags