public final class ResourceUtils extends Object
The ResourceUtils
class provides utility methods for resource
handling.
Modifier and Type | Method and Description |
---|---|
static InputStream |
getResource(String path) |
static String |
getResourceString(String key)
Returns the localized String for the given
key . |
static String |
getResourceString(String key,
Locale locale)
Returns the localized String for the given
key and
locale . |
static String |
getResourceString(String key,
Locale locale,
Object requestor)
Returns the localized String for the given
key and
locale . |
static String |
getResourceString(String key,
Object requestor)
Returns the localized String for the given
key . |
static String |
localizeString(String str,
Locale locale,
Object requestor)
Returns the localized version of the given
String
str . |
static String |
localizeString(String str,
Object requestor)
Returns the localized version of the given
String
str . |
static char |
optLocalizeChar(String str,
Object requestor)
Returns the localized version of the given
String
str as char if the result is a 1-length String, '\0'
otherwise. |
static String |
optLocalizeString(String str,
Object requestor)
Returns the localized version of the given
String
str . |
static void |
setHandler(ResourceHandler resourceHandler)
Sets the
ResourceHandler . |
public static void setHandler(ResourceHandler resourceHandler) throws NullPointerException
ResourceHandler
.resourceHandler
- ResourceHandler
to be set.NullPointerException
- if resourceHandler
is null
public static String getResourceString(String key) throws MissingResourceException
key
.
The current set Locale
is used to lookup the requested String
key
- to get localized String for.key
.MissingResourceException
- if no String could be found in the current set Locale
for the given key
.Locale
public static String getResourceString(String key, Object requestor) throws MissingResourceException
key
.
The current set Locale
is used to lookup the requested String
key
- to get localized String for.requestor
- object that requests the resource String
. The
requestor
may be crucial how the strategy is
looking for the resource. If requestor
is
null
only the default resource bundle is searched
through.key
.MissingResourceException
- if no String could be found in the current set Locale
for the given key
.Locale
public static String getResourceString(String key, Locale locale) throws MissingResourceException
key
and
locale
.key
- to get localized String for.locale
- to lookup the String
for.key
.MissingResourceException
- if no String could be found in the current set Locale
for the given key
.Locale
public static String getResourceString(String key, Locale locale, Object requestor) throws MissingResourceException
key
and
locale
.key
- to get localized String for.locale
- to lookup the String
for.requestor
- object that requests the resource String
. The
requestor
may be crucial how the strategy is
looking for the resource. If requestor
is
null
only the default resource bundle is searched
through.key
.MissingResourceException
- if no String could be found in the current set Locale
for the given key
.Locale
public static String optLocalizeString(String str, Object requestor)
String
str
. Only parts of the String
fitting the pattern
{$myKey}
will be localized. myKey
represents
the key for a localized String in the chosen Locale
.
The current set Locale
is used to lookup the requested String.
Hint: The MissingResourceException
is
suppressed by the method. The stack trace of the
MissingResourceException
will be reported to the
Application
's logger.
public static char optLocalizeChar(String str, Object requestor)
String
str
as char if the result is a 1-length String, '\0'
otherwise. Only parts of the String
fitting the pattern
{$myKey}
will be localized. myKey
represents
the key for a localized String in the chosen Locale
.
The current set Locale
is used to lookup the requested String.
Hint: The MissingResourceException
is
suppressed by the method. The stack trace of the
MissingResourceException
will be reported to the
Application
's logger.
str
- to localizerequestor
- object that requests the resource String
. The
requestor
may be crucial how the strategy is
looking for the resource. If requestor
is
null
only the default resource bundle is searched
through.str
or '\0'.Locale
public static String localizeString(String str, Object requestor) throws MissingResourceException
String
str
. Only parts of the String
fitting the pattern
{$myKey}
will be localized. myKey
represents
the key for a localized String in the chosen Locale
.
The current set Locale
is used to lookup the requested String.
str
- to localizerequestor
- object that requests the resource String
. The
requestor
may be crucial how the strategy is
looking for the resource. If requestor
is
null
only the default resource bundle is searched
through.key
.MissingResourceException
- if no String could be found in the current set Locale
for the given key
.Locale
public static String localizeString(String str, Locale locale, Object requestor) throws MissingResourceException
String
str
. Only parts of the String
fitting the pattern
{$myKey}
will be localized. myKey
represents
the key for a localized String in the chosen Locale
.str
- to localizelocale
- to lookup the String
for.requestor
- object that requests the resource String
. The
requestor
may be crucial how the strategy is
looking for the resource. If requestor
is
null
only the default resource bundle is searched
through.key
.MissingResourceException
- if no String could be found in the current set Locale
for the given key
.Locale
public static InputStream getResource(String path) throws IOException
IOException
Copyright © 2003–2023 XDEV Software. All rights reserved.