001 package hirondelle.web4j.request;
002
003 import java.util.Locale;
004 import javax.servlet.http.HttpServletRequest;
005
006 import hirondelle.web4j.util.WebUtil;
007 import hirondelle.web4j.Controller;
008
009 /**
010 Retrieve the {@link Locale} stored in any scope under the key
011 {@link hirondelle.web4j.Controller#LOCALE}.
012
013 <P>Upon startup, the {@link hirondelle.web4j.Controller} will read in the <tt>DefaultLocale</tt>
014 configured in <tt>web.xml</tt>, and place it in application scope under the key
015 {@link hirondelle.web4j.Controller#LOCALE}, as a {@link Locale} object (not a {@link String}).
016
017 <P><em>If desired</em>, the application programmer can also store a user-specific
018 {@link Locale} in session scope, under the same key. Thus,
019 this class will first find the user-specific <tt>Locale</tt>, overriding the default
020 <tt>Locale</tt> stored in application scope.
021
022 <P>If any other behavior is desired, then simply provide an alternate implementation of
023 {@link LocaleSource}.
024 */
025 public class LocaleSourceImpl implements LocaleSource {
026
027 /** See class comment. */
028 public Locale get(HttpServletRequest aRequest){
029 return (Locale)WebUtil.findAttribute(Controller.LOCALE, aRequest);
030 }
031 }