|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object marf.util.OptionFileLoader
public class OptionFileLoader
Loads a configuration file.
This class is based upon OptionsFileLoaderSingleton
originally implemented by Marc-Andre Laverdiere in the Crytolysis
and Ftklipse projects. It was later adapted to be an options provider
and brought to MARF by Serguei Mokhov.
The class loads a configuration file with the format:
key=value #commentWARNING: this is not a great option to keep passwords in memory, because the data is kept as strings. $Id: OptionFileLoader.java,v 1.2 2007/12/23 06:29:47 mokhov Exp $
Field Summary | |
---|---|
protected boolean |
bIsInitialized
Indicates that the config was initialized. |
protected static char |
COMMENT_SYMBOL
Comment symbol. |
protected static java.lang.String |
DEFAULT_CONFIG_FILE_NAME
Default config file name. |
protected java.util.Hashtable |
oHashOptionValuePairTracker
Options tracking in the form (key, value), both kept as strings. |
protected static OptionFileLoader |
oOptionsLoaderInstance
Singleton Instance. |
protected static char |
SEPARATOR_SYMBOL
Separator symbol. |
Constructor Summary | |
---|---|
protected |
OptionFileLoader()
Constructs an uninitialized options loader. |
Method Summary | |
---|---|
void |
addActiveOption(int piOptionCode,
java.lang.String pstrOptionString)
|
void |
addActiveOption(java.lang.String pstrOptionString)
|
void |
addActiveOption(java.lang.String pstrOptionString,
java.lang.String pstrOptionValue)
|
void |
addValidOption(int piOptionCode,
java.lang.String pstrOptionString)
|
void |
addValidOption(int piOptionCode,
java.lang.String pstrOptionString,
boolean pbRequiresArgument)
|
void |
addValidOption(java.lang.String pstrOptionString)
|
java.util.Hashtable |
getActiveOptions()
|
java.lang.String |
getArgumentString()
|
java.lang.String[] |
getArgumentVector()
|
java.lang.String |
getConfigurationSetting(java.lang.String pstrKey)
Allows retrieving setting by a key. |
static OptionFileLoader |
getInstance()
Obtains singleton instance. |
java.util.Vector |
getInvalidOptions()
|
protected java.lang.String |
getKey(java.lang.String pstrLine)
Obtains the key of the line |
java.lang.String |
getOption(int piOption)
|
java.lang.String |
getOption(int piOption,
boolean pbReturnOnError)
|
int |
getOption(java.lang.String pstrOption)
|
int |
getOption(java.lang.String pstrOption,
boolean pbReturnOnError)
|
java.lang.String |
getOptionArgument(int piOption)
|
java.lang.String |
getOptionArgument(int piOption,
boolean pbReturnOnError)
|
java.lang.String |
getOptionArgument(java.lang.String pstrOption)
|
java.lang.String |
getOptionArgument(java.lang.String pstrOption,
boolean pbReturnOnError)
|
java.util.Hashtable |
getValidOptions()
|
protected java.lang.String |
getValue(java.lang.String pstrLine)
Obtains the value of the line. |
boolean |
isActiveOption(int piOption)
|
boolean |
isActiveOption(java.lang.String pstrOption)
|
boolean |
isInitialized()
|
boolean |
isInvalidOption(java.lang.String pstrOption)
|
boolean |
isValidOption(int piOption)
|
boolean |
isValidOption(java.lang.String pstrOption)
|
void |
loadConfiguration()
Loads default configuration file. |
void |
loadConfiguration(java.lang.String pstrFileName)
Loads specified configuration file. |
protected java.lang.String |
removeComment(java.lang.String pstrLine)
Removes the comment from the line |
int |
size()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static OptionFileLoader oOptionsLoaderInstance
protected java.util.Hashtable oHashOptionValuePairTracker
protected boolean bIsInitialized
protected static final java.lang.String DEFAULT_CONFIG_FILE_NAME
protected static final char COMMENT_SYMBOL
protected static final char SEPARATOR_SYMBOL
Constructor Detail |
---|
protected OptionFileLoader()
Method Detail |
---|
public static OptionFileLoader getInstance()
public void loadConfiguration() throws java.io.IOException
java.io.IOException
- on error reading filepublic void loadConfiguration(java.lang.String pstrFileName) throws java.io.IOException
pstrFileName
- name of the configuration file
java.io.IOException
- on error reading filepublic java.lang.String getConfigurationSetting(java.lang.String pstrKey)
pstrKey
- the key
protected java.lang.String removeComment(java.lang.String pstrLine)
pstrLine
- line of data
protected java.lang.String getKey(java.lang.String pstrLine)
pstrLine
- line of data
protected java.lang.String getValue(java.lang.String pstrLine)
pstrLine
- line of data
public boolean isInitialized()
public void addValidOption(java.lang.String pstrOptionString)
addValidOption
in interface IOptionProvider
public void addValidOption(int piOptionCode, java.lang.String pstrOptionString)
addValidOption
in interface IOptionProvider
public void addValidOption(int piOptionCode, java.lang.String pstrOptionString, boolean pbRequiresArgument)
addValidOption
in interface IOptionProvider
public void addActiveOption(java.lang.String pstrOptionString)
addActiveOption
in interface IOptionProvider
public void addActiveOption(int piOptionCode, java.lang.String pstrOptionString)
addActiveOption
in interface IOptionProvider
public void addActiveOption(java.lang.String pstrOptionString, java.lang.String pstrOptionValue)
addActiveOption
in interface IOptionProvider
public int size()
size
in interface IOptionProvider
IOptionProvider.size()
public java.lang.String[] getArgumentVector()
getArgumentVector
in interface IOptionProvider
public java.lang.String getArgumentString()
getArgumentString
in interface IOptionProvider
public int getOption(java.lang.String pstrOption)
getOption
in interface IOptionProvider
public int getOption(java.lang.String pstrOption, boolean pbReturnOnError)
getOption
in interface IOptionProvider
public java.lang.String getOptionArgument(java.lang.String pstrOption, boolean pbReturnOnError)
getOptionArgument
in interface IOptionProvider
public java.lang.String getOption(int piOption)
getOption
in interface IOptionProvider
public java.lang.String getOption(int piOption, boolean pbReturnOnError)
getOption
in interface IOptionProvider
public java.lang.String getOptionArgument(java.lang.String pstrOption)
getOptionArgument
in interface IOptionProvider
public java.lang.String getOptionArgument(int piOption)
getOptionArgument
in interface IOptionProvider
public java.lang.String getOptionArgument(int piOption, boolean pbReturnOnError)
getOptionArgument
in interface IOptionProvider
public java.util.Vector getInvalidOptions()
getInvalidOptions
in interface IOptionProvider
public java.util.Hashtable getActiveOptions()
getActiveOptions
in interface IOptionProvider
public java.util.Hashtable getValidOptions()
getValidOptions
in interface IOptionProvider
public boolean isActiveOption(java.lang.String pstrOption)
isActiveOption
in interface IOptionProvider
public boolean isActiveOption(int piOption)
isActiveOption
in interface IOptionProvider
public boolean isValidOption(java.lang.String pstrOption)
isValidOption
in interface IOptionProvider
public boolean isValidOption(int piOption)
isValidOption
in interface IOptionProvider
public boolean isInvalidOption(java.lang.String pstrOption)
isInvalidOption
in interface IOptionProvider
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |