|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Dictionary
java.util.Hashtable
java.util.Properties
com.taco.util.MultiLineProperties
public class MultiLineProperties
A subclass of java.util.Properties
that allows a slightly
more user-friendly syntax. If a property value is a C-like expression, it
may span multiple lines, without the '\' at the end of each line, provided
that the expression has not closed all parenthesis, quotes, etc. This
allows values that are BeanShell expressions in particular to be much
easier to write.
Also, if '\' is the last non-whitespace character on a line, it is
treated as a line continuation marker. This differs from
java.util.Properties
in which it must be the last character on
a line; whitespace afterward invalidates its interpretation as a line
continuation marker. In practice, this is quite annoying.
Finally, comments can be associated with each key/value pair. When reading a .properties file, instances of this class associate comments with the key/value pair below it. These comments can be retrieved and set by the user. When a .properties file is written out by this class, if a key/value pair has a comment associated with it, it will be written out before the definition of the property. Thus comments are more or less preserved during the process of reading a .properties file and writing it back out again.
One other deficiency with Properties
is fixed by this
class. Properties
extends Hashtable
and uses the
hash table to store its mappings. This results in randomly ordered
mappings, so key/value pairs are stored and output in a totally different
order than read in. To correct this problem, this class uses a
LinkedHashMap
to store mappings, which keeps the mappings in
insertion order. Thus keys()
,
keySet().iterator()
, entrySet().iterator()
, and
elements()
, values().iterator()
return iterators
that iterate over the mappings in the same order as they appeared in the
.properties file. store()
outputs the mappings in the same
order.
Warning: unlike Properties
, this class is not synchronized.
This is so a resource bundle backed by an instance of this class doesn't
need to copy the mappings or make synchronized calls to this instance.
Instead, a resource bundle backed by an instance of this class can make
calls to this class without any synchronization penalty.
Field Summary | |
---|---|
protected static java.lang.String |
_ASSIGNMENT_CHARS
All characters used explicitly to denote an assignment operation between keys and values. |
protected static java.lang.String |
_COMMENT_CHARS
All characters that mark the beginning of single line comments. |
protected java.util.Map |
_commentMap
A map that holds the comments for each property key. |
protected static java.util.regex.Pattern |
_KEY_ASSIGNMENT_PATTERN
The pattern to match for a key assignment. |
protected static java.lang.String |
_KEY_CHARS_TO_ESCAPE
Characters in a property key to escape with a backslash before output. |
protected static java.util.regex.Pattern |
_LINE_END_PATTERN
|
protected static java.lang.String |
_LINE_SEPARATOR
The system-dependent line separator. |
protected java.util.Map |
_propertyMap
A map that holds the properties in the same order as read in. |
protected static java.lang.String |
_SPACE_CHARS
|
protected static java.lang.String |
_VALUE_CHARS_TO_ESCAPE
Characters in a property value to escape with a backslash before output. |
Fields inherited from class java.util.Properties |
---|
defaults |
Constructor Summary | |
---|---|
MultiLineProperties()
Construct a new instance that has no mappings. |
|
MultiLineProperties(java.util.Properties defaults)
Construct a new instance that has the same mappings as defaults . |
Method Summary | |
---|---|
protected java.lang.String |
_commentChars()
Return a string consisting of all characters used to mark the beginning of single line comments. |
protected java.lang.String |
_formatComment(java.lang.CharSequence comment)
Convert a comment (just ordinary text) into text that can actually be put into a .properties file. |
protected java.lang.String |
_keyCharsToEscape()
Return a string consisting of all characters in a property key that need to be escaped with a backslash before being output. |
protected java.lang.String |
_valueCharsToEscape()
Return a string consisting of all characters in a property value that need to be escaped with a backslash before being output. |
void |
clear()
|
java.lang.Object |
clone()
|
boolean |
contains(java.lang.Object value)
|
boolean |
containsKey(java.lang.Object a0)
|
boolean |
containsValue(java.lang.Object a0)
|
java.util.Enumeration |
elements()
|
java.util.Set |
entrySet()
|
java.lang.Object |
get(java.lang.Object a0)
|
java.lang.String |
getCommentForProperty(java.lang.String propertyName)
Return the comments in the .properties file that appeared just before the definition of the property with the argument name. |
boolean |
isEmpty()
|
java.util.Enumeration |
keys()
|
java.util.Set |
keySet()
|
void |
load(java.io.InputStream inputStream)
|
static void |
main(java.lang.String[] args)
A simple test program. |
java.lang.Object |
put(java.lang.Object a0,
java.lang.Object a1)
|
void |
putAll(java.util.Map a0)
|
java.lang.Object |
remove(java.lang.Object a0)
|
void |
setCommentForProperty(java.lang.String propertyName,
java.lang.String comment)
Set the comment associated with the property with argument name. |
int |
size()
|
void |
store(java.io.OutputStream outputStream,
java.lang.String header)
|
static void |
usage()
|
java.util.Collection |
values()
|
Methods inherited from class java.util.Properties |
---|
getProperty, getProperty, list, list, loadFromXML, propertyNames, save, setProperty, storeToXML, storeToXML |
Methods inherited from class java.util.Hashtable |
---|
equals, hashCode, rehash, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.Map _propertyMap
protected java.util.Map _commentMap
protected static final java.lang.String _COMMENT_CHARS
protected static final java.lang.String _ASSIGNMENT_CHARS
protected static final java.lang.String _SPACE_CHARS
protected static final java.util.regex.Pattern _KEY_ASSIGNMENT_PATTERN
protected static final java.util.regex.Pattern _LINE_END_PATTERN
protected static final java.lang.String _VALUE_CHARS_TO_ESCAPE
protected static final java.lang.String _KEY_CHARS_TO_ESCAPE
protected static final java.lang.String _LINE_SEPARATOR
Constructor Detail |
---|
public MultiLineProperties()
public MultiLineProperties(java.util.Properties defaults)
defaults
.
Method Detail |
---|
public java.lang.Object put(java.lang.Object a0, java.lang.Object a1)
put
in interface java.util.Map
put
in class java.util.Hashtable
public java.lang.Object get(java.lang.Object a0)
get
in interface java.util.Map
get
in class java.util.Hashtable
public int size()
size
in interface java.util.Map
size
in class java.util.Hashtable
public java.util.Collection values()
values
in interface java.util.Map
values
in class java.util.Hashtable
public java.lang.Object remove(java.lang.Object a0)
remove
in interface java.util.Map
remove
in class java.util.Hashtable
public void clear()
clear
in interface java.util.Map
clear
in class java.util.Hashtable
public boolean containsKey(java.lang.Object a0)
containsKey
in interface java.util.Map
containsKey
in class java.util.Hashtable
public boolean containsValue(java.lang.Object a0)
containsValue
in interface java.util.Map
containsValue
in class java.util.Hashtable
public java.util.Set entrySet()
entrySet
in interface java.util.Map
entrySet
in class java.util.Hashtable
public boolean isEmpty()
isEmpty
in interface java.util.Map
isEmpty
in class java.util.Hashtable
public java.util.Set keySet()
keySet
in interface java.util.Map
keySet
in class java.util.Hashtable
public void putAll(java.util.Map a0)
putAll
in interface java.util.Map
putAll
in class java.util.Hashtable
public java.lang.Object clone()
clone
in class java.util.Hashtable
public boolean contains(java.lang.Object value)
contains
in class java.util.Hashtable
public java.util.Enumeration elements()
elements
in class java.util.Hashtable
public java.util.Enumeration keys()
keys
in class java.util.Hashtable
public void load(java.io.InputStream inputStream) throws java.io.IOException
load
in class java.util.Properties
java.io.IOException
public void store(java.io.OutputStream outputStream, java.lang.String header) throws java.io.IOException
store
in class java.util.Properties
java.io.IOException
public static void usage()
public static void main(java.lang.String[] args)
protected java.lang.String _formatComment(java.lang.CharSequence comment)
Convert a comment (just ordinary text) into text that can actually be put into a .properties file.
This implementation simply puts a '#' character in front of each line. The contents of each line and number of lines are unchanged.
public java.lang.String getCommentForProperty(java.lang.String propertyName)
public void setCommentForProperty(java.lang.String propertyName, java.lang.String comment)
protected java.lang.String _commentChars()
_COMMENT_CHARS
.
protected java.lang.String _keyCharsToEscape()
_KEY_CHARS_TO_ESCAPE
.
protected java.lang.String _valueCharsToEscape()
_VALUE_CHARS_TO_ESCAPE
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |