Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
Hashtable
org.apache.velocity.runtime.configuration.Configuration
public class Configuration
extends Hashtable
key = value
# lines starting with # are comments # This is the simplest property key = value # A long property may be separated on multiple lines longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa # This is a property with many tokens tokens_on_a_line = first token, second token # This sequence generates exactly the same result tokens_on_multiple_lines = first token tokens_on_multiple_lines = second token # commas may be escaped in tokens commas.excaped = Hi\, what'up?NOTE: this class has not been written for performance nor low memory usage. In fact, it's way slower than it could be and generates too much memory garbage. But since performance is not an issue during intialization (and there is not much time to improve it), I wrote it this way. If you don't like it, go ahead and tune it up!
Nested Class Summary | |
(package private) class |
|
(package private) class |
|
Field Summary | |
protected String |
|
private Configuration |
|
private ExtendedProperties | |
protected String |
|
protected String |
|
protected static String |
|
protected boolean |
|
protected ArrayList |
|
Constructor Summary | |
| |
| |
|
Method Summary | |
void |
|
private void |
|
void |
|
void |
|
static Configuration |
|
void |
|
boolean |
|
Boolean |
|
boolean |
|
byte |
|
Byte |
|
byte |
|
double |
|
Double |
|
double |
|
ExtendedProperties |
|
float |
|
Float |
|
float |
|
String |
|
int |
|
int |
|
int |
|
Integer |
|
int |
|
Iterator |
|
Iterator |
|
long |
|
Long |
|
long |
|
Properties |
|
Properties |
|
Object |
|
short |
|
Short |
|
short |
|
String |
|
String |
|
String[] |
|
Vector |
|
Vector |
|
private void |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
Configuration |
|
String |
|
protected String basePath
Base path of the configuration file used to create this Configuration object.
private ExtendedProperties deprecationCrutch
protected String file
The file connected to this repository (holding comments and such).
protected String fileSeparator
File separator.
protected static String include
This is the name of the property that can point to other properties file for including other properties files.
protected boolean isInitialized
Has this configuration been intialized.
protected ArrayList keysAsListed
These are the keys in the order they listed in the configuration file. This is useful when you wish to perform operations with configuration information in a particular order.
public Configuration()
Creates an empty extended properties object.
public Configuration(String file) throws IOException
Creates and loads the extended properties from the specified file.
- Parameters:
file
- A String.
public Configuration(String file, String defaultFile) throws IOException
Creates and loads the extended properties from the specified file.
- Parameters:
file
- A String.
public void addProperty(String key, Object token)
Add a property to the configuration. If it already exists then the value stated here will be added to the configuration entry. For example, if resource.loader = file is already present in the configuration and you addProperty("resource.loader", "classpath") Then you will end up with a Vector like the following: ["file", "classpath"]
- Parameters:
private void addStringProperty(String key, String token)
Sets a string property w/o checking for commas - used internally when a property has been broken up into strings that could contain escaped commas to prevent the inadvertant vectorization. Thanks to Leon Messerschmidt for this one.
public void clearProperty(String key)
Clear a property in the configuration.
- Parameters:
public void combine(Configuration c)
Combines an existing Hashtable with this Hashtable. Warning: It will overwrite previous entries without warning.
- Parameters:
public static Configuration convertProperties(Properties p)
Convert a standard properties class into a configuration class.
- Parameters:
- Returns:
- Configuration configuration created from the properties object.
public void display()
Display the configuration for debugging purposes.
public boolean getBoolean(String key)
Get a boolean associated with the given configuration key.
- Parameters:
key
- The configuration key.
- Returns:
- The associated boolean.
public Boolean getBoolean(String key, Boolean defaultValue)
Get a boolean associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated boolean if key is found and has valid format, default value otherwise.
public boolean getBoolean(String key, boolean defaultValue)
Get a boolean associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated boolean.
public byte getByte(String key)
Get a byte associated with the given configuration key.
- Parameters:
key
- The configuration key.
- Returns:
- The associated byte.
public Byte getByte(String key, Byte defaultValue)
Get a byte associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated byte if key is found and has valid format, default value otherwise.
public byte getByte(String key, byte defaultValue)
Get a byte associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated byte.
public double getDouble(String key)
Get a double associated with the given configuration key.
- Parameters:
key
- The configuration key.
- Returns:
- The associated double.
public Double getDouble(String key, Double defaultValue)
Get a double associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated double if key is found and has valid format, default value otherwise.
public double getDouble(String key, double defaultValue)
Get a double associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated double.
public ExtendedProperties getExtendedProperties()
Deprecated. Do not use. For deprecation assistance only.
Routine intended for deprecation period only as we switch from using the Configuration class in Velocity to the Jakarta Commons ExtendedProperties Do not use this for general use. It will disappear
- Returns:
- ExtendedProperties containing data of Configuration
public float getFloat(String key)
Get a float associated with the given configuration key.
- Parameters:
key
- The configuration key.
- Returns:
- The associated float.
public Float getFloat(String key, Float defaultValue)
Get a float associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated float if key is found and has valid format, default value otherwise.
public float getFloat(String key, float defaultValue)
Get a float associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated float.
public String getInclude()
Gets the property value for including other properties files. By default it is "include".
- Returns:
- A String.
public int getInt(String name)
The purpose of this method is to get the configuration resource with the given name as an integer.
- Parameters:
name
- The resource name.
- Returns:
- The value of the resource as an integer.
public int getInt(String name, int def)
The purpose of this method is to get the configuration resource with the given name as an integer, or a default value.
- Parameters:
name
- The resource namedef
- The default value of the resource.
- Returns:
- The value of the resource as an integer.
public int getInteger(String key)
Get a int associated with the given configuration key.
- Parameters:
key
- The configuration key.
- Returns:
- The associated int.
public Integer getInteger(String key, Integer defaultValue)
Get a int associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated int if key is found and has valid format, default value otherwise.
public int getInteger(String key, int defaultValue)
Get a int associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated int.
public Iterator getKeys()
Get the list of the keys contained in the configuration repository.
- Returns:
- An Iterator.
public Iterator getKeys(String prefix)
Get the list of the keys contained in the configuration repository that match the specified prefix.
- Parameters:
prefix
- The prefix to test against.
- Returns:
- An Iterator of keys that match the prefix.
public long getLong(String key)
Get a long associated with the given configuration key.
- Parameters:
key
- The configuration key.
- Returns:
- The associated long.
public Long getLong(String key, Long defaultValue)
Get a long associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated long if key is found and has valid format, default value otherwise.
public long getLong(String key, long defaultValue)
Get a long associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated long.
public Properties getProperties(String key)
Get a list of properties associated with the given configuration key.
- Parameters:
key
- The configuration key.
- Returns:
- The associated properties if key is found.
public Properties getProperties(String key, Properties defaults)
Get a list of properties associated with the given configuration key.
- Parameters:
key
- The configuration key.
- Returns:
- The associated properties if key is found.
public Object getProperty(String key)
Gets a property from the configuration.
- Parameters:
key
- property to retrieve
- Returns:
- value as object. Will return user value if exists, if not then default value if exists, otherwise null
public short getShort(String key)
Get a short associated with the given configuration key.
- Parameters:
key
- The configuration key.
- Returns:
- The associated short.
public Short getShort(String key, Short defaultValue)
Get a short associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated short if key is found and has valid format, default value otherwise.
public short getShort(String key, short defaultValue)
Get a short associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated short.
public String getString(String key)
Get a string associated with the given configuration key.
- Parameters:
key
- The configuration key.
- Returns:
- The associated string.
public String getString(String key, String defaultValue)
Get a string associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated string if key is found, default value otherwise.
public String[] getStringArray(String key)
Get an array of strings associated with the given configuration key.
- Parameters:
key
- The configuration key.
- Returns:
- The associated string array if key is found.
public Vector getVector(String key)
Get a Vector of strings associated with the given configuration key.
- Parameters:
key
- The configuration key.
- Returns:
- The associated Vector.
public Vector getVector(String key, Vector defaultValue)
Get a Vector of strings associated with the given configuration key.
- Parameters:
key
- The configuration key.defaultValue
- The default value.
- Returns:
- The associated Vector.
private void init(Configuration exp) throws IOException
Private initializer method that sets up the generic resources.
public boolean isInitialized()
Indicate to client code whether property resources have been initialized or not.
public void load(InputStream input) throws IOException
Load the properties from the given input stream.
- Parameters:
input
- An InputStream.
public void save(OutputStream output, String Header) throws IOException
Save the properties to the given outputstream.
- Parameters:
output
- An OutputStream.
public void setInclude(String inc)
Sets the property value for including other properties files. By default it is "include".
- Parameters:
inc
- A String.
public void setProperty(String key, Object value)
Set a property, this will replace any previously set values. Set values is implicitly a call to clearProperty(key), addProperty(key,value).
- Parameters:
public Configuration subset(String prefix)
Create a Configurations object that is a subset of this one. Take into account duplicate keys by using the setProperty() in Configuration.
- Parameters:
public String testBoolean(String value)
Test whether the string represent by value maps to a boolean value or not. We will allowtrue
,on
, andyes
for atrue
boolean value, andfalse
,off
, andno
forfalse
boolean values. Case of value to test for boolean status is ignored.
- Parameters:
- Returns:
true
orfalse
if the supplied text maps to a boolean value, ornull
otherwise.