Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.opensymphony.xwork2.util
Class PropertiesReader

    java.lang.Object
      java.io.Reader
          java.io.BufferedReader
              java.io.LineNumberReader
                  com.opensymphony.xwork2.util.PropertiesReader

All Implemented Interfaces:
  Closeable, Readable

    public class PropertiesReader

extends LineNumberReader

This class is used to read properties lines. These lines do not terminate with new-line chars but rather when there is no backslash sign a the end of the line. This is used to concatenate multiple lines for readability. This class was pulled out of Jakarta Commons Configuration and Jakarta Commons Lang trunk revision 476093

Field Summary
`(package private) static String` | `COMMENT_CHARS` Constant for the supported comment characters.
`private List` | `commentLines` Stores the comment lines for the currently processed property.
`private char` | `delimiter` Stores the list delimiter character.
`private static int` | `HEX_RADIX` Constant for the radix of hex numbers.
`private String` | `propertyName` Stores the name of the last read property.
`private String` | `propertyValue` Stores the value of the last read property.
`private static char[]` | `SEPARATORS` The list of possible key/value separators
`private static int` | `UNICODE_LEN` Constant for the length of a unicode literal.
`private static char[]` | `WHITE_SPACE` The white space characters used as key/value separators.

Fields inherited from class java.io.Reader
`lock`

Constructor Summary
`PropertiesReader(Reader reader)` Constructor.
`PropertiesReader(Reader reader, char listDelimiter)` Creates a new instance of `PropertiesReader` and sets the underlaying reader and the list delimiter.

Method Summary
`private boolean` | `checkCombineLines(String line)` Checks if the passed in line should be combined with the following.
`boolean` | `contains(char[] array, char objectToFind)` Checks if the object is in the given array.
`List` | `getCommentLines()` Returns the comment lines that have been read for the last property.
`String` | `getPropertyName()` Returns the name of the last read property.
`String` | `getPropertyValue()` Returns the value of the last read property.
`(package private) boolean` | `isCommentLine(String line)` Tests whether a line is a comment, i.e. whether it starts with a comment character.
`boolean` | `nextProperty()` Parses the next property from the input stream and stores the found name and value in internal fields.
`private String[]` | `parseProperty(String line)` Parse a property line and return the key and the value in an array.
`String` | `readProperty()` Reads a property line.
`static String` | `unescapeJava(String str)` Unescapes any Java literals found in the `String`.
`protected static String` | `unescapeJava(String str, char delimiter)` Unescapes any Java literals found in the `String` to a `Writer`.
`static void` | `unescapeJava(Writer out, String str)` Unescapes any Java literals found in the `String` to a `Writer`.

Methods inherited from class java.io.LineNumberReader
`getLineNumber, mark, read, read, readLine, reset, setLineNumber, skip`

Methods inherited from class java.io.BufferedReader
`close, markSupported, ready`

Methods inherited from class java.io.Reader
`read, read`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### commentLines

    private List commentLines

  Stores the comment lines for the currently processed property.

### propertyName

    private String propertyName

  Stores the name of the last read property.

### propertyValue

    private String propertyValue

  Stores the value of the last read property.

### delimiter

    private char delimiter

  Stores the list delimiter character.

### COMMENT_CHARS

    static final String COMMENT_CHARS

  Constant for the supported comment characters.

  See Also:
    Constant Field Values

### HEX_RADIX

    private static final int HEX_RADIX

  Constant for the radix of hex numbers.

  See Also:
    Constant Field Values

### UNICODE_LEN

    private static final int UNICODE_LEN

  Constant for the length of a unicode literal.

  See Also:
    Constant Field Values

### SEPARATORS

    private static final char[] SEPARATORS

  The list of possible key/value separators

### WHITE_SPACE

    private static final char[] WHITE_SPACE

  The white space characters used as key/value separators.

Constructor Detail

### PropertiesReader

    public PropertiesReader(Reader reader)

  Constructor.

  Parameters:
    `reader` - A Reader.

### PropertiesReader

    public PropertiesReader(Reader reader,
                            char listDelimiter)

  Creates a new instance of `PropertiesReader` and sets the underlaying reader and the list delimiter.

  Parameters:
    `reader` - the reader
    `listDelimiter` - the list delimiter character
  Since:
    1.3

Method Detail

### isCommentLine

    boolean isCommentLine(String line)

  Tests whether a line is a comment, i.e. whether it starts with a comment character.

  Parameters:
    `line` - the line
  Returns:
    a flag if this is a comment line
  Since:
    1.3

### readProperty

    public String readProperty()
                        throws IOException

  Reads a property line. Returns null if Stream is at EOF. Concatenates lines ending with "\". Skips lines beginning with "#" or "!" and empty lines. The return value is a property definition (`<name>` = `<value>`)

  Returns:
    A string containing a property value or null
  Throws:
    `IOException` - in case of an I/O error

### nextProperty

    public boolean nextProperty()
                         throws IOException

  Parses the next property from the input stream and stores the found name and value in internal fields. These fields can be obtained using the provided getter methods. The return value indicates whether EOF was reached (false) or whether further properties are available (true).

  Returns:
    a flag if further properties are available
  Throws:
    `IOException` - if an error occurs
  Since:
    1.3

### getCommentLines

    public List getCommentLines()

  Returns the comment lines that have been read for the last property.

  Returns:
    the comment lines for the last property returned by `readProperty()`
  Since:
    1.3

### getPropertyName

    public String getPropertyName()

  Returns the name of the last read property. This method can be called after ``nextProperty()`` was invoked and its return value was true.

  Returns:
    the name of the last read property
  Since:
    1.3

### getPropertyValue

    public String getPropertyValue()

  Returns the value of the last read property. This method can be called after ``nextProperty()`` was invoked and its return value was true.

  Returns:
    the value of the last read property
  Since:
    1.3

### checkCombineLines

    private boolean checkCombineLines(String line)

  Checks if the passed in line should be combined with the following. This is true, if the line ends with an odd number of backslashes.

  Parameters:
    `line` - the line
  Returns:
    a flag if the lines should be combined

### parseProperty

    private String[] parseProperty(String line)

  Parse a property line and return the key and the value in an array.

  Parameters:
    `line` - the line to parse
  Returns:
    an array with the property's key and value
  Since:
    1.2

### unescapeJava

    protected static String unescapeJava(String str,
                                         char delimiter)

  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
    `delimiter` - the delimiter for multi-valued properties
  Returns:
    the processed string
  Throws:
    `IllegalArgumentException` - if the Writer is `null`

### contains

    public boolean contains(char[] array,
                            char objectToFind)

  Checks if the object is in the given array.

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

  Parameters:
    `array` - the array to search through
    `objectToFind` - the object to find
  Returns:
    `true` if the array contains the object

### unescapeJava

    public static String unescapeJava(String str)

  Unescapes any Java literals found in the `String`. For example, it will turn a sequence of `'\'` and `'n'` into a newline character, unless the `'\'` is preceded by another `'\'`.

  Parameters:
    `str` - the `String` to unescape, may be null
  Returns:
    a new unescaped `String`, `null` if null string input

### unescapeJava

    public static void unescapeJava(Writer out,
                                    String str)
                             throws IOException

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

  For example, it will turn a sequence of `'\'` and `'n'` into a newline character, unless the `'\'` is preceded by another `'\'`.

  A `null` string input has no effect.

  Parameters:
    `out` - the `Writer` used to output unescaped characters
    `str` - the `String` to unescape, may be null
  Throws:
    `IllegalArgumentException` - if the Writer is `null`
    `IOException` - if error occurs on underlying Writer

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2007 OpenSymphony. All Rights Reserved.