org.apache.tapestry.util.text
Class LocalizedProperties

java.lang.Object
  extended by org.apache.tapestry.util.text.LocalizedProperties

public class LocalizedProperties
extends Object

A version of java.util.Properties that can read the properties from files using an encoding other than ISO-8859-1. All non-latin characters are read correctly using the given encoding and no longer need to be quoted using native2ascii. In addition, the properties may be stored in an arbitrary map, rather than only in Properties. For example, using LinkedHashMap will preserve the order of the properties as defined in the file.

Since:
4.0
Author:
mb

Constructor Summary
LocalizedProperties()
          Create a new object with an empty property storage.
LocalizedProperties(Map propertyMap)
          Use the provided argument as the storage location for the properties managed by this object.
 
Method Summary
 String getProperty(String key)
          Returns the property value corresponding the provided key.
 String getProperty(String key, String defaultValue)
          Returns the property value corresponding to the provided key, or the provided default value if no such property exists.
 Map getPropertyMap()
          Returns the map containing all properties.
 void load(InputStream ins)
          Loads the properties from the given stream using the default character encoding.
 void load(InputStream ins, String encoding)
          Loads the properties from the given stream using the provided character encoding.
 void load(Reader reader)
          Loads the properties from the given reader.
 void setProperty(String key, String value)
          Stores a property value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalizedProperties

public LocalizedProperties()
Create a new object with an empty property storage.


LocalizedProperties

public LocalizedProperties(Map propertyMap)
Use the provided argument as the storage location for the properties managed by this object. This allows different types of Map implementations to be used, such as a LinkedHashMap to preserve the order of the keys, for example. The provided map may contain the default property values as well.

Parameters:
propertyMap - the map where properties are to be stored
Method Detail

getProperty

public String getProperty(String key)
Returns the property value corresponding the provided key. If there is no such property, or the value in the provided map is not of type String, null is returned.

Parameters:
key - the property key
Returns:
the value of the property, or null if there is no such property

getProperty

public String getProperty(String key,
                          String defaultValue)
Returns the property value corresponding to the provided key, or the provided default value if no such property exists.

Parameters:
key - the property key
defaultValue - the default value of the property
Returns:
the value of the property, or the default value if there is no such property

setProperty

public void setProperty(String key,
                        String value)
Stores a property value.

Parameters:
key - the property key
value - the property value

getPropertyMap

public Map getPropertyMap()
Returns the map containing all properties. The map can be used to enumerate the properties or their keys.

Returns:
a map containing the properties

load

public void load(InputStream ins)
          throws IOException
Loads the properties from the given stream using the default character encoding. This method operates in the same way as the equivalent method in Properties, but it also handles non-ascii symbols.

Parameters:
ins - the stream to load the properties from
Throws:
IOException

load

public void load(InputStream ins,
                 String encoding)
          throws IOException
Loads the properties from the given stream using the provided character encoding. This method operates in the same way as the equivalent method in Properties, but it also handles non-ascii symbols.

Parameters:
ins - the stream to load the properties from
encoding - the encoding the use when parsing the stream
Throws:
IOException

load

public void load(Reader reader)
          throws IOException
Loads the properties from the given reader. This method operates in the same way as the equivalent method in Properties, but it also handles non-ascii symbols.

Parameters:
reader - the reader to load the properties from
Throws:
IOException


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.