1. /*
  2. * Copyright 2002-2004 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. package org.springframework.web.servlet.i18n;
  17. import java.util.Locale;
  18. import javax.servlet.http.HttpServletRequest;
  19. import javax.servlet.http.HttpServletResponse;
  20. import org.springframework.web.servlet.LocaleResolver;
  21. /**
  22. * Implementation of LocaleResolver that simply uses the primary locale
  23. * specified in the "accept-language" header of the HTTP request
  24. * (i.e., the locale sent by the client browser, normally that of the client's OS).
  25. *
  26. * <p>Note: Does not support setLocale, because the accept header cannot be changed.
  27. *
  28. * @author Juergen Hoeller
  29. * @since 27.02.2003
  30. */
  31. public class AcceptHeaderLocaleResolver implements LocaleResolver {
  32. public Locale resolveLocale(HttpServletRequest request) {
  33. return request.getLocale();
  34. }
  35. public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
  36. throw new IllegalArgumentException("Cannot change HTTP accept header - use a different locale resolution strategy");
  37. }
  38. }