org.apache.cocoon.acting
Class LocaleAction

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.acting.AbstractAction
          extended by org.apache.cocoon.acting.ServiceableAction
              extended by org.apache.cocoon.acting.LocaleAction
All Implemented Interfaces:
Component, Configurable, LogEnabled, Serviceable, ThreadSafe, Action

public class LocaleAction
extends ServiceableAction
implements ThreadSafe, Configurable

An action that locates and provides to the pipeline locale information looked up in a range of ways.

Configuration

A sample configuration (given in the <map:matchers> section of the sitemap) is given below. This configuration shows default values.

   <map:action name="locale" src="org.apache.cocoon.acting.LocaleAction">
     <locale-attribute>locale</locale-attribute>
     <use-locale>true</use-locale>
     <default-locale language="en" country="US"/>
     <store-in-request>false<store-in-request>
     <create-session>false<create-session>
     <store-in-session>false<store-in-session>
     <store-in-cookie>false<store-in-cookie>
   </map:action>
 

Above configuration parameters mean:

Usage

This action will be used in a pipeline like so:

   <map:act type="locale">
     <map:generate src="file_{language}_{country}_{variant}.xml"/>
     ...
   </map:match>
 

or

   <map:act type="locale">
     <map:generate src="file_{locale}.xml"/>
     ...
   </map:match>
 

Locale Identification

Locales will be tested in following order:

First found locale will be returned.

Sitemap Variables

Once locale has been found, the following sitemap variables will be available to sitemap elements contained within the action:

Version:
CVS $Id: LocaleAction.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Marcus Crafter, Konstantin Piroumian, Lassi Immonen, Vadim Gritsenko

Field Summary
static String CREATE_SESSION
          Constant representing the session creation configuration attribute
static String LOCALE
          Default locale attribute name.
static String LOCALE_ATTR
          Configuration element name for locale attribute name.
static String STORE_COOKIE
          Constant representing the cookie storage configuration attribute
static String STORE_REQUEST
          Constant representing the request storage configuration attribute
static String STORE_SESSION
          Constant representing the session storage configuration attribute
 
Fields inherited from class org.apache.cocoon.acting.ServiceableAction
manager
 
Fields inherited from class org.apache.cocoon.acting.AbstractAction
EMPTY_MAP
 
Fields inherited from interface org.apache.cocoon.acting.Action
ROLE
 
Constructor Summary
LocaleAction()
           
 
Method Summary
 Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters params)
          Action which obtains the current environments locale information, and places it in the objectModel (and optionally in a session/cookie).
 void configure(Configuration config)
          Configure this action.
static String getLocaleAttribute(Map objectModel, String localeAttrName)
          Deprecated. See I18nUtils.findLocale
 
Methods inherited from class org.apache.cocoon.acting.ServiceableAction
service
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALE

public static final String LOCALE
Default locale attribute name.

See Also:
Constant Field Values

LOCALE_ATTR

public static final String LOCALE_ATTR
Configuration element name for locale attribute name.

See Also:
Constant Field Values

STORE_REQUEST

public static final String STORE_REQUEST
Constant representing the request storage configuration attribute

See Also:
Constant Field Values

CREATE_SESSION

public static final String CREATE_SESSION
Constant representing the session creation configuration attribute

See Also:
Constant Field Values

STORE_SESSION

public static final String STORE_SESSION
Constant representing the session storage configuration attribute

See Also:
Constant Field Values

STORE_COOKIE

public static final String STORE_COOKIE
Constant representing the cookie storage configuration attribute

See Also:
Constant Field Values
Constructor Detail

LocaleAction

public LocaleAction()
Method Detail

configure

public void configure(Configuration config)
               throws ConfigurationException
Configure this action.

Specified by:
configure in interface Configurable
Parameters:
config - configuration information (if any)
Throws:
ConfigurationException

act

public Map act(Redirector redirector,
               SourceResolver resolver,
               Map objectModel,
               String source,
               Parameters params)
        throws Exception
Action which obtains the current environments locale information, and places it in the objectModel (and optionally in a session/cookie).

Specified by:
act in interface Action
resolver - The SourceResolver in charge
objectModel - The Map with object of the calling environment which can be used to select values this controller may need (ie Request, Response).
source - A source String to the Action
params - The Parameters for this invocation
Returns:
Map The returned Map object with sitemap substitution values which can be used in subsequent elements attributes like src= using a xpath like expression: src="mydir/{myval}/foo" If the return value is null the processing inside the element of the sitemap will be skipped.
Throws:
Exception - Indicates something is totally wrong

getLocaleAttribute

public static String getLocaleAttribute(Map objectModel,
                                        String localeAttrName)
Deprecated. See I18nUtils.findLocale

Helper method to retreive the attribute value containing locale information. See class documentation for locale determination algorythm.

Parameters:
objectModel - requesting object's environment
Returns:
locale value or null if no locale was found


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.