com.ora.jsp.beans.locale
Class LocaleBean

java.lang.Object
  |
  +--com.ora.jsp.beans.locale.LocaleBean
All Implemented Interfaces:
java.io.Serializable

public class LocaleBean
extends java.lang.Object
implements java.io.Serializable

This class contains a number of methods for dealing with localized content. It's used by the com.ora.jsp.tags.generic localization tag handler classes, but can also be used stand-alone.

Version:
1.0
Author:
Hans Bergsten, Gefion software
See Also:
Serialized Form

Field Summary
private  java.util.ResourceBundle bundle
           
private  java.lang.String bundleName
           
private  java.lang.String charset
           
private  java.text.DateFormat dateFormat
           
private  java.lang.String language
           
private  java.util.Locale locale
           
private  java.text.NumberFormat numberFormat
           
private  java.util.Hashtable parameters
           
private  java.util.Locale[] requestLocales
           
private  java.lang.String supportedLangs
           
 
Constructor Summary
LocaleBean()
           
 
Method Summary
 java.util.Date getDate(java.lang.String date)
          Returns the specified date String converted to a Date, parsed as defined by the currently selected locale.
 java.lang.String getDateString(java.util.Date date)
          Returns the specified Date converted to a String, formatted as defined by the currently selected locale.
private  java.lang.String getDecodedValue(java.lang.String value)
          This method returns a new String created from the specified String, encoded as 8859_1 converted to the currently set charset.
private  java.util.Locale getDefaultLocale()
          Returns a Locale for the default language.
 double getDouble(java.lang.String number)
          Returns the specified number String converted to a double, parsed as defined by the currently selected locale.
 float getFloat(java.lang.String number)
          Returns the specified number String converted to a float, parsed as defined by the currently selected locale.
 int getInt(java.lang.String number)
          Returns the specified number String converted to a int, parsed as defined by the currently selected locale.
 java.lang.String getLanguage()
          Returns the language code for the currently selected locale.
 java.util.Locale getLocale()
          Returns a Locale.
 long getLong(java.lang.String number)
          Returns the specified number String converted to a long, parsed as defined by the currently selected locale.
private  java.lang.Number getNumber(java.lang.String number)
          Returns the specified String as a Number, parsed based on the currently selected locale.
 java.lang.String getNumberString(double number)
          Returns the specified number converted to a String, formatted as defined by the currently selected locale.
 java.lang.String getPageName(java.lang.String basePageName)
          Returns a version of the specified page name with a language/country suffix for the currently selected locale.
 java.lang.String getParameter(java.lang.String parameter)
          Returns the first all value for the specified parameter, parsed using the currently specified charset.
 java.util.Enumeration getParameterNames()
          Returns an Enumeration of all parameter names.
 java.lang.String[] getParameterValues(java.lang.String parameter)
          Returns an array of all values for the specified parameter, parsed using the currently specified charset.
private  java.util.Locale getSupportedLocale(java.util.Locale[] locales)
          Returns the first Locale that matches a supported language, or the default Locale if no match.
 java.lang.String getText(java.lang.String resourceName)
          Returns the text resource for the specified key, with the best match for the currently selected locale.
private  boolean isEqual(java.util.Locale[] arr1, java.util.Locale[] arr2)
          Returns true if the the specifed Locale arrays contains exactly the same locale information.
private  boolean isSupportedLang(java.lang.String language)
          Returns true if the specified languge is a supported language.
private  void resetBundle()
          Resets the ResourceBundle.
private  void resetLocale()
          Resets all locale dependent variables.
 void setBundleName(java.lang.String bundleName)
          Sets the bundle name.
 void setCharset(java.lang.String charset)
          Sets the charset used to parse request parameters.
 void setLanguage(java.lang.String language)
          Sets the user selected language/country code.
 void setParameters(java.util.Hashtable parameters)
          Sets the parameter list.
 void setRequestLocales(java.util.Locale[] locales)
          Sets the set of locales received with the request, and resets the currently selected locale if the new set is different from the current set.
 void setSupportedLangs(java.lang.String supportedLangs)
          Sets the set of supported languages, provided as a comma separated list of country/language codes.
private  java.lang.String toLanguage(java.util.Locale locale)
          Returns the language/country code for the specified Locale.
private  java.util.Locale toLocale(java.lang.String language)
          Returns a Locale for the specifed language/country code.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

locale

private java.util.Locale locale

requestLocales

private java.util.Locale[] requestLocales

bundle

private java.util.ResourceBundle bundle

supportedLangs

private java.lang.String supportedLangs

bundleName

private java.lang.String bundleName

language

private java.lang.String language

numberFormat

private java.text.NumberFormat numberFormat

dateFormat

private java.text.DateFormat dateFormat

charset

private java.lang.String charset

parameters

private java.util.Hashtable parameters
Constructor Detail

LocaleBean

public LocaleBean()
Method Detail

getLocale

public java.util.Locale getLocale()
Returns a Locale. The Locale is constructed based on the language property, if set. If not, the Locale determined based on the Accept-Language header (the requestLocales property) is returned, if set. If the Locale found this way matches one of the supported languages, it's returned. Otherwise the Locale for first language in the list of supported languages is returned.

setRequestLocales

public void setRequestLocales(java.util.Locale[] locales)
Sets the set of locales received with the request, and resets the currently selected locale if the new set is different from the current set. This is done so that all possible locale sources will be evaluated again the next time the locale property is retrieved.

setSupportedLangs

public void setSupportedLangs(java.lang.String supportedLangs)
Sets the set of supported languages, provided as a comma separated list of country/language codes. This is a mandatory property.

Resets the currently selected locale if the new set is different from the current set. This is done so that all possible locale sources will be evaluated again the next time the locale property is retrieved.


getLanguage

public java.lang.String getLanguage()
Returns the language code for the currently selected locale.

setLanguage

public void setLanguage(java.lang.String language)
Sets the user selected language/country code.

Resets the currently selected locale if the new language is different from the current. This is done so that all possible locale sources will be evaluated again the next time the locale property is retrieved.


setBundleName

public void setBundleName(java.lang.String bundleName)
Sets the bundle name.

Resets the current ResourceBundle so that a new will be created with the new bundle name the next time the ResourceBundle is retrieved.


setCharset

public void setCharset(java.lang.String charset)
Sets the charset used to parse request parameters.

getDouble

public double getDouble(java.lang.String number)
                 throws java.text.ParseException
Returns the specified number String converted to a double, parsed as defined by the currently selected locale.

getFloat

public float getFloat(java.lang.String number)
               throws java.text.ParseException
Returns the specified number String converted to a float, parsed as defined by the currently selected locale.

getInt

public int getInt(java.lang.String number)
           throws java.text.ParseException
Returns the specified number String converted to a int, parsed as defined by the currently selected locale.

getLong

public long getLong(java.lang.String number)
             throws java.text.ParseException
Returns the specified number String converted to a long, parsed as defined by the currently selected locale.

getDate

public java.util.Date getDate(java.lang.String date)
                       throws java.text.ParseException
Returns the specified date String converted to a Date, parsed as defined by the currently selected locale.

getNumberString

public java.lang.String getNumberString(double number)
Returns the specified number converted to a String, formatted as defined by the currently selected locale.

getDateString

public java.lang.String getDateString(java.util.Date date)
Returns the specified Date converted to a String, formatted as defined by the currently selected locale.

getText

public java.lang.String getText(java.lang.String resourceName)
Returns the text resource for the specified key, with the best match for the currently selected locale.

getPageName

public java.lang.String getPageName(java.lang.String basePageName)
Returns a version of the specified page name with a language/country suffix for the currently selected locale.

setParameters

public void setParameters(java.util.Hashtable parameters)
Sets the parameter list.

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String parameter)
                                      throws java.io.UnsupportedEncodingException
Returns an array of all values for the specified parameter, parsed using the currently specified charset.

getParameterNames

public java.util.Enumeration getParameterNames()
Returns an Enumeration of all parameter names.

getParameter

public java.lang.String getParameter(java.lang.String parameter)
                              throws java.io.UnsupportedEncodingException
Returns the first all value for the specified parameter, parsed using the currently specified charset.

resetBundle

private void resetBundle()
Resets the ResourceBundle.

resetLocale

private void resetLocale()
Resets all locale dependent variables.

isEqual

private boolean isEqual(java.util.Locale[] arr1,
                        java.util.Locale[] arr2)
Returns true if the the specifed Locale arrays contains exactly the same locale information.

isSupportedLang

private boolean isSupportedLang(java.lang.String language)
Returns true if the specified languge is a supported language.

getDefaultLocale

private java.util.Locale getDefaultLocale()
Returns a Locale for the default language.

toLocale

private java.util.Locale toLocale(java.lang.String language)
Returns a Locale for the specifed language/country code.

toLanguage

private java.lang.String toLanguage(java.util.Locale locale)
Returns the language/country code for the specified Locale.

getSupportedLocale

private java.util.Locale getSupportedLocale(java.util.Locale[] locales)
Returns the first Locale that matches a supported language, or the default Locale if no match.

getNumber

private java.lang.Number getNumber(java.lang.String number)
                            throws java.text.ParseException
Returns the specified String as a Number, parsed based on the currently selected locale.

getDecodedValue

private java.lang.String getDecodedValue(java.lang.String value)
                                  throws java.io.UnsupportedEncodingException
This method returns a new String created from the specified String, encoded as 8859_1 converted to the currently set charset.