001/* 002 * Copyright 2002-2009 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.view.tiles2; 018 019import java.util.Locale; 020import javax.servlet.http.HttpServletRequest; 021import javax.servlet.jsp.PageContext; 022 023import org.apache.tiles.context.TilesRequestContext; 024import org.apache.tiles.jsp.context.JspTilesRequestContext; 025import org.apache.tiles.locale.impl.DefaultLocaleResolver; 026import org.apache.tiles.servlet.context.ServletTilesRequestContext; 027 028import org.springframework.web.servlet.support.RequestContextUtils; 029 030/** 031 * Tiles LocaleResolver adapter that delegates to a Spring 032 * {@link org.springframework.web.servlet.LocaleResolver}, 033 * exposing the DispatcherServlet-managed locale. 034 * 035 * <p>This adapter gets automatically registered by {@link TilesConfigurer}. 036 * If you are using standard Tiles bootstrap, specify the name of this class 037 * as value for the init-param "org.apache.tiles.locale.LocaleResolver". 038 * 039 * <p><b>NOTE: Tiles 2 support is deprecated in favor of Tiles 3 and will be removed 040 * as of Spring Framework 5.0.</b>. 041 * 042 * @author Juergen Hoeller 043 * @since 2.5 044 * @see org.apache.tiles.definition.UrlDefinitionsFactory#LOCALE_RESOLVER_IMPL_PROPERTY 045 * @deprecated as of Spring 4.2, in favor of Tiles 3 046 */ 047@Deprecated 048public class SpringLocaleResolver extends DefaultLocaleResolver { 049 050 @Override 051 public Locale resolveLocale(TilesRequestContext context) { 052 if (context instanceof JspTilesRequestContext) { 053 PageContext pc = ((JspTilesRequestContext) context).getPageContext(); 054 return RequestContextUtils.getLocale((HttpServletRequest) pc.getRequest()); 055 } 056 else if (context instanceof ServletTilesRequestContext) { 057 HttpServletRequest request = ((ServletTilesRequestContext) context).getRequest(); 058 if (request != null) { 059 return RequestContextUtils.getLocale(request); 060 } 061 } 062 return super.resolveLocale(context); 063 } 064 065}