com.isti.util
Class XmlConfigLoader

java.lang.Object
  extended by com.isti.util.ErrorMessageMgr
      extended by com.isti.util.IstiXmlUtils
          extended by com.isti.util.XmlConfigLoader
All Implemented Interfaces:
ErrorMsgMgrIntf

public class XmlConfigLoader
extends IstiXmlUtils

Class XmlConfigLoader defines a loader for reading configuration-property settings from an XML-format input file.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.isti.util.IstiXmlUtils
IstiXmlUtils.RootElement
 
Field Summary
protected static java.lang.String DEF_HELP1_STR
           
protected static java.lang.String DEF_HELP2_STR
           
protected static java.lang.String DEF_VER1_STR
           
protected static java.lang.String DEF_VER2_STR
           
protected static java.lang.String help1String
           
protected static java.lang.String help2String
           
protected static java.lang.String version1String
           
protected static java.lang.String version2String
           
 
Fields inherited from class com.isti.util.IstiXmlUtils
ISO_8859_1_ENCODING_FORMAT, loadFileOpenedFlag, rootElement, useDocumentFlag, UTF_8_ENCODING_FORMAT, XML_FILE_EXTENSION, XML_STYLESHEET, XML_STYLESHEET_PROCESSING_INSTRUCTION, xmlBuilderObj, xmlFileOutputterObj, xmlFixedStrOutputterObj, xmlStrOutputterObj
 
Constructor Summary
XmlConfigLoader()
           
 
Method Summary
 java.lang.String getVersionString()
          Gets the version string to be displayed.
 boolean loadConfiguration(java.lang.String fileName, java.lang.String rootElementName, java.lang.String settingsElementName, boolean mustFlag, CfgProperties cfgPropObj, boolean defaultsFlag)
          Loads the XML-format configuration file and loads the set of "name = value" items specified by the "Settings" element in the configuration file.
 boolean loadConfiguration(java.lang.String fileName, java.lang.String rootElementName, java.lang.String settingsElementName, boolean mustFlag, CfgProperties cfgPropObj, java.lang.String[] programArgs)
          Loads the XML-format configuration file and loads the set of "name = value" items specified by the "Settings" element in the configuration file.
 boolean loadConfiguration(java.lang.String fileName, java.lang.String rootElementName, java.lang.String settingsElementName, boolean mustFlag, CfgProperties cfgPropObj, java.lang.String[] programArgs, boolean defaultsFlag, java.lang.String cfgParamSpecStr)
          Loads the XML-format configuration file and loads the set of "name = value" items specified by the "Settings" element in the configuration file.
 boolean loadConfiguration(java.lang.String fileName, java.lang.String rootElementName, java.lang.String settingsElementName, boolean mustFlag, CfgProperties cfgPropObj, java.lang.String[] programArgs, java.lang.String cfgParamSpecStr)
          Loads the XML-format configuration file and loads the set of "name = value" items specified by the "Settings" element in the configuration file.
static void setHelpParamNames(java.lang.String help1Str, java.lang.String help2Str)
          Sets the names for the display-help-info command-line parameters.
static void setVersionParamNames(java.lang.String ver1Str, java.lang.String ver2Str)
          Sets the names for the display-version-info command-line parameters.
 void setVersionString(java.lang.String s)
          Sets the version string to be displayed.
 
Methods inherited from class com.isti.util.IstiXmlUtils
addXmlFileExtension, clearErrorMessage, convertFromEscapedCodes, createCdata, createRootElement, ctrlCharsFromEscapedCodes, ctrlCharsToEscapedCodes, ctrlCharsToEscapedCodes, elementToFixedString, elementToString, elementToString, findElement, findElement, getAnyNSChild, getChildDataFixedStr, getChildDataStr, getChildDataStr, getChildDataStr, getComponentForClass, getEncodedString, getErrorFlag, getErrorMessage, getLoadFileOpenedFlag, getRootElement, loadFile, loadFile, loadStream, loadStream, loadStream, loadStream, saveToFile, saveToFile, saveToStream, saveToStream, setDocumentStylesheet, setElementNamespace, setElementNamespace, setErrorMessage, setFileLineSeparator, setFileOmitDeclaration, setFileOmitEncoding, setFileOutExpandEmptyElements, setFileOutIndent, setFileOutNewlines, setFileOutTextTrim, setLoadExternalDTDFeature, setRootElement, setStrOutExpandEmptyElements, setStrOutIndent, setStrOutNewlines, setStrOutTextTrim, stringToElement
 
Methods inherited from class com.isti.util.ErrorMessageMgr
clearErrorMessageString, clearFetchedErrorMessage, enterErrorMessageString, getErrorMessageFlag, getErrorMessageString, getUnfetchedMessageFlag, setErrorMessageString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEF_VER1_STR

protected static final java.lang.String DEF_VER1_STR
See Also:
Constant Field Values

DEF_VER2_STR

protected static final java.lang.String DEF_VER2_STR
See Also:
Constant Field Values

DEF_HELP1_STR

protected static final java.lang.String DEF_HELP1_STR
See Also:
Constant Field Values

DEF_HELP2_STR

protected static final java.lang.String DEF_HELP2_STR
See Also:
Constant Field Values

version1String

protected static java.lang.String version1String

version2String

protected static java.lang.String version2String

help1String

protected static java.lang.String help1String

help2String

protected static java.lang.String help2String
Constructor Detail

XmlConfigLoader

public XmlConfigLoader()
Method Detail

loadConfiguration

public boolean loadConfiguration(java.lang.String fileName,
                                 java.lang.String rootElementName,
                                 java.lang.String settingsElementName,
                                 boolean mustFlag,
                                 CfgProperties cfgPropObj,
                                 java.lang.String[] programArgs,
                                 boolean defaultsFlag,
                                 java.lang.String cfgParamSpecStr)
Loads the XML-format configuration file and loads the set of "name = value" items specified by the "Settings" element in the configuration file. Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first). Command-line parameters may also be processed via this method. If the configuration file is not found and 'mustFlag'==false then an empty root element containing a "Settings" element is created. If the display-version-info or display-help-info command-line parameter is detected then the program is terminated (via 'System.exit(0)') after the information is sent to the console.

Parameters:
fileName - the name of the XML file to load.
rootElementName - the expected name of the root element in the XML file, or null to accept any name.
settingsElementName - the name of the "Settings" element whose text contains the "name = value" items.
mustFlag - if true and a configuration file with a "Settings" element is not found then an error will be generated and the method will return 'false'.
cfgPropObj - the 'CfgProperties' object to be loaded from the configuration file.
programArgs - string array of command-line parameters to be processed, or null for none.
defaultsFlag - true to load the items as defaults into the configuration-properties object; false to load the items normally.
cfgParamSpecStr - name of command-line parameter for specifying the configuration file, or null for none.
Returns:
'true' if successful, false if an error occurred (in which case the 'getErrorMessage()' method may be used to fetch a description of the error).

loadConfiguration

public boolean loadConfiguration(java.lang.String fileName,
                                 java.lang.String rootElementName,
                                 java.lang.String settingsElementName,
                                 boolean mustFlag,
                                 CfgProperties cfgPropObj,
                                 java.lang.String[] programArgs,
                                 java.lang.String cfgParamSpecStr)
Loads the XML-format configuration file and loads the set of "name = value" items specified by the "Settings" element in the configuration file. Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first). Command-line parameters may also be processed via this method. If the configuration file is not found and 'mustFlag'==false then an empty root element containing a "Settings" element is created. If the display-version-info or display-help-info command-line parameter is detected then the program is terminated (via 'System.exit(0)') after the information is sent to the console.

Parameters:
fileName - the name of the XML file to load.
rootElementName - the expected name of the root element in the XML file, or null to accept any name.
settingsElementName - the name of the "Settings" element whose text contains the "name = value" items.
mustFlag - if true and a configuration file with a "Settings" element is not found then an error will be generated and the method will return 'false'.
cfgPropObj - the 'CfgProperties' object to be loaded from the configuration file.
programArgs - string array of command-line parameters to be processed, or null for none.
cfgParamSpecStr - name of command-line parameter for specifying the configuration file, or null for none.
Returns:
'true' if successful, false if an error occurred (in which case the 'getErrorMessage()' method may be used to fetch a description of the error).

loadConfiguration

public boolean loadConfiguration(java.lang.String fileName,
                                 java.lang.String rootElementName,
                                 java.lang.String settingsElementName,
                                 boolean mustFlag,
                                 CfgProperties cfgPropObj,
                                 java.lang.String[] programArgs)
Loads the XML-format configuration file and loads the set of "name = value" items specified by the "Settings" element in the configuration file. Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first). Command-line parameters may also be processed via this method. If the configuration file is not found and 'mustFlag'==false then an empty root element containing a "Settings" element is created. If the display-version-info or display-help-info command-line parameter is detected then the program is terminated (via 'System.exit(0)') after the information is sent to the console.

Parameters:
fileName - the name of the XML file to load.
rootElementName - the expected name of the root element in the XML file, or null to accept any name.
settingsElementName - the name of the "Settings" element whose text contains the "name = value" items.
mustFlag - if true and a configuration file with a "Settings" element is not found then an error will be generated and the method will return 'false'.
cfgPropObj - the 'CfgProperties' object to be loaded from the configuration file.
programArgs - string array of command-line parameters to be processed, or null for none.
Returns:
'true' if successful, false if an error occurred (in which case the 'getErrorMessage()' method may be used to fetch a description of the error).

loadConfiguration

public boolean loadConfiguration(java.lang.String fileName,
                                 java.lang.String rootElementName,
                                 java.lang.String settingsElementName,
                                 boolean mustFlag,
                                 CfgProperties cfgPropObj,
                                 boolean defaultsFlag)
Loads the XML-format configuration file and loads the set of "name = value" items specified by the "Settings" element in the configuration file. Attempts to open the given name as a local file, as a URL, as a resource and as an entry in a 'jar' file (whichever works first). If the configuration file is not found and 'mustFlag'==false then an empty root element containing a "Settings" element is created. If the display-version-info or display-help-info command-line parameter is detected then the program is terminated (via 'System.exit(0)') after the information is sent to the console.

Parameters:
fileName - the name of the XML file to load.
rootElementName - the expected name of the root element in the XML file, or null to accept any name.
settingsElementName - the name of the "Settings" element whose text contains the "name = value" items.
mustFlag - if true and a configuration file with a "Settings" element is not found then an error will be generated and the method will return 'false'.
cfgPropObj - the 'CfgProperties' object to be loaded from the configuration file.
defaultsFlag - true to load the items as defaults into the configuration-properties object; false to load the items normally.
Returns:
'true' if successful, false if an error occurred (in which case the 'getErrorMessage()' method may be used to fetch a description of the error).

getVersionString

public java.lang.String getVersionString()
Gets the version string to be displayed.

Returns:
the version string or null if none.

setVersionString

public void setVersionString(java.lang.String s)
Sets the version string to be displayed.

Parameters:
s - the version string or null if none.

setVersionParamNames

public static void setVersionParamNames(java.lang.String ver1Str,
                                        java.lang.String ver2Str)
Sets the names for the display-version-info command-line parameters. If this method is not used then the parameters will default to "version" and "v".

Parameters:
ver1Str - first parameter name to use.
ver2Str - second parameter name to use.

setHelpParamNames

public static void setHelpParamNames(java.lang.String help1Str,
                                     java.lang.String help2Str)
Sets the names for the display-help-info command-line parameters. If this method is not used then the parameters will default to "help" and "h".

Parameters:
help1Str - first parameter name to use.
help2Str - second parameter name to use.