KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > i18n > AcceptHeaderLocaleResolver


1 /*
2  * Copyright 2002-2006 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.i18n;
18
19 import java.util.Locale JavaDoc;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
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 JavaDoc resolveLocale(HttpServletRequest JavaDoc request) {
41         return request.getLocale();
42     }
43
44     public void setLocale(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Locale JavaDoc locale) {
45         throw new UnsupportedOperationException JavaDoc(
46                 "Cannot change HTTP accept header - use a different locale resolution strategy");
47     }
48     
49 }
50
Popular Tags