org.apache.cocoon.acting
Class LocaleAction

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.acting.AbstractAction
          extended byorg.apache.cocoon.acting.ServiceableAction
              extended byorg.apache.cocoon.acting.LocaleAction
All Implemented Interfaces:
org.apache.cocoon.acting.Action, Configurable, Serviceable, ThreadSafe

public class LocaleAction
extends org.apache.cocoon.acting.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:
$Id: LocaleAction.html 1304280 2012-03-23 11:18:01Z ilgrosso $

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(org.apache.cocoon.environment.Redirector redirector, org.apache.cocoon.environment.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.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
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(org.apache.cocoon.environment.Redirector redirector,
               org.apache.cocoon.environment.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 org.apache.cocoon.acting.Action
Throws:
Exception

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-2008 The Apache Software Foundation. All Rights Reserved.