org.jagatoo.util.ini
Class AbstractIniParser

java.lang.Object
  extended by org.jagatoo.util.ini.AbstractIniParser

public abstract class AbstractIniParser
extends java.lang.Object

The AbstractIniParser parses ini files ;).

Author:
Marvin Froehlich (aka Qudus)

Field Summary
static java.lang.String DEFAULT_OPERATOR
           
 
Constructor Summary
protected AbstractIniParser()
          Creates a new AbstractIniParser.
 
Method Summary
protected  boolean acceptMissingTrailingQuote()
          Override this method and return true to accept a missing trailing (double-)quote as a correct line.
protected  boolean handleParsingException(int lineNr, java.lang.String group, java.lang.String line, java.lang.Throwable t)
          This method is called when an illigal line was detected.
protected  boolean onCommentParsed(int lineNr, java.lang.String group, java.lang.String comment)
          This method is invoked, when a standalone comment line has been found.
protected  boolean onEmptyLineParsed(int lineNr, java.lang.String group)
          This method is invoked, when an empty line has been found.
protected  boolean onGroupParsed(int lineNr, java.lang.String group)
          This method is invoked, when a new group has been found.
protected  void onParsingFinished()
          This method is invoked when the parsing of the file as been finished.
protected abstract  boolean onSettingParsed(int lineNr, java.lang.String group, java.lang.String key, java.lang.String value, java.lang.String comment)
          This method is invoked, when a new setting has been found.
 void parse(java.io.File file)
          Parses the given file.
 void parse(java.io.File file, java.nio.charset.Charset charset)
          Parses the given file.
 void parse(java.io.File file, java.lang.String charset)
          Parses the given file.
 void parse(java.io.InputStream in)
          Parses the given file.
 void parse(java.io.InputStream in, java.nio.charset.Charset charset)
          Parses the given file.
 void parse(java.io.InputStream in, java.lang.String charset)
          Parses the given file.
 void parse(java.lang.String filename)
          Parses the given file.
 void parse(java.lang.String filename, java.nio.charset.Charset charset)
          Parses the given file.
 void parse(java.lang.String filename, java.lang.String charset)
          Parses the given file.
 void parse(java.net.URL url)
          Parses the given file.
 void parse(java.net.URL url, java.nio.charset.Charset charset)
          Parses the given file.
 void parse(java.net.URL url, java.lang.String charset)
          Parses the given file.
protected  void parseImpl(java.io.InputStream in, java.lang.String codepage, java.nio.charset.Charset charset)
          Parses the given file.
static java.lang.String parseIniValue(java.io.File file, java.nio.charset.Charset charset, java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Parses a single value from the given ini file.
static java.lang.String parseIniValue(java.io.File file, java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Parses a single value from the given ini file.
static java.lang.String parseIniValue(java.io.File file, java.lang.String charset, java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Parses a single value from the given ini file.
static java.lang.String parseIniValue(java.io.InputStream in, java.nio.charset.Charset charset, java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Parses a single value from the given ini file.
static java.lang.String parseIniValue(java.io.InputStream in, java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Parses a single value from the given ini file.
static java.lang.String parseIniValue(java.io.InputStream in, java.lang.String charset, java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Parses a single value from the given ini file.
static java.lang.String parseIniValue(java.lang.String filename, java.nio.charset.Charset charset, java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Parses a single value from the given ini file.
static java.lang.String parseIniValue(java.lang.String filename, java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Parses a single value from the given ini file.
static java.lang.String parseIniValue(java.lang.String filename, java.lang.String charset, java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Parses a single value from the given ini file.
static java.lang.String parseIniValue(java.net.URL url, java.nio.charset.Charset charset, java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Parses a single value from the given ini file.
static java.lang.String parseIniValue(java.net.URL url, java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Parses a single value from the given ini file.
static java.lang.String parseIniValue(java.net.URL url, java.lang.String charset, java.lang.String group, java.lang.String key, java.lang.String defaultValue)
          Parses a single value from the given ini file.
protected  boolean parseLine(int lineNr, java.lang.String currentGroup, java.lang.String line)
          Parses the given line.
static boolean parseLine(int lineNr, java.lang.String currentGroup, java.lang.String line, java.lang.String operator, IniLine iniLine, AbstractIniParser handler)
          Parses the given line.
static java.lang.String tryToParseGroup(int lineNr, java.lang.String line)
          Parses the given line (must be trimmed).
static java.lang.String tryToParseGroup(java.lang.String line)
          Parses the given line (must be trimmed).
protected  boolean verifyIllegalLine(int lineNr, java.lang.String group, java.lang.String line)
          This method is called when an illigal line was detected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_OPERATOR

public static final java.lang.String DEFAULT_OPERATOR
See Also:
Constant Field Values
Constructor Detail

AbstractIniParser

protected AbstractIniParser()
Creates a new AbstractIniParser.

Method Detail

onEmptyLineParsed

protected boolean onEmptyLineParsed(int lineNr,
                                    java.lang.String group)
                             throws ParsingException
This method is invoked, when an empty line has been found.

Parameters:
lineNr -
group -
Returns:
true, to indicate, that parsing should be proceeded, false to stop parsing.
Throws:
ParsingException

onCommentParsed

protected boolean onCommentParsed(int lineNr,
                                  java.lang.String group,
                                  java.lang.String comment)
                           throws ParsingException
This method is invoked, when a standalone comment line has been found.

Parameters:
lineNr -
group -
comment -
Returns:
true, to indicate, that parsing should be proceeded, false to stop parsing.
Throws:
ParsingException

onGroupParsed

protected boolean onGroupParsed(int lineNr,
                                java.lang.String group)
                         throws ParsingException
This method is invoked, when a new group has been found.

Parameters:
lineNr -
group -
Returns:
true, to indicate, that parsing should be proceeded, false to stop parsing.
Throws:
ParsingException

onSettingParsed

protected abstract boolean onSettingParsed(int lineNr,
                                           java.lang.String group,
                                           java.lang.String key,
                                           java.lang.String value,
                                           java.lang.String comment)
                                    throws ParsingException
This method is invoked, when a new setting has been found.

Parameters:
lineNr -
group -
key -
value -
comment - the comment behind the value. (can be null)
Returns:
true, to indicate, that parsing should be proceeded, false to stop parsing.
Throws:
ParsingException

acceptMissingTrailingQuote

protected boolean acceptMissingTrailingQuote()
Override this method and return true to accept a missing trailing (double-)quote as a correct line.

Returns:
true to accept lines like that.

verifyIllegalLine

protected boolean verifyIllegalLine(int lineNr,
                                    java.lang.String group,
                                    java.lang.String line)
                             throws ParsingException
This method is called when an illigal line was detected.

Parameters:
lineNr -
group -
line -
Returns:
true, if this line was handled, false otherwise
Throws:
ParsingException

handleParsingException

protected boolean handleParsingException(int lineNr,
                                         java.lang.String group,
                                         java.lang.String line,
                                         java.lang.Throwable t)
                                  throws ParsingException
This method is called when an illigal line was detected.

Parameters:
lineNr -
group -
line -
t -
Returns:
true, to indicate, that parsing should be proceeded, false to stop parsing.
Throws:
ParsingException

onParsingFinished

protected void onParsingFinished()
This method is invoked when the parsing of the file as been finished.


tryToParseGroup

public static java.lang.String tryToParseGroup(int lineNr,
                                               java.lang.String line)
                                        throws ParsingException
Parses the given line (must be trimmed). If it is a group header, the group name is returned, null otherwise.

Parameters:
lineNr -
line -
Returns:
the group name, if the given line is a group name, null otherwise.
Throws:
ParsingException

tryToParseGroup

public static java.lang.String tryToParseGroup(java.lang.String line)
                                        throws ParsingException
Parses the given line (must be trimmed). If it is a group header, the group name is returned, null otherwise.

Parameters:
line -
Returns:
the group name, if the given line is a group name, null otherwise.
Throws:
ParsingException

parseLine

public static boolean parseLine(int lineNr,
                                java.lang.String currentGroup,
                                java.lang.String line,
                                java.lang.String operator,
                                IniLine iniLine,
                                AbstractIniParser handler)
                         throws java.io.IOException,
                                ParsingException
Parses the given line.
This method implements the actual parsing code for a single line.

Parameters:
lineNr -
currentGroup -
line -
operator -
iniLine -
handler -
Returns:
success?
Throws:
java.io.IOException
ParsingException

parseLine

protected boolean parseLine(int lineNr,
                            java.lang.String currentGroup,
                            java.lang.String line)
                     throws java.io.IOException,
                            ParsingException
Parses the given line.
This method implements the actual parsing code for a single line.

Parameters:
lineNr -
currentGroup -
line -
Returns:
success?
Throws:
java.io.IOException
ParsingException

parseImpl

protected void parseImpl(java.io.InputStream in,
                         java.lang.String codepage,
                         java.nio.charset.Charset charset)
                  throws java.io.IOException,
                         ParsingException
Parses the given file.
This method implements the actual parsing code.

Parameters:
in -
codepage -
charset -
Throws:
java.io.IOException
ParsingException

parse

public final void parse(java.io.InputStream in,
                        java.lang.String charset)
                 throws java.io.IOException,
                        ParsingException
Parses the given file.

Parameters:
in -
charset -
Throws:
java.io.IOException
ParsingException

parse

public final void parse(java.io.InputStream in,
                        java.nio.charset.Charset charset)
                 throws java.io.IOException,
                        ParsingException
Parses the given file.

Parameters:
in -
charset -
Throws:
java.io.IOException
ParsingException

parse

public final void parse(java.io.InputStream in)
                 throws java.io.IOException,
                        ParsingException
Parses the given file.

Parameters:
in -
Throws:
java.io.IOException
ParsingException

parse

public final void parse(java.net.URL url,
                        java.lang.String charset)
                 throws java.io.IOException,
                        ParsingException
Parses the given file.

Parameters:
url -
charset -
Throws:
java.io.IOException
ParsingException

parse

public final void parse(java.net.URL url,
                        java.nio.charset.Charset charset)
                 throws java.io.IOException,
                        ParsingException
Parses the given file.

Parameters:
url -
charset -
Throws:
java.io.IOException
ParsingException

parse

public final void parse(java.net.URL url)
                 throws java.io.IOException,
                        ParsingException
Parses the given file.

Parameters:
url -
Throws:
java.io.IOException
ParsingException

parse

public final void parse(java.io.File file,
                        java.lang.String charset)
                 throws java.io.IOException,
                        ParsingException
Parses the given file.

Parameters:
file -
charset -
Throws:
java.io.IOException
ParsingException

parse

public final void parse(java.io.File file,
                        java.nio.charset.Charset charset)
                 throws java.io.IOException,
                        ParsingException
Parses the given file.

Parameters:
file -
charset -
Throws:
java.io.IOException
ParsingException

parse

public final void parse(java.io.File file)
                 throws java.io.IOException,
                        ParsingException
Parses the given file.

Parameters:
file -
Throws:
java.io.IOException
ParsingException

parse

public final void parse(java.lang.String filename,
                        java.lang.String charset)
                 throws java.io.IOException,
                        ParsingException
Parses the given file.

Parameters:
filename -
charset -
Throws:
java.io.IOException
ParsingException

parse

public final void parse(java.lang.String filename,
                        java.nio.charset.Charset charset)
                 throws java.io.IOException,
                        ParsingException
Parses the given file.

Parameters:
filename -
charset -
Throws:
java.io.IOException
ParsingException

parse

public final void parse(java.lang.String filename)
                 throws java.io.IOException,
                        ParsingException
Parses the given file.

Parameters:
filename -
Throws:
java.io.IOException
ParsingException

parseIniValue

public static final java.lang.String parseIniValue(java.io.InputStream in,
                                                   java.lang.String charset,
                                                   java.lang.String group,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
Parses a single value from the given ini file.

Parameters:
in -
charset -
group -
key -
defaultValue -
Returns:
the value or 'defaultValue'.

parseIniValue

public static final java.lang.String parseIniValue(java.io.InputStream in,
                                                   java.nio.charset.Charset charset,
                                                   java.lang.String group,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
Parses a single value from the given ini file.

Parameters:
in -
charset -
group -
key -
defaultValue -
Returns:
the value or 'defaultValue'.

parseIniValue

public static final java.lang.String parseIniValue(java.io.InputStream in,
                                                   java.lang.String group,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
Parses a single value from the given ini file.

Parameters:
in -
group -
key -
defaultValue -
Returns:
the value or 'defaultValue'.

parseIniValue

public static final java.lang.String parseIniValue(java.net.URL url,
                                                   java.lang.String charset,
                                                   java.lang.String group,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
Parses a single value from the given ini file.

Parameters:
url -
charset -
group -
key -
defaultValue -
Returns:
the value or 'defaultValue'.

parseIniValue

public static final java.lang.String parseIniValue(java.net.URL url,
                                                   java.nio.charset.Charset charset,
                                                   java.lang.String group,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
Parses a single value from the given ini file.

Parameters:
url -
charset -
group -
key -
defaultValue -
Returns:
the value or 'defaultValue'.

parseIniValue

public static final java.lang.String parseIniValue(java.net.URL url,
                                                   java.lang.String group,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
Parses a single value from the given ini file.

Parameters:
url -
group -
key -
defaultValue -
Returns:
the value or 'defaultValue'.

parseIniValue

public static final java.lang.String parseIniValue(java.io.File file,
                                                   java.lang.String charset,
                                                   java.lang.String group,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
Parses a single value from the given ini file.

Parameters:
file -
charset -
group -
key -
defaultValue -
Returns:
the value or 'defaultValue'.

parseIniValue

public static final java.lang.String parseIniValue(java.io.File file,
                                                   java.nio.charset.Charset charset,
                                                   java.lang.String group,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
Parses a single value from the given ini file.

Parameters:
file -
charset -
group -
key -
defaultValue -
Returns:
the value or 'defaultValue'.

parseIniValue

public static final java.lang.String parseIniValue(java.io.File file,
                                                   java.lang.String group,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
Parses a single value from the given ini file.

Parameters:
file -
group -
key -
defaultValue -
Returns:
the value or 'defaultValue'.

parseIniValue

public static final java.lang.String parseIniValue(java.lang.String filename,
                                                   java.lang.String charset,
                                                   java.lang.String group,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
Parses a single value from the given ini file.

Parameters:
filename -
charset -
group -
key -
defaultValue -
Returns:
the value or 'defaultValue'.

parseIniValue

public static final java.lang.String parseIniValue(java.lang.String filename,
                                                   java.nio.charset.Charset charset,
                                                   java.lang.String group,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
Parses a single value from the given ini file.

Parameters:
filename -
charset -
group -
key -
defaultValue -
Returns:
the value or 'defaultValue'.

parseIniValue

public static final java.lang.String parseIniValue(java.lang.String filename,
                                                   java.lang.String group,
                                                   java.lang.String key,
                                                   java.lang.String defaultValue)
Parses a single value from the given ini file.

Parameters:
filename -
group -
key -
defaultValue -
Returns:
the value or 'defaultValue'.