org.apache.felix.utils.properties
Class Properties

java.lang.Object
  extended by java.util.AbstractMap<String,String>
      extended by org.apache.felix.utils.properties.Properties
All Implemented Interfaces:
Map<String,String>

public class Properties
extends AbstractMap<String,String>

Enhancement of the standard Properties managing the maintain of comments, etc.

Author:
gnodet, jbonofre

Nested Class Summary
protected static class Properties.Layout
          TODO
static class Properties.PropertiesReader
          This class is used to read properties lines.
static class Properties.PropertiesWriter
          This class is used to write properties lines.
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
Properties()
           
Properties(File location)
           
 
Method Summary
 void clear()
           
static boolean contains(char[] array, char valueToFind)
          Checks if the value is in the given array.
 Set<Map.Entry<String,String>> entrySet()
           
protected static String escapeJava(String str)
          Escapes the characters in a String using Java String rules.
 List<String> getFooter()
          Return the comment footer.
 List<String> getHeader()
          Return the comment header.
protected static String hex(char ch)
          Returns an upper case hexadecimal String for the given character.
 void load(File location)
           
 void load(InputStream is)
           
 void load(Reader reader)
           
 void load(URL location)
           
protected  void loadLayout(Reader in)
          Reads a properties file and stores its internal structure.
 String put(String key, String value)
           
 String remove(Object key)
           
 void save()
           
 void save(File location)
           
 void save(OutputStream os)
           
 void save(Writer writer)
           
protected  void saveLayout(Writer out)
          Writes the properties file to the given writer, preserving as much of its structure as possible.
 void setFooter(List<String> footer)
          Set the comment footer.
 void setHeader(List<String> header)
          Set the comment header.
protected static String unescapeJava(String str)
          Unescapes any Java literals found in the String to a Writer.
 
Methods inherited from class java.util.AbstractMap
clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Properties

public Properties()

Properties

public Properties(File location)
           throws IOException
Throws:
IOException
Method Detail

load

public void load(File location)
          throws IOException
Throws:
IOException

load

public void load(URL location)
          throws IOException
Throws:
IOException

load

public void load(InputStream is)
          throws IOException
Throws:
IOException

load

public void load(Reader reader)
          throws IOException
Throws:
IOException

save

public void save()
          throws IOException
Throws:
IOException

save

public void save(File location)
          throws IOException
Throws:
IOException

save

public void save(OutputStream os)
          throws IOException
Throws:
IOException

save

public void save(Writer writer)
          throws IOException
Throws:
IOException

entrySet

public Set<Map.Entry<String,String>> entrySet()
Specified by:
entrySet in interface Map<String,String>
Specified by:
entrySet in class AbstractMap<String,String>

put

public String put(String key,
                  String value)
Specified by:
put in interface Map<String,String>
Overrides:
put in class AbstractMap<String,String>

remove

public String remove(Object key)
Specified by:
remove in interface Map<String,String>
Overrides:
remove in class AbstractMap<String,String>

clear

public void clear()
Specified by:
clear in interface Map<String,String>
Overrides:
clear in class AbstractMap<String,String>

getHeader

public List<String> getHeader()
Return the comment header.

Returns:
the comment header

setHeader

public void setHeader(List<String> header)
Set the comment header.

Parameters:
header - the header to use

getFooter

public List<String> getFooter()
Return the comment footer.

Returns:
the comment footer

setFooter

public void setFooter(List<String> footer)
Set the comment footer.

Parameters:
footer - the footer to use

loadLayout

protected void loadLayout(Reader in)
                   throws IOException
Reads a properties file and stores its internal structure. The found properties will be added to the associated configuration object.

Parameters:
in - the reader to the properties file
Throws:
IOException - if an error occurs

saveLayout

protected void saveLayout(Writer out)
                   throws IOException
Writes the properties file to the given writer, preserving as much of its structure as possible.

Parameters:
out - the writer
Throws:
IOException - if an error occurs

unescapeJava

protected static String unescapeJava(String str)

Unescapes any Java literals found in the String to a Writer.

This is a slightly modified version of the StringEscapeUtils.unescapeJava() function in commons-lang that doesn't drop escaped separators (i.e '\,').

Parameters:
str - the String to unescape, may be null
Returns:
the processed string
Throws:
IllegalArgumentException - if the Writer is null

escapeJava

protected static String escapeJava(String str)

Escapes the characters in a String using Java String rules.

Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)

So a tab becomes the characters '\\' and 't'.

The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote must be escaped.

Example:

 input string: He didn't say, "Stop!"
 output string: He didn't say, \"Stop!\"
 

Parameters:
str - String to escape values in, may be null
Returns:
String with escaped values, null if null string input

hex

protected static String hex(char ch)

Returns an upper case hexadecimal String for the given character.

Parameters:
ch - The character to convert.
Returns:
An upper case hexadecimal String

contains

public static boolean contains(char[] array,
                               char valueToFind)

Checks if the value is in the given array.

The method returns false if a null array is passed in.

Parameters:
array - the array to search through
valueToFind - the value to find
Returns:
true if the array contains the object


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