com.internationalnetwork.util
Class ConfFile

Object
  extended by com.internationalnetwork.util.ConfFile

public class ConfFile
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
ConfFile(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

ConfFile

public ConfFile(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 ConfFile object:

      ConfFile ConfFile = new ConfFile("Canada.conf",
        new String[]{ "Directive", "regex=.+" },
        new String[]{ "", "regex=.+" },
        new String[]{ "Minimum", "int=1..100", "default=3" },
        new String[]{ "Maximum", "int=1..100", "default=8" }
      );
    

Directive parameters

default
The default value to return in place of a NULL object when this value isn't set by a directive within the configuration file.

regex
Regular Expression rule to use when matching the parameter format.

text
Any text.

int / long / short / byte / nybble
Numeric value.

hostname
RFC-compliant hostname.

ip
IP address.

path
Path, without a filename.

filename
Filename, with or without a path.

uri
RFC-compliant Universal Resource Identifier, such as web or FTP site addresses.

Parameters:
filename - Name (and path) of the configuration file to process (this file will be opened for reading, so read-only access to the specified file is all that is needed).
directives - String arrays that specify the details of the directive or container, and the parameters that may be specified within the configuration file. Any number of "directive parameters" may be specified, in the array, but the first string must contain the directive or container name.

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)