Package org.geotools.util
Class IndexedResourceBundle
- Object
-
- ResourceBundle
-
- IndexedResourceBundle
-
- Direct Known Subclasses:
Descriptions,Logging,Loggings,Vocabulary,Vocabulary
public class IndexedResourceBundle extends ResourceBundle
ResourceBundleimplementation using integers instead of strings for resource keys. Because it doesn't use strings, this implementation avoids adding all those string constants to.classfiles and runtime images. Developers still have meaningful labels in their code (e.g.DIMENSION_MISMATCH) through a set of constants defined in interfaces. This approach furthermore gives the benefit of compile-time safety. Because integer constants are inlined right into class files at compile time, the declarative interface is never loaded at run time. This class also provides facilities for string formatting usingMessageFormat.- Since:
- 2.4
- Author:
- Martin Desruisseaux (IRD)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ResourceBundle
ResourceBundle.Control
-
-
Field Summary
-
Fields inherited from class ResourceBundle
parent
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedIndexedResourceBundle()Constructs a new resource bundle.protectedIndexedResourceBundle(String filename)Constructs a new resource bundle.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Stringformat(LogRecord record)Localize and format the message string from a log record.Enumeration<String>getKeys()Returns an enumeration of the keys.StringgetLabel(int key)Gets a string for the given key and appends ": " to it.LogRecordgetLogRecord(Level level, int key)Gets a localized log record.LogRecordgetLogRecord(Level level, int key, Object arg0)Gets a localized log record.LogRecordgetLogRecord(Level level, int key, Object arg0, Object arg1)Gets a localized log record.LogRecordgetLogRecord(Level level, int key, Object arg0, Object arg1, Object arg2)Gets a localized log record.LogRecordgetLogRecord(Level level, int key, Object arg0, Object arg1, Object arg2, Object arg3)Gets a localized log record.StringgetMenuLabel(int key)Gets a string for the given key and appends "..." to it.StringgetString(int key)Gets a string for the given key from this resource bundle or one of its parents.StringgetString(int key, Object arg0)Gets a string for the given key and formats it with the specified argument.StringgetString(int key, Object arg0, Object arg1)Gets a string for the given key and replaces all occurrences of "{0}", "{1}", with values ofarg0,arg1, etc.StringgetString(int key, Object arg0, Object arg1, Object arg2)Gets a string for the given key and replaces all occurrences of "{0}", "{1}", with values ofarg0,arg1, etc.StringgetString(int key, Object arg0, Object arg1, Object arg2, Object arg3)Gets a string for the given key and replaces all occurrences of "{0}", "{1}", with values ofarg0,arg1, etc.StringgetString(int key, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4)Gets a string for the given key and replaces all occurrences of "{0}", "{1}", with values ofarg0,arg1, etc.protected ObjecthandleGetObject(String key)Gets an object for the given key from this resource bundle.voidlist(Writer out)Lists resources to the specified stream.StringtoString()Returns a string representation of this object.-
Methods inherited from class ResourceBundle
clearCache, clearCache, containsKey, getBaseBundleName, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, handleKeySet, keySet, setParent
-
-
-
-
Constructor Detail
-
IndexedResourceBundle
protected IndexedResourceBundle()
Constructs a new resource bundle. The resource filename will be inferred from the fully qualified classname of thisIndexedResourceBundlesubclass.
-
IndexedResourceBundle
protected IndexedResourceBundle(String filename)
Constructs a new resource bundle.- Parameters:
filename- The resource name containing resources. It may be a filename or an entry in a JAR file.
-
-
Method Detail
-
list
public final void list(Writer out) throws IOException
Lists resources to the specified stream. If a resource has more than one line, only the first line will be written. This method is used mostly for debugging purposes.- Parameters:
out- The destination stream.- Throws:
IOException- if an output operation failed.
-
getKeys
public final Enumeration<String> getKeys()
Returns an enumeration of the keys.- Specified by:
getKeysin classResourceBundle
-
handleGetObject
protected final Object handleGetObject(String key)
Gets an object for the given key from this resource bundle. Returns null if this resource bundle does not contain an object for the given key.- Specified by:
handleGetObjectin classResourceBundle- Parameters:
key- the key for the desired object- Returns:
- the object for the given key, or null
- Throws:
NullPointerException- ifkeyisnull
-
getMenuLabel
public final String getMenuLabel(int key) throws MissingResourceException
Gets a string for the given key and appends "..." to it. This method is typically used for creating menu items.- Parameters:
key- The key for the desired string.- Returns:
- The string for the given key.
- Throws:
MissingResourceException- If no object for the given key can be found.
-
getLabel
public final String getLabel(int key) throws MissingResourceException
Gets a string for the given key and appends ": " to it. This method is typically used for creating labels.- Parameters:
key- The key for the desired string.- Returns:
- The string for the given key.
- Throws:
MissingResourceException- If no object for the given key can be found.
-
getString
public final String getString(int key) throws MissingResourceException
Gets a string for the given key from this resource bundle or one of its parents.- Parameters:
key- The key for the desired string.- Returns:
- The string for the given key.
- Throws:
MissingResourceException- If no object for the given key can be found.
-
getString
public final String getString(int key, Object arg0) throws MissingResourceException
Gets a string for the given key and formats it with the specified argument. The message is formatted usingMessageFormat. Calling this method is approximately equivalent to calling:
IfString pattern = getString(key); Format f = new MessageFormat(pattern); return f.format(arg0);
arg0is not already an array, it will be placed into an array of length 1. UsingMessageFormat, all occurrences of "{0}", "{1}", "{2}" in the resource string will be replaced byarg0[0],arg0[1],arg0[2], etc.- Parameters:
key- The key for the desired string.arg0- A single object or an array of objects to be formatted and substituted.- Returns:
- The string for the given key.
- Throws:
MissingResourceException- If no object for the given key can be found.- See Also:
ResourceBundle.getString(String),getString(int,Object,Object),getString(int,Object,Object,Object),MessageFormat
-
getString
public final String getString(int key, Object arg0, Object arg1) throws MissingResourceException
Gets a string for the given key and replaces all occurrences of "{0}", "{1}", with values ofarg0,arg1, etc.- Parameters:
key- The key for the desired string.arg0- Value to substitute for "{0}".arg1- Value to substitute for "{1}".- Returns:
- The formatted string for the given key.
- Throws:
MissingResourceException- If no object for the given key can be found.
-
getString
public final String getString(int key, Object arg0, Object arg1, Object arg2) throws MissingResourceException
Gets a string for the given key and replaces all occurrences of "{0}", "{1}", with values ofarg0,arg1, etc.- Parameters:
key- The key for the desired string.arg0- Value to substitute for "{0}".arg1- Value to substitute for "{1}".arg2- Value to substitute for "{2}".- Returns:
- The formatted string for the given key.
- Throws:
MissingResourceException- If no object for the given key can be found.
-
getString
public final String getString(int key, Object arg0, Object arg1, Object arg2, Object arg3) throws MissingResourceException
Gets a string for the given key and replaces all occurrences of "{0}", "{1}", with values ofarg0,arg1, etc.- Parameters:
key- The key for the desired string.arg0- Value to substitute for "{0}".arg1- Value to substitute for "{1}".arg2- Value to substitute for "{2}".arg3- Value to substitute for "{3}".- Returns:
- The formatted string for the given key.
- Throws:
MissingResourceException- If no object for the given key can be found.
-
getString
public final String getString(int key, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4) throws MissingResourceException
Gets a string for the given key and replaces all occurrences of "{0}", "{1}", with values ofarg0,arg1, etc.- Parameters:
key- The key for the desired string.arg0- Value to substitute for "{0}".arg1- Value to substitute for "{1}".arg2- Value to substitute for "{2}".arg3- Value to substitute for "{3}".arg4- Value to substitute for "{4}".- Returns:
- The formatted string for the given key.
- Throws:
MissingResourceException- If no object for the given key can be found.
-
getLogRecord
public LogRecord getLogRecord(Level level, int key)
Gets a localized log record.- Parameters:
level- The log record level.key- The resource key.- Returns:
- The log record.
-
getLogRecord
public LogRecord getLogRecord(Level level, int key, Object arg0)
Gets a localized log record.- Parameters:
level- The log record level.key- The resource key.arg0- The parameter for the log message, ornull.- Returns:
- The log record.
-
getLogRecord
public LogRecord getLogRecord(Level level, int key, Object arg0, Object arg1)
Gets a localized log record.- Parameters:
level- The log record level.key- The resource key.arg0- The first parameter.arg1- The second parameter.- Returns:
- The log record.
-
getLogRecord
public LogRecord getLogRecord(Level level, int key, Object arg0, Object arg1, Object arg2)
Gets a localized log record.- Parameters:
level- The log record level.key- The resource key.arg0- The first parameter.arg1- The second parameter.arg2- The third parameter.- Returns:
- The log record.
-
getLogRecord
public LogRecord getLogRecord(Level level, int key, Object arg0, Object arg1, Object arg2, Object arg3)
Gets a localized log record.- Parameters:
level- The log record level.key- The resource key.arg0- The first parameter.arg1- The second parameter.arg2- The third parameter.arg3- The fourth parameter.- Returns:
- The log record.
-
format
public static String format(LogRecord record)
Localize and format the message string from a log record. This method performs a work similar toFormatter.formatMessage(java.util.logging.LogRecord), except that the work will be delegated togetString(int, Object)if the record resource bundle is an instance ofIndexedResourceBundle.- Parameters:
record- The log record to format.- Returns:
- The formatted message.
-
-