001/* 002 * Copyright 2002-2010 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 * https://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 017package org.springframework.web.servlet.handler; 018 019import java.util.Locale; 020 021import javax.servlet.http.HttpServletRequest; 022import javax.servlet.http.HttpServletResponse; 023 024import org.springframework.web.context.request.ServletWebRequest; 025import org.springframework.web.servlet.support.RequestContextUtils; 026 027/** 028 * {@link ServletWebRequest} subclass that is aware of 029 * {@link org.springframework.web.servlet.DispatcherServlet}'s 030 * request context, such as the Locale determined by the configured 031 * {@link org.springframework.web.servlet.LocaleResolver}. 032 * 033 * @author Juergen Hoeller 034 * @since 2.0 035 * @see #getLocale() 036 * @see org.springframework.web.servlet.LocaleResolver 037 */ 038public class DispatcherServletWebRequest extends ServletWebRequest { 039 040 /** 041 * Create a new DispatcherServletWebRequest instance for the given request. 042 * @param request current HTTP request 043 */ 044 public DispatcherServletWebRequest(HttpServletRequest request) { 045 super(request); 046 } 047 048 /** 049 * Create a new DispatcherServletWebRequest instance for the given request and response. 050 * @param request current HTTP request 051 * @param response current HTTP response 052 */ 053 public DispatcherServletWebRequest(HttpServletRequest request, HttpServletResponse response) { 054 super(request, response); 055 } 056 057 @Override 058 public Locale getLocale() { 059 return RequestContextUtils.getLocale(getRequest()); 060 } 061 062}