net.sourceforge.stripes.localization
Class LocalizationUtility

java.lang.Object
  extended by net.sourceforge.stripes.localization.LocalizationUtility

public class LocalizationUtility
extends Object

Provides simple localization utility methods that are used in multiple places in the Stripes code base.

Since:
Stripes 1.1
Author:
Tim Fennell

Constructor Summary
LocalizationUtility()
           
 
Method Summary
static String getErrorMessage(Locale locale, String key)
          Looks up the specified key in the error message resource bundle.
static String getLocalizedFieldName(String fieldName, String actionPath, Class<? extends ActionBean> beanclass, Locale locale)
          Fetches the localized name for a form field if one exists in the form field resource bundle.
static String makePseudoFriendlyName(String fieldNameKey)
          Makes a half hearted attempt to convert the property name of a field into a human friendly name by breaking it on periods and upper case letters and capitalizing each word.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalizationUtility

public LocalizationUtility()
Method Detail

getLocalizedFieldName

public static String getLocalizedFieldName(String fieldName,
                                           String actionPath,
                                           Class<? extends ActionBean> beanclass,
                                           Locale locale)

Fetches the localized name for a form field if one exists in the form field resource bundle. If for any reason a localized value cannot be found (e.g. the bundle cannot be found, or does not contain the required properties) then null will be returned.

Looks first for a property called beanClassFQN.fieldName in the resource bundle. If that is undefined, it next looks for actionPath.fieldName and if not defined, looks for a property called fieldName. Will strip any indexing from the field name prior to using it to construct property names (e.g. foo[12] will become simply foo).

Parameters:
fieldName - The name of the field whose localized name to look up
actionPath - The action path of the form in which the field is nested. If for some reason this is not available, null may be passed without causing errors.
locale - The desired locale of the looked up name.
Returns:
a localized field name if one can be found, or null otherwise.

makePseudoFriendlyName

public static String makePseudoFriendlyName(String fieldNameKey)
Makes a half hearted attempt to convert the property name of a field into a human friendly name by breaking it on periods and upper case letters and capitalizing each word. This is only used when developers do not provide names for their fields.

Parameters:
fieldNameKey - the programmatic name of a form field
Returns:
String a more user friendly name for the field in the absence of anything better

getErrorMessage

public static String getErrorMessage(Locale locale,
                                     String key)
Looks up the specified key in the error message resource bundle. If the bundle is missing or if the resource cannot be found, will return null instead of throwing an exception.

Parameters:
locale - the locale in which to lookup the resource
key - the exact resource key to lookup
Returns:
the resource String or null


? Copyright 2005-2006, Stripes Development Team.