Example usage for org.apache.commons.configuration CompositeConfiguration interpolatedConfiguration

List of usage examples for org.apache.commons.configuration CompositeConfiguration interpolatedConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.configuration CompositeConfiguration interpolatedConfiguration.

Prototype

public Configuration interpolatedConfiguration() 

Source Link

Document

Returns a configuration with the same content as this configuration, but with all variables replaced by their actual values.

Usage

From source file:ffx.autoparm.Keyword_poltype.java

/**
 * This method sets up configuration properties in the following precedence
 * order: 1.) Java system properties a.) -Dkey=value from the Java command
 * line b.) System.setProperty("key","value") within Java code.
 *
 * 2.) Structure specific properties (for example pdbname.properties)
 *
 * 3.) User specific properties (~/.ffx/ffx.properties)
 *
 * 4.) System wide properties (file defined by environment variable
 * FFX_PROPERTIES)//  www .j  a  v a 2 s  . c  o m
 *
 * 5.) Internal force field definition.
 *
 * @since 1.0
 * @param file a {@link java.io.File} object.
 * @return a {@link org.apache.commons.configuration.CompositeConfiguration}
 * object.
 */
public static CompositeConfiguration loadProperties(File file) {
    /**
     * Command line options take precedences.
     */
    CompositeConfiguration properties = new CompositeConfiguration();
    properties.addConfiguration(new SystemConfiguration());

    /**
     * Structure specific options are 2nd.
     */
    if (file != null && file.exists() && file.canRead()) {

        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            String prmfilename = br.readLine().split(" +")[1];
            File prmfile = new File(prmfilename);
            if (prmfile.exists() && prmfile.canRead()) {
                properties.addConfiguration(new PropertiesConfiguration(prmfile));
                properties.addProperty("propertyFile", prmfile.getCanonicalPath());
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }

    //      /**
    //       * User specific options are 3rd.
    //       */
    //      String filename = System.getProperty("user.home") + File.separator
    //            + ".ffx/ffx.properties";
    //      File userPropFile = new File(filename);
    //      if (userPropFile.exists() && userPropFile.canRead()) {
    //         try {
    //            properties.addConfiguration(new PropertiesConfiguration(
    //                  userPropFile));
    //         } catch (Exception e) {
    //            logger.info("Error loading " + filename + ".");
    //         }
    //      }
    //
    //      /**
    //       * System wide options are 2nd to last.
    //       */
    //      filename = System.getenv("FFX_PROPERTIES");
    //      if (filename != null) {
    //         File systemPropFile = new File(filename);
    //         if (systemPropFile.exists() && systemPropFile.canRead()) {
    //            try {
    //               properties.addConfiguration(new PropertiesConfiguration(
    //                     systemPropFile));
    //            } catch (Exception e) {
    //               logger.info("Error loading " + filename + ".");
    //            }
    //         }
    //      }
    /**
     * Echo the interpolated configuration.
     */
    if (logger.isLoggable(Level.FINE)) {
        Configuration config = properties.interpolatedConfiguration();
        Iterator<String> i = config.getKeys();
        while (i.hasNext()) {
            String s = i.next();
            logger.fine("Key: " + s + ", Value: " + Arrays.toString(config.getList(s).toArray()));
        }
    }

    return properties;
}