org.apache.cocoon.acting
Class LocaleAction

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLoggable
        |
        +--org.apache.cocoon.acting.AbstractAction
              |
              +--org.apache.cocoon.acting.ComposerAction
                    |
                    +--org.apache.cocoon.acting.LocaleAction
All Implemented Interfaces:
Action, org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.Loggable, org.apache.avalon.framework.thread.ThreadSafe

public class LocaleAction
extends ComposerAction
implements org.apache.avalon.framework.thread.ThreadSafe, org.apache.avalon.framework.configuration.Configurable

LocaleAction is a class which obtains the request's locale information (language, country, variant) and makes it available to the sitemap/pipeline. Definition in sitemap:

 <map:actions>
  <map:action name="locale" src="org.apache.cocoon.acting.LocaleAction"/>
 </map:actions>
 
Examples:
 <map:match pattern="file">
  <map:act type="locale">
   <map:generate src="file_{lang}{country}{variant}.xml"/>
  </map:act>
 </map:match>
 
or
 <map:match pattern="file">
  <map:act type="locale">
   <map:generate src="file.xml?locale={locale}"/>
  </map:act>
 </map:match>
 

The variables lang, country, variant, and locale are all available. Note that country and variant can be empty, however lang and locale will always contain a valid value.
The following search criteria are used in order when ascertaining locale values:
  1. Request CGI parameter locale
  2. Session attribute locale
  3. First matching Cookie parameter locale within each cookie sent with the current request
  4. Locale setting of the requesting object
(in the case of language, if the above cases do not yield a valid value the locale value of the server is used)
The attribute names can be configured/customized at action definition and/or usage time, using the paramters {language,country,variant,locale}-attribute. eg.
 <map:action name="locale" src="org.apache.cocoon.acting.LocaleAction">
  <language-attribute>lg</language-attribute>
 </map:action>
 
or:
 <map:act type="locale">
  <map:parameter name="language-attribute" value="lg"/>
 </map:act>
 
Code originated from org.apache.cocoon.acting.LangSelect

Version:
CVS $Id: LocaleAction.java,v 1.7.2.1 2002/08/03 14:49:42 vgritsenko Exp $
Author:
Marcus Crafter, Konstantin Piroumian, Lassi Immonen

Field Summary
static java.lang.String COUNTRY
          Constant representing the country parameter
static java.lang.String COUNTRY_ATTR
          Constant representing the country configuration attribute
static java.lang.String CREATE_SESSION
          Constant representing the session creation configuration attribute
static java.lang.String LANG
          Constant representing the language parameter
static java.lang.String LANG_ATTR
          Constant representing the language configuration attribute
static java.lang.String LOCALE
          Constant representing the locale parameter
static java.lang.String LOCALE_ATTR
          Constant representing the locale configuration attribute
static java.lang.String STORE_COOKIE
          Constant representing the cookie storage configuration attribute
static java.lang.String STORE_REQUEST
          Constant representing the request storage configuration attribute
static java.lang.String STORE_SESSION
          Constant representing the session storage configuration attribute
static java.lang.String VARIANT
          Constant representing the variant parameter
static java.lang.String VARIANT_ATTR
          Constant representing the variant configuration attribute
 
Fields inherited from class org.apache.cocoon.acting.ComposerAction
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
 java.util.Map act(Redirector redirector, SourceResolver resolver, java.util.Map objectModel, java.lang.String source, org.apache.avalon.framework.parameters.Parameters par)
          Action which obtains the current environments locale information, and places it in the objectModel (and optionally in a session/cookie).
 void configure(org.apache.avalon.framework.configuration.Configuration conf)
          Configure this action.
static java.lang.String getLocaleAttribute(java.util.Map objectModel)
          Helper method to access Locale sub component values.
 
Methods inherited from class org.apache.cocoon.acting.ComposerAction
compose
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLoggable
getLogger, setLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LANG

public static final java.lang.String LANG
Constant representing the language parameter

COUNTRY

public static final java.lang.String COUNTRY
Constant representing the country parameter

VARIANT

public static final java.lang.String VARIANT
Constant representing the variant parameter

LOCALE

public static final java.lang.String LOCALE
Constant representing the locale parameter

LANG_ATTR

public static final java.lang.String LANG_ATTR
Constant representing the language configuration attribute

COUNTRY_ATTR

public static final java.lang.String COUNTRY_ATTR
Constant representing the country configuration attribute

VARIANT_ATTR

public static final java.lang.String VARIANT_ATTR
Constant representing the variant configuration attribute

LOCALE_ATTR

public static final java.lang.String LOCALE_ATTR
Constant representing the locale configuration attribute

STORE_REQUEST

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

CREATE_SESSION

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

STORE_SESSION

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

STORE_COOKIE

public static final java.lang.String STORE_COOKIE
Constant representing the cookie storage configuration attribute
Constructor Detail

LocaleAction

public LocaleAction()
Method Detail

configure

public void configure(org.apache.avalon.framework.configuration.Configuration conf)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Configure this action.
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Parameters:
conf - configuration information (if any)

act

public java.util.Map act(Redirector redirector,
                         SourceResolver resolver,
                         java.util.Map objectModel,
                         java.lang.String source,
                         org.apache.avalon.framework.parameters.Parameters par)
                  throws java.lang.Exception
Action which obtains the current environments locale information, and places it in the objectModel (and optionally in a session/cookie).
Following copied from interface: org.apache.cocoon.acting.Action
Parameters:
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
parameters - 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:
java.lang.Exception - Indicates something is totally wrong

getLocaleAttribute

public static java.lang.String getLocaleAttribute(java.util.Map objectModel)
                                           throws java.lang.Exception
Helper method to access Locale sub component values.
Parameters:
objectModel - requesting object's environment
Returns:
locale value
Throws:
java.lang.Exception - should some error occur


Copyright � 1999-2002 Apache Software Foundation. All Rights Reserved.