Class ConfigFileReader

java.lang.Object
org.eclnt.util.file.ConfigFileReader

public class ConfigFileReader extends Object
Utility class for reading configuration file that may be configured from outside the application. The file is read following a certain sequence of locations, see details of readConfigFile(String).
  • Constructor Details

    • ConfigFileReader

      public ConfigFileReader()
  • Method Details

    • readConfigFile

      public static String readConfigFile(String configFileName)
      Short version of readConfigFile(String, boolean), passing parameter "contentIsXML" as "false".
    • readConfigFile

      public static String readConfigFile(String configFileName, boolean contentIsXML)
      Reads a configuration file content in a certain sequence.

      1. If a environment variable "cc_configDirectory" or "ccee_configDirectory" is defined, then this directory is checked in two steps:
      1a. First a directory with the context name of the webapp is checked if it contains the configuration file.
      1b. Then the directory itself is checked if it contains the configuration file.

      3. Then the classloader may contain the file that is desired.

      4. Then The file is picked within the web application using the access to web resources that is granted by the servlet context.

      Example: if the environment "cc_configDirectory" is set to "c:/myconfig" and the file's name is "test.xml", and the current web application is "demos", then:
      1. First the file C:/myconfig/demos/test.xml" is checked.
      2. Then the file C:/myconfig/test.xml" is checked.
      3. Then the file is read from the classloader.
      4. Then the file is read from the webcontent

      Afte reading the config file its content is post-processed so that system variables are replaced following ValueManager.replaceSystemProperties(String, boolean).
      Parameters:
      contentIsXML - Set to "true" if the config file contains XML content. Purpose: in the config file you may add system parameters - which are processed by ValueManager.replaceSystemProperties(String, boolean). During the replacement characters must be correctly encoded if the file is some XML-file (e.g. characters like "<", ">" need to be correctly transferred to their XML representation).
      Returns:
      content of configuration file as string. If the configuration file is not found then null is returned.
    • readConfigFiles

      public static List<String> readConfigFiles(String configFileName, boolean withReadingExternalConfiguration, boolean contentIsXML)
      Read all occurrences of this file: classloader, webcontent, external configuration. The result is typically merged by the caller.
    • readPropertiesFile

      public static ResourceBundle readPropertiesFile(String configFileName)
      Reads the content of the configuration file and passes back the result as properties file (resource bundle). The content of the file is read using readConfigFile(String, boolean).

      Please note:
      1. while reading the file, there is no language/country-based resolution as it is done when accessing resource bundles!
      2. the name of the file must be part with its extension (e.g. ".properties").
      Parameters:
      configFileName - (with extension!)
      Returns:
      content of file as ResourceBundle. Null in case the file cannot be found.
    • readExternalConfigFile

      public static String readExternalConfigFile(String configFileName, boolean contentIsXML)
      Similar to readConfigFile(String, boolean, boolean) - but ONLY checks for these places that are outside the content of the web application. This means: step 3 (classloader) and 4 (webcontent) are NOT executed.