01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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: * <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
37: * <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
38: * <property name="prefix" value="/WEB-INF/jsp/"/>
39: * <property name="suffix" value=".jsp"/>
40: * </bean>
41: *
42: * <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
43: * <property name="basename" value="messages"/>
44: * </bean></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: protected void initApplicationContext() {
74: super .initApplicationContext();
75: this .jstlAwareMessageSource = JstlUtils
76: .getJstlAwareMessageSource(getServletContext(),
77: getApplicationContext());
78: }
79:
80: protected void exposeHelpers(HttpServletRequest request)
81: throws Exception {
82: JstlUtils.exposeLocalizationContext(request,
83: this.jstlAwareMessageSource);
84: }
85:
86: }
|