01: /*
02: * Copyright 2002-2006 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.i18n;
18:
19: import java.util.Locale;
20:
21: import javax.servlet.http.HttpServletRequest;
22: import javax.servlet.http.HttpServletResponse;
23:
24: import org.springframework.web.servlet.LocaleResolver;
25:
26: /**
27: * Implementation of LocaleResolver that simply uses the primary locale
28: * specified in the "accept-language" header of the HTTP request (that is,
29: * the locale sent by the client browser, normally that of the client's OS).
30: *
31: * <p>Note: Does not support <code>setLocale</code>, since the accept header
32: * can only be changed through changing the client's locale settings.
33: *
34: * @author Juergen Hoeller
35: * @since 27.02.2003
36: * @see javax.servlet.http.HttpServletRequest#getLocale()
37: */
38: public class AcceptHeaderLocaleResolver implements LocaleResolver {
39:
40: public Locale resolveLocale(HttpServletRequest request) {
41: return request.getLocale();
42: }
43:
44: public void setLocale(HttpServletRequest request,
45: HttpServletResponse response, Locale locale) {
46: throw new UnsupportedOperationException(
47: "Cannot change HTTP accept header - use a different locale resolution strategy");
48: }
49:
50: }
|