org.tigris.scarab.tools
Class ScarabLocalizationTool

java.lang.Object
  extended byorg.apache.turbine.tool.LocalizationTool
      extended byorg.tigris.scarab.tools.ScarabLocalizationTool
All Implemented Interfaces:
org.apache.turbine.services.pull.ApplicationTool

public class ScarabLocalizationTool
extends org.apache.turbine.tool.LocalizationTool

Scarab-specific localiztion tool. Uses a specific property format to map a generic i10n key to a specific screen. For example, the $i10n.title on the screen: admin/AddPermission.vm would be in ScarabBundle_en.properties

  admin/AddPermission.vm.Title
 

Author:
Daniel Rall , Eric Pugh

Field Summary
static java.util.Locale DEFAULT_LOCALE
          The Locale to be used, if the Resource could not be found in one of the Locales specified in the Browser's language preferences.
 
Constructor Summary
ScarabLocalizationTool()
          Creates a new instance.
 
Method Summary
protected  java.lang.String findProperty(java.lang.String property)
          Retrieves the localized version of the value of property.
 java.lang.String format(java.lang.String key, java.util.List args)
          Formats a localized value using the provided objects.
 java.lang.String format(java.lang.String key, java.lang.Object arg1)
          Formats a localized value using the provided object.
 java.lang.String format(java.lang.String key, java.lang.Object[] args)
          Formats a localized value using the provided objects.
 java.lang.String format(java.lang.String key, java.lang.Object arg1, java.lang.Object arg2)
          Formats a localized value using the provided objects.
 java.lang.String format(java.lang.String key, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
          Formats a localized value using the provided objects.
 java.lang.String get(Localizable key)
          Return the localized property value.
 java.lang.String get(java.lang.String key)
          Deprecated. Please use #get(LocalizationKey) instead
protected  java.lang.String getBundleName()
          Get the default ResourceBundle name
 java.lang.String getIgnoreMissingResource(java.lang.String key)
          Deprecated. Please use #get(LocalizationKey) instead
 java.lang.String getMessage(java.lang.Throwable t)
          Extract a message from an exception.
 java.util.Locale getPrimaryLocale()
          Gets the primary locale.
 java.lang.String getTitle()
          Provides $l10n.Title to templates, grabbing it from the title property for the current template.
 void init(java.lang.Object obj)
          Initialize the tool.
 boolean isFilterEnabled()
          Whether our cross-site scripting filter is enabled.
 void refresh()
          Reset this instance to initial values.
 void restoreBundlePrefix()
          Restore the old Bundle Prefix to it's previous value.
 void setBundlePrefix(java.lang.String prefix)
          Change the BundlePrefix.
 void setFilterEnabled(boolean v)
          Allow us to be able to enable/disable our cross-site scripting filter when rendering something from the format() method.
 
Methods inherited from class org.apache.turbine.tool.LocalizationTool
determineBundleName, formatErrorMessage, get, getLocale, getLocalizationService, getPrefix, setPrefix
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LOCALE

public static java.util.Locale DEFAULT_LOCALE
The Locale to be used, if the Resource could not be found in one of the Locales specified in the Browser's language preferences.

Constructor Detail

ScarabLocalizationTool

public ScarabLocalizationTool()
Creates a new instance. Client should initialize the instance.

Method Detail

get

public java.lang.String get(Localizable key)
Return the localized property value. Take into account the Browser settings (in order of preference), the Turbine default settings and the System Locale, if the Turbine Default Locale is not defined.


get

public java.lang.String get(java.lang.String key)
Deprecated. Please use #get(LocalizationKey) instead

Return the localized property value. Take into account the Browser settings (in order of preference), the Turbine default settings and the System Locale, if the Turbine Default Locale is not defined. NOTE: Please don't use this method from the Java-code. It is intended for use with Velocity only!


getIgnoreMissingResource

public java.lang.String getIgnoreMissingResource(java.lang.String key)
Deprecated. Please use #get(LocalizationKey) instead

Return the localized property value. Take into account the Browser settings (in order of preference), the Turbine default settings and the System Locale, if the Turbine Default Locale is not defined. NOTE: Please don't use this method from the Java-code. It is intended for use with Velocity only!


format

public java.lang.String format(java.lang.String key,
                               java.lang.Object arg1)
Formats a localized value using the provided object.

Parameters:
key - The identifier for the localized text to retrieve,
arg1 - The object to use as {0} when formatting the localized text.
Returns:
Formatted localized text.
See Also:
format(String, List)

format

public java.lang.String format(java.lang.String key,
                               java.lang.Object arg1,
                               java.lang.Object arg2)
Formats a localized value using the provided objects.

Parameters:
key - The identifier for the localized text to retrieve,
arg1 - The object to use as {0} when formatting the localized text.
arg2 - The object to use as {1} when formatting the localized text.
Returns:
Formatted localized text.
See Also:
format(String, List)

format

public java.lang.String format(java.lang.String key,
                               java.lang.Object arg1,
                               java.lang.Object arg2,
                               java.lang.Object arg3)
Formats a localized value using the provided objects.

Parameters:
key - The identifier for the localized text to retrieve,
arg1 - The object to use as {0} when formatting the localized text.
arg2 - The object to use as {1} when formatting the localized text.
arg3 - The object to use as {2} when formatting the localized text.
Returns:
Formatted localized text.
See Also:
format(String, List)

format

public java.lang.String format(java.lang.String key,
                               java.util.List args)

Formats a localized value using the provided objects.

ResourceBundle:

  VelocityUsersNotWrong={0} out of {1} users can't be wrong!
 
Template:
 $l10n.format("VelocityUsersNotWrong", ["9", "10"])
 
Result:
  9 out of 10 Velocity users can't be wrong!
 

Parameters:
key - The identifier for the localized text to retrieve,
args - The objects to use as {0}, {1}, etc. when formatting the localized text.
Returns:
Formatted localized text.

setFilterEnabled

public void setFilterEnabled(boolean v)
Allow us to be able to enable/disable our cross-site scripting filter when rendering something from the format() method. The default is to have it enabled.


isFilterEnabled

public boolean isFilterEnabled()
Whether our cross-site scripting filter is enabled.


format

public java.lang.String format(java.lang.String key,
                               java.lang.Object[] args)
Formats a localized value using the provided objects. Take into account the Browser settings (in order of preference), the Turbine default settings and the System Locale, if the Turbine Default Locale is not defined.

Parameters:
key - The identifier for the localized text to retrieve,
args - The MessageFormat data used when formatting the localized text.
Returns:
Formatted localized text.
See Also:
format(String, List)

getTitle

public java.lang.String getTitle()
Provides $l10n.Title to templates, grabbing it from the title property for the current template.

Returns:
The title for the template used in the current request, or null if title property was not found in the available resource bundles.

findProperty

protected java.lang.String findProperty(java.lang.String property)
Retrieves the localized version of the value of property.

Parameters:
property - The name of the property whose value to retrieve.
Returns:
The localized property value.

setBundlePrefix

public void setBundlePrefix(java.lang.String prefix)
Change the BundlePrefix. Keep the original value for later restore

Parameters:
prefix -

restoreBundlePrefix

public void restoreBundlePrefix()
Restore the old Bundle Prefix to it's previous value.


getBundleName

protected java.lang.String getBundleName()
Get the default ResourceBundle name


getPrimaryLocale

public java.util.Locale getPrimaryLocale()
Gets the primary locale. The primary locale is the locale which will be choosen at first from the set of Locales which are accepted by the user as defined on the Browser language preferrences.

Returns:
The primary locale currently in use.

init

public void init(java.lang.Object obj)
Initialize the tool. Within the turbine pull service this tool is initialized with a RunData. However, the tool can also be initialized with a Locale.


refresh

public void refresh()
Reset this instance to initial values. Probably needed for reuse of ScarabLocalizationTool Instances.


getMessage

public java.lang.String getMessage(java.lang.Throwable t)
Extract a message from an exception. This method checks, if the exception is Localizable. If so, we now can retrieve the localized exception message. Otherwise we retrieve the standard message via e.getLocalizedMessage().

Returns:
throws NullPointerException if t is null


Copyright © 2000-2004 Tigris.org. All Rights Reserved.