Methods Summary |
---|
public 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.
if (dateFormat == null) {
dateFormat = DateFormat.getDateInstance(dateFormat.FULL, getLocale());
}
return dateFormat.parse(date);
|
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.
if (dateFormat == null) {
dateFormat = DateFormat.getDateInstance(dateFormat.FULL, getLocale());
}
return dateFormat.format(date);
|
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.
if (charset == null) {
return value;
}
return new String(value.getBytes("8859_1"), charset);
|
private java.util.Locale | getDefaultLocale()Returns a Locale for the default language.
StringTokenizer st = new StringTokenizer(supportedLangs, ",");
String defaultLang = st.nextToken().trim();
return toLocale(defaultLang);
|
public double | getDouble(java.lang.String number)Returns the specified number String converted to a
double, parsed as defined by the currently selected locale.
return getNumber(number).doubleValue();
|
public float | getFloat(java.lang.String number)Returns the specified number String converted to a
float, parsed as defined by the currently selected locale.
return getNumber(number).floatValue();
|
public int | getInt(java.lang.String number)Returns the specified number String converted to a
int, parsed as defined by the currently selected locale.
return getNumber(number).intValue();
|
public java.lang.String | getLanguage()Returns the language code for the currently selected
locale.
if (language == null) {
language = toLanguage(getLocale());
}
return language;
|
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.
if (locale == null) {
if (language != null && isSupportedLang(language)) {
locale = toLocale(language);
}
else if (requestLocales != null) {
locale = getSupportedLocale(requestLocales);
}
if (locale == null) {
locale = getDefaultLocale();
}
}
return locale;
|
public long | getLong(java.lang.String number)Returns the specified number String converted to a
long, parsed as defined by the currently selected locale.
return getNumber(number).longValue();
|
private java.lang.Number | getNumber(java.lang.String number)Returns the specified String as a Number, parsed based on
the currently selected locale.
if (numberFormat == null) {
numberFormat = NumberFormat.getNumberInstance(getLocale());
}
return numberFormat.parse(number);
|
public java.lang.String | getNumberString(double number)Returns the specified number converted to a
String, formatted as defined by the currently selected locale.
if (numberFormat == null) {
numberFormat = NumberFormat.getNumberInstance(getLocale());
}
return numberFormat.format(number);
|
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.
StringBuffer pageName = new StringBuffer();
Locale locale = getLocale();
if (locale.equals(getDefaultLocale())) {
pageName.append(basePageName);
}
else {
String suffix = getLocale().toString();
int extPos = basePageName.indexOf(".");
if (extPos != -1) {
pageName.append(basePageName.substring(0, extPos)).
append("_").append(suffix).
append(basePageName.substring(extPos));
}
else {
pageName.append(basePageName).
append("_").append(suffix);
}
}
return pageName.toString();
|
public java.lang.String | getParameter(java.lang.String parameter)Returns the first all value for the specified parameter,
parsed using the currently specified charset.
String firstValue = null;
String[] values = getParameterValues(parameter);
if (values != null && values.length > 0) {
firstValue = values[0];
}
return firstValue;
|
public java.util.Enumeration | getParameterNames()Returns an Enumeration of all parameter names.
if (parameters == null) {
parameters = new Hashtable();
}
return parameters.keys();
|
public java.lang.String[] | getParameterValues(java.lang.String parameter)Returns an array of all values for the specified parameter,
parsed using the currently specified charset.
String[] values = null;
if (parameters != null) {
String[] encodedValues = (String[]) parameters.get(parameter);
if (encodedValues != null) {
values = new String[encodedValues.length];
for (int i = 0; i < encodedValues.length; i++) {
values[i] = getDecodedValue(encodedValues[i]);
}
}
}
return values;
|
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.
Locale locale = getDefaultLocale();
for (int i = 0; i < locales.length; i++) {
if (isSupportedLang(toLanguage(locales[i]))) {
locale = locales[i];
break;
}
}
return locale;
|
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.
if (bundle == null) {
bundle = ResourceBundle.getBundle(bundleName, getLocale());
}
return bundle.getString(resourceName);
|
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.
boolean isEqual = true;
if (arr1.length != arr2.length) {
isEqual = false;
}
else {
for (int i = 1; i < arr1.length; i++) {
if (!arr1[i].equals(arr2[i])) {
isEqual = false;
break;
}
}
}
return isEqual;
|
private boolean | isSupportedLang(java.lang.String language)Returns true if the specified languge is a supported language.
return supportedLangs.indexOf(language) != -1;
|
private void | resetBundle()Resets the ResourceBundle.
bundle = null;
|
private void | resetLocale()Resets all locale dependent variables.
locale = null;
numberFormat = null;
dateFormat = null;
bundle = null;
|
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.
if (this.bundleName != null && !bundleName.equals(this.bundleName)) {
resetBundle();
}
this.bundleName = bundleName;
|
public void | setCharset(java.lang.String charset)Sets the charset used to parse request parameters.
this.charset = charset;
|
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.
if (this.language != null && !language.equals(this.language)) {
resetLocale();
}
this.language = language;
|
public void | setParameters(java.util.Hashtable parameters)Sets the parameter list.
this.parameters = parameters;
|
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.
if (requestLocales != null && !isEqual(requestLocales, locales)) {
resetLocale();
}
requestLocales = locales;
|
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.
if (this.supportedLangs != null &&
!this.supportedLangs.equals(supportedLangs)) {
resetLocale();
}
this.supportedLangs = supportedLangs;
|
private java.lang.String | toLanguage(java.util.Locale locale)Returns the language/country code for the specified Locale.
String language = locale.getLanguage();
String country = locale.getCountry();
if (country != null && country.length() > 0) {
language = language + "-" + country;
}
return language;
|
private java.util.Locale | toLocale(java.lang.String language)Returns a Locale for the specifed language/country code.
Locale locale = null;
int countrySeparator = language.indexOf("-");
if (countrySeparator != -1) {
locale = new Locale(language.substring(0, countrySeparator),
language.substring(countrySeparator + 1));
}
else {
locale = new Locale(language, "");
}
return locale;
|