Ejemplo n.º 1
0
 /**
  * Handle Configuration file.
  *
  * <p>The method will attempt to obtain the properties file from the reserved configuration switch
  * if it is enabled. The application wide <code>Properties</code> obtained from the <code>CliBase
  * </code> will be loaded with the configuration if enabled and found.
  *
  * <p>If the configuration switch is enabled and the <code>Properties</code> can not be loaded
  * with the given file, this method will call Help with error information. Help will exit the
  * application and this method will never return in this case.
  *
  * @return true if the configuration switch is enabled and the configuration was obtained.
  *     Otherwise, false is returned.
  */
 public boolean handleConfiguration() {
   boolean gotConfig = false;
   if (cliBase.isConfigSwitch() || !cliBase.isLogToFile()) {
     // if !logToFileSwitch try looking in the configuration file for configPathKey
     gotConfig = true;
     if (!commandline.hasOption(CliBase.ConfigurationPathShortCl)) {
       gotConfig = false;
       if (cliBase.isConfigSwitch() && commandline.hasOption(CliBase.HelpShortCl)) {
         System.err.println(
             "-"
                 + CliBase.ConfigurationPathShortCl
                 + " | --"
                 + CliBase.ConfigurationPathLongCl
                 + " required\n");
         help(CliBase.ConfigNotFound, "Given configuration file not found");
       }
     }
     if (gotConfig) {
       StringBuilder sb = cliBase.getInitsb();
       Properties properties = cliBase.properties;
       String configPathKey = cliBase.getConfigPathKey();
       String configPath = commandline.getOptionValue(CliBase.ConfigurationPathShortCl);
       StrH.ttl(sb, 1, "--", CliBase.ConfigurationPathLongCl, " = ", configPath);
       try {
         PropertiesFile.loadFile(properties, new File(configPath));
       } catch (Exception e) {
         help(CliBase.ConfigNotFound, "Given configuration file not found");
       }
       if (configPathKey != null) {
         StrH.ttl(sb, 1, configPathKey, " = ", configPath);
         System.setProperty(configPathKey, configPath);
       }
     }
   }
   return gotConfig;
 }