com.internationalnetwork.util
Class ReadConfFile

Object
  extended by com.internationalnetwork.util.ReadConfFile

public class ReadConfFile
extends Object

Reads a simple Apache-HTTPd format ".conf" file and provides a HashMap containing the Directives and their associated, unparsed values. At this time, Containers are not yet supported.


Field Summary
static String VERSION
          Version number of this Package (read-only).
 
Constructor Summary
ReadConfFile(String filename, String... directives)
          Processes the specified configuration file.
 
Method Summary
 String get(String directive)
          Returns the value associated with the specified Directive name.
 String get(String directive, int index)
          Returns the value associated with the specified Directive name.
 String[] getDirectives()
          Returns a list of directives that are currently set.
 long getLineNumber()
          Returns the most recently processed line number.
 String[] getLinePair()
          Returns the most recently processed directive and value String pair.
 String[] toArray(String directive)
          Returns the String array[] associated with the specified directive.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Version number of this Package (read-only).

See Also:
Constant Field Values
Constructor Detail

ReadConfFile

public ReadConfFile(String filename,
                    String... directives)
             throws java.io.FileNotFoundException,
                    java.io.IOException,
                    IllegalArgumentException
Processes the specified configuration file. This method may be called more than once to combine multiple configuration files.

Here is an example of how to instantiate a ReadConfFile object:

      ReadConfFile readConfFile = new ReadConfFile("canada.conf",
        "Directive=.+", null,
        "=.+",
        "Minimum=\\d+", "3",
        "Maximum=\\d+", "8");
    

Parameters:
filename - Name (and path) of the configuration file to process
directives - Pairs of strings, the first one being a Directive that is permitted, along with the Regular Expression that specifies the matching rule (the format of this first string is "Directive=RegEx"). The second string in the pair defines the default value (if not NULL), which will be set internally at the root level so that later queries for it will return this value instead of NULL.

Any directive name that is enclosed with "<" and ">" characters is a container, and does not have a default value (it is a single entity, and cannot have a default or NULL value specified with it).

The order in which the directive definitions are provided is irrelevant, but it is important to note that no duplicates are permitted; a Directive and a Container name may be identical though, and will be treated entirely separate from one-another.

Throws:
java.io.FileNotFoundException - if the file specified cannot be opened
java.io.IOException - if an error occurs while reading the file
IllegalArgumentException - if an invalid or duplicate Directive is encountered
Method Detail

get

public String get(String directive)
Returns the value associated with the specified Directive name.

Parameters:
directive - Directive name
Returns:
String Value (null = directive not found)

get

public String get(String directive,
                  int index)
Returns the value associated with the specified Directive name.

Parameters:
directive - Directive name
index - Specific value number to obtain
Returns:
String Value (null = directive not found)

getDirectives

public String[] getDirectives()
Returns a list of directives that are currently set.

The following example code illustrates how to obtain a list of directives that have been set, and display each with their associated value.

Returns:
String[] Directives (null = none defined)

getLineNumber

public long getLineNumber()
Returns the most recently processed line number.

Returns:
long Current line number

getLinePair

public String[] getLinePair()
Returns the most recently processed directive and value String pair.

Returns:
String[] A two-element String array containg the Directive, and its Value (unparsed), respectively

toArray

public String[] toArray(String directive)
Returns the String array[] associated with the specified directive.

Parameters:
directive - Name of directive
Returns:
String[] Value (null = directive not found)