Source Code Cross Referenced for RequestContextUtils.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » servlet » support » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.web.servlet.support 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.support;
018:
019:        import java.util.Locale;
020:
021:        import javax.servlet.ServletContext;
022:        import javax.servlet.ServletRequest;
023:        import javax.servlet.http.HttpServletRequest;
024:
025:        import org.springframework.ui.context.Theme;
026:        import org.springframework.ui.context.ThemeSource;
027:        import org.springframework.web.context.WebApplicationContext;
028:        import org.springframework.web.context.support.WebApplicationContextUtils;
029:        import org.springframework.web.servlet.DispatcherServlet;
030:        import org.springframework.web.servlet.LocaleResolver;
031:        import org.springframework.web.servlet.ThemeResolver;
032:
033:        /**
034:         * Utility class for easy access to request-specific state
035:         * which has been set by the DispatcherServlet.
036:         *
037:         * <p>Supports lookup of current WebApplicationContext, LocaleResolver,
038:         * Locale, ThemeResolver, Theme, and MultipartResolver.
039:         *
040:         * @author Juergen Hoeller
041:         * @since 03.03.2003
042:         * @see RequestContext
043:         * @see org.springframework.web.servlet.DispatcherServlet
044:         */
045:        public abstract class RequestContextUtils {
046:
047:            /**
048:             * Look for the WebApplicationContext associated with the DispatcherServlet
049:             * that has initiated request processing.
050:             * @param request current HTTP request
051:             * @return the request-specific web application context
052:             * @throws IllegalStateException if no servlet-specific context has been found
053:             */
054:            public static WebApplicationContext getWebApplicationContext(
055:                    ServletRequest request) throws IllegalStateException {
056:
057:                return getWebApplicationContext(request, null);
058:            }
059:
060:            /**
061:             * Look for the WebApplicationContext associated with the DispatcherServlet
062:             * that has initiated request processing, and for the global context if none
063:             * was found associated with the current request. This method is useful to
064:             * allow components outside the framework, such as JSP tag handlers,
065:             * to access the most specific application context available.
066:             * @param request current HTTP request
067:             * @param servletContext current servlet context
068:             * @return the request-specific WebApplicationContext, or the global one
069:             * if no request-specific context has been found
070:             * @throws IllegalStateException if neither a servlet-specific nor a
071:             * global context has been found
072:             */
073:            public static WebApplicationContext getWebApplicationContext(
074:                    ServletRequest request, ServletContext servletContext)
075:                    throws IllegalStateException {
076:
077:                WebApplicationContext webApplicationContext = (WebApplicationContext) request
078:                        .getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
079:                if (webApplicationContext == null) {
080:                    if (servletContext == null) {
081:                        throw new IllegalStateException(
082:                                "No WebApplicationContext found: not in a DispatcherServlet request?");
083:                    }
084:                    webApplicationContext = WebApplicationContextUtils
085:                            .getWebApplicationContext(servletContext);
086:                    if (webApplicationContext == null) {
087:                        throw new IllegalStateException(
088:                                "No WebApplicationContext found: no ContextLoaderListener registered?");
089:                    }
090:                }
091:                return webApplicationContext;
092:            }
093:
094:            /**
095:             * Return the LocaleResolver that has been bound to the request by the
096:             * DispatcherServlet.
097:             * @param request current HTTP request
098:             * @return the current LocaleResolver, or <code>null</code> if not found
099:             */
100:            public static LocaleResolver getLocaleResolver(
101:                    HttpServletRequest request) {
102:                return (LocaleResolver) request
103:                        .getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE);
104:            }
105:
106:            /**
107:             * Retrieves the current locale from the given request,
108:             * using the LocaleResolver bound to the request by the DispatcherServlet
109:             * (if available), falling back to the request's accept-header Locale.
110:             * @param request current HTTP request
111:             * @return the current locale, either from the LocaleResolver or from
112:             * the plain request
113:             * @see #getLocaleResolver
114:             * @see javax.servlet.http.HttpServletRequest#getLocale()
115:             */
116:            public static Locale getLocale(HttpServletRequest request) {
117:                LocaleResolver localeResolver = getLocaleResolver(request);
118:                if (localeResolver != null) {
119:                    return localeResolver.resolveLocale(request);
120:                } else {
121:                    return request.getLocale();
122:                }
123:            }
124:
125:            /**
126:             * Return the ThemeResolver that has been bound to the request by the
127:             * DispatcherServlet.
128:             * @param request current HTTP request
129:             * @return the current ThemeResolver, or <code>null</code> if not found
130:             */
131:            public static ThemeResolver getThemeResolver(
132:                    HttpServletRequest request) {
133:                return (ThemeResolver) request
134:                        .getAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE);
135:            }
136:
137:            /**
138:             * Return the ThemeSource that has been bound to the request by the
139:             * DispatcherServlet.
140:             * @param request current HTTP request
141:             * @return the current ThemeSource
142:             */
143:            public static ThemeSource getThemeSource(HttpServletRequest request) {
144:                return (ThemeSource) request
145:                        .getAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE);
146:            }
147:
148:            /**
149:             * Retrieves the current theme from the given request, using the ThemeResolver
150:             * and ThemeSource bound to the request by the DispatcherServlet.
151:             * @param request current HTTP request
152:             * @return the current theme, or <code>null</code> if not found
153:             * @see #getThemeResolver
154:             */
155:            public static Theme getTheme(HttpServletRequest request) {
156:                ThemeResolver themeResolver = getThemeResolver(request);
157:                ThemeSource themeSource = getThemeSource(request);
158:                if (themeResolver != null && themeSource != null) {
159:                    String themeName = themeResolver.resolveThemeName(request);
160:                    return themeSource.getTheme(themeName);
161:                } else {
162:                    return null;
163:                }
164:            }
165:
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.