001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *     http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.gbif.ws.server.provider;
015
016import java.util.Locale;
017
018import org.springframework.core.MethodParameter;
019import org.springframework.web.bind.support.WebDataBinderFactory;
020import org.springframework.web.context.request.NativeWebRequest;
021import org.springframework.web.method.support.HandlerMethodArgumentResolver;
022import org.springframework.web.method.support.ModelAndViewContainer;
023
024public class LocaleHandlerMethodArgumentResolver extends LocaleProvider
025    implements HandlerMethodArgumentResolver {
026
027  @Override
028  public boolean supportsParameter(MethodParameter parameter) {
029    return Locale.class.equals(parameter.getParameterType());
030  }
031
032  @Override
033  public Object resolveArgument(
034      MethodParameter parameter,
035      ModelAndViewContainer mavContainer,
036      NativeWebRequest webRequest,
037      WebDataBinderFactory binderFactory) {
038    return getValue(webRequest);
039  }
040}