FileDocCategorySizeDatePackage
LocaleAction.javaAPI DocExample4463Thu Jul 08 09:26:54 BST 2004org.apache.struts.webapp.example

LocaleAction

public final class LocaleAction extends BaseAction

Change user's Struts @link(java.util.Locale).

Fields Summary
private static final String
LANGUAGE

Parameter for @link(java.util.Locale) language property. ["language"]

private static final String
COUNTRY

Parameter for @link(java.util.Locale) country property. ["country"]

private static final String
PAGE

Parameter for response page URI. ["page"]

private static final String
FORWARD

Parameter for response forward name. ["forward"]

private static final String
LOCALE_LOG

Logging message if LocaleAction is missing a target parameter.

Constructors Summary
Methods Summary
public org.apache.struts.action.ActionForwardexecute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

Change the user's Struts @link(java.util.Locale) based on request parameters for "language", "country". After setting the Locale, control is forwarded to an URI path indicated by a "page" parameter, or a forward indicated by a "forward" parameter, or to a forward given as the mappings "parameter" property. The response location must be specified one of these ways.

param
mapping The ActionMapping used to select this instance
param
form The optional ActionForm bean for this request (if any)
param
request The HTTP request we are processing
param
response The HTTP response we are creating
return
An ActionForward indicate the resources that will render the response
exception
Exception if an input/output error or servlet exception occurs


                                                                                                                            
       
                  
                  
                  
      

        String language = request.getParameter(LANGUAGE);
        String country = request.getParameter(COUNTRY);

        Locale locale = getLocale(request);

        if ((!isBlank(language)) && (!isBlank(country))) {
            locale = new Locale(language, country);
        }
        else if (!isBlank(language)) {
            locale = new Locale(language, "");
        }

        HttpSession session = request.getSession();
        session.setAttribute(Globals.LOCALE_KEY, locale);

        String target = request.getParameter(PAGE);
        if (!isBlank(target)) return new ActionForward(target);

        target = request.getParameter(FORWARD);
        if (isBlank(target)) target = mapping.getParameter();
        if (isBlank(target)) {
            log.warn(LOCALE_LOG);
            return null;
        }
        return mapping.findForward(target);
    
private booleanisBlank(java.lang.String string)

Return true if parameter is null or trims to empty.

param
string The string to text; may be null
return
true if parameter is null or empty

        return ((string==null) || (string.trim().length()==0));