Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.edelbyte.util
Class UnixCfgParser  view UnixCfgParser download UnixCfgParser.java

java.lang.Object
  extended byorg.edelbyte.util.UnixCfgParser

public class UnixCfgParser
extends java.lang.Object

A basic Unix configuration file parser. The parser reads from a java.io.BufferedReader (or one of its subclasses) and returns a java.util.Properties object with the found key and value pairs. It is an alternative to the java.lang.Properties.load() method (which has some strange behavior).

More information can be found in the detailed description of the parse(java.io.BufferedReader) 55 method.


Field Summary
protected  boolean bBetweenCheckEnabled
          Field holding the activation status of the Between Check mechanism (default is false).
protected static java.lang.String COMMENT_TOKEN
          Constant holding the token used for the comment detection within the stream.
protected static java.lang.String CONTINUATION_TOKEN
          Constant holding the token used for the line continuation detection within the stream.
protected static java.lang.String EQUALS_TOKEN
          Constant holding the token used for the key and value pair separation within the stream.
protected  java.lang.String oBetweenBeginToken
          Field holding the token, which indicates the beginning of the key and value pairs part of the stream.
protected  java.lang.String oBetweenEndToken
          Field holding the token, which indicates the end of the key and value pairs part of the stream.
 
Constructor Summary
UnixCfgParser()
          Creates a new instance of this class.
 
Method Summary
 java.lang.String getBetweenBeginToken()
          Returns the token, which indicates the beginning of the key and value pairs part (from the oBetweenBeginToken 55 field).
 java.lang.String getBetweenEndToken()
          Returns the token, which indicates the end of the key and value pairs part (from the oBetweenEndToken 55 field).
 boolean isBetweenCheckEnabled()
          Returns true for the case, that the Between Check mechanism is active.

The Between Check mechanism ensures, that there are key and value pairs between the so called BetweenBegin and BetweenEnd tokens (see getBetweenBeginToken() 55 and getBetweenEndToken() 55 ) only.
 java.util.Properties parse(java.io.BufferedReader oReader)
          Reads key and value pairs from a java.io.BufferedReader (or one of its subclasses).

The parser reads the stream line wise using the readLine() method of the object given by the oReader parameter.
 void setBetweenBeginToken(java.lang.String oBetweenBeginToken)
          Set a alternative value for the BetweenBegin token, which is used by the Between Check mechanism.
 void setBetweenCheckEnabled(boolean bStatus)
          Enables or disables the Between Check mechanism while parsing the stream.

The Between Check mechanism ensures, that there are key and value pairs between the so called BetweenBegin and BetweenEnd tokens (see getBetweenBeginToken() 55 and getBetweenEndToken() 55 ) only.
 void setBetweenEndToken(java.lang.String oBetweenEndToken)
          Set a alternative value for the BetweenEnd token, which is used by the Between Check mechanism.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMENT_TOKEN

protected static final java.lang.String COMMENT_TOKEN
Constant holding the token used for the comment detection within the stream. ************************************************************************

See Also:
Constant Field Values

EQUALS_TOKEN

protected static final java.lang.String EQUALS_TOKEN
Constant holding the token used for the key and value pair separation within the stream. ************************************************************************

See Also:
Constant Field Values

CONTINUATION_TOKEN

protected static final java.lang.String CONTINUATION_TOKEN
Constant holding the token used for the line continuation detection within the stream. ************************************************************************

See Also:
Constant Field Values

oBetweenBeginToken

protected java.lang.String oBetweenBeginToken
Field holding the token, which indicates the beginning of the key and value pairs part of the stream. It is used for the Between Check mechanism. ************************************************************************


oBetweenEndToken

protected java.lang.String oBetweenEndToken
Field holding the token, which indicates the end of the key and value pairs part of the stream. It is used for the Between Check mechanism. ************************************************************************


bBetweenCheckEnabled

protected boolean bBetweenCheckEnabled
Field holding the activation status of the Between Check mechanism (default is false). ************************************************************************

Constructor Detail

UnixCfgParser

public UnixCfgParser()
Creates a new instance of this class. ************************************************************************

Method Detail

getBetweenBeginToken

public java.lang.String getBetweenBeginToken()
Returns the token, which indicates the beginning of the key and value pairs part (from the oBetweenBeginToken 55 field).


getBetweenEndToken

public java.lang.String getBetweenEndToken()
Returns the token, which indicates the end of the key and value pairs part (from the oBetweenEndToken 55 field).


isBetweenCheckEnabled

public boolean isBetweenCheckEnabled()
Returns true for the case, that the Between Check mechanism is active.

The Between Check mechanism ensures, that there are key and value pairs between the so called BetweenBegin and BetweenEnd tokens (see getBetweenBeginToken() 55 and getBetweenEndToken() 55 ) only.


parse

public java.util.Properties parse(java.io.BufferedReader oReader)
                           throws java.io.IOException,
                                  java.text.ParseException
Reads key and value pairs from a java.io.BufferedReader (or one of its subclasses).

The parser reads the stream line wise using the readLine() method of the object given by the oReader parameter. A line can hold up to one key and value pair. Everything after the first occurrence of "#" is interpreted as comment and therefore skipped. Lines containing tabs and blanks only are skipped as well. The first occurrence of "=" is interpreted as a delimiter separating key and value. After the separation of key and value, the key is converted to upper case. Lines ending with " \" (please notice the blank leading the backslash!) indicates a line continuation.

An sample configuration file is listed below:

##### Database configuration file for SAMPLE database

#BEGIN
Backup.Enabled = YES             ##### Backup allowed [YES|NO]
Backup.Rule.1  = (A > B) &&  \   ##### Backup rule number one
                 (C != D)
#END

For the given example, the returning java.util.Properties object contains the following key and value pairs:
  • The key is "BACKUP.ENABLED" and the associated value is "YES".
  • The key is "BACKUP.RULE.1" and the associated value is "(A > B) && (C != D)".


setBetweenBeginToken

public void setBetweenBeginToken(java.lang.String oBetweenBeginToken)
Set a alternative value for the BetweenBegin token, which is used by the Between Check mechanism.


setBetweenCheckEnabled

public void setBetweenCheckEnabled(boolean bStatus)
Enables or disables the Between Check mechanism while parsing the stream.

The Between Check mechanism ensures, that there are key and value pairs between the so called BetweenBegin and BetweenEnd tokens (see getBetweenBeginToken() 55 and getBetweenEndToken() 55 ) only.


setBetweenEndToken

public void setBetweenEndToken(java.lang.String oBetweenEndToken)
Set a alternative value for the BetweenEnd token, which is used by the Between Check mechanism.