1/*2 * $Id: DefaultLocaleResolver.java 637434 2008-03-15 15:48:38Z apetrelli $3 *4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */21package org.apache.tiles.locale.impl;
2223import java.util.Locale;
24import java.util.Map;
2526import org.apache.tiles.context.TilesRequestContext;
27import org.apache.tiles.locale.LocaleResolver;
2829/***30 * Default implementation of <code>LocaleResolver</code><br>31 * It tries to take the locale from the session-scoped attribute32 * {@link DefaultLocaleResolver#LOCALE_KEY}. If it is not found, it returns the33 * locale included in the request.34 *35 * @version $Rev: 637434 $ $Date: 2008-03-15 16:48:38 +0100 (sab, 15 mar 2008) $36 */37publicclassDefaultLocaleResolver implements LocaleResolver {
3839/***40 * The attribute name that is used to store the current locale.41 */42publicstaticfinal String LOCALE_KEY = "org.apache.tiles.LOCALE";
4344/*** {@inheritDoc} */45publicvoid init(Map<String, String> params) {
46// Does nothing.47 }
4849/*** {@inheritDoc} */50public Locale resolveLocale(TilesRequestContext request) {
51 Locale retValue = null;
52 Map<String, Object> session = request.getSessionScope();
53if (session != null) {
54 retValue = (Locale) session.get(DefaultLocaleResolver.LOCALE_KEY);
55 }
56if (retValue == null) {
57 retValue = request.getRequestLocale();
58 }
5960return retValue;
61 }
62 }