Example usage for org.apache.commons.configuration.io FileHandler FileHandler

List of usage examples for org.apache.commons.configuration.io FileHandler FileHandler

Introduction

In this page you can find the example usage for org.apache.commons.configuration.io FileHandler FileHandler.

Prototype

public FileHandler(FileBased obj) 

Source Link

Document

Creates a new instance of FileHandler and sets the managed FileBased object.

Usage

From source file:ubic.basecode.util.ConfigUtils.java

/**
 * @param name the classpath location, such as "project.properties" in the base package, or
 *        org/foo/project.properties./* www.  ja v  a  2 s  .  c o m*/
 * @return
 * @throws ConfigurationException
 */
public static PropertiesConfiguration loadClasspathConfig(String name) throws ConfigurationException {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();

    URL url = loader.getResource(name);
    if (url == null) {
        throw new ConfigurationException("Couldn't locate: " + name);
    }

    PropertiesConfiguration pc = new PropertiesConfiguration();
    FileHandler handler = new FileHandler(pc);
    handler.setURL(url);
    handler.load();
    return pc;
}

From source file:ubic.basecode.util.ConfigUtils.java

/**
 * @param file//from ww  w  . j  av a 2  s .c  om
 * @return
 * @throws ConfigurationException
 */
public static PropertiesConfiguration loadConfig(File file) throws ConfigurationException {
    if (!file.exists()) {
        try {
            FileTools.touch(file);
        } catch (IOException e) {
            throw new ConfigurationException("Couldn't create the file: " + e.getMessage());
        }
    }
    PropertiesConfiguration pc = new PropertiesConfiguration();
    FileHandler handler = new FileHandler(pc);
    handler.setFile(file);
    handler.load();
    return pc;
}

From source file:ubic.basecode.util.r.RServeClient.java

/**
 * @return/*w w w .  j  a  va2 s . com*/
 * @throws ConfigurationException
 */
protected static String findRserveCommand() throws ConfigurationException {
    URL userSpecificConfigFileLocation = ConfigUtils.locate("local.properties");

    PropertiesConfiguration userConfig = null;
    if (userSpecificConfigFileLocation != null) {
        userConfig = new PropertiesConfiguration();
        FileHandler handler = new FileHandler(userConfig);
        handler.setFileName("local.properties");
        handler.load();
    }
    String rserveExecutable = null;
    if (userConfig != null) {
        rserveExecutable = userConfig.getString("rserve.start.command");
    }
    if (StringUtils.isBlank(rserveExecutable)) {
        log.info("Rserve command not configured? Trying fallbacks");
        if (os.startsWith("windows")) { // lower cased
            rserveExecutable = System.getenv("R_HOME") + File.separator + "library" + File.separator + "Rserve"
                    + File.separator + "Rserve.exe";
        } else {
            rserveExecutable = "R CMD Rserve";
        }
    }
    return rserveExecutable;
}

From source file:ubic.gemma.web.util.ConfigurationCookie.java

/**
 * Used when loading cookies from the user.
 *
 * @param cookie Must have been originally created as a ConfigurationCookie (or look just like one).
 * @throws ConfigurationException if the cookie cannot be converted.
 *///  w w w .j  a  v a  2s  .c om
public ConfigurationCookie(Cookie cookie) throws ConfigurationException {
    super(cookie.getName(), cookie.getValue());

    // turn the value into properties.
    StringReader reader = new StringReader(this.getValue().replaceAll(PROPERTY_DELIMITER, "\n"));
    configuration = new PropertiesConfiguration();
    FileHandler fh = new FileHandler(configuration);
    fh.load(reader);
}

From source file:ubic.gemma.web.util.ConfigurationCookie.java

public void addProperty(String key, Object value) {
    this.configuration.addProperty(key, value);
    // Rewrite the value.
    StringWriter writer = new StringWriter();
    try {/*from w w  w  .j  av a2 s. co  m*/
        FileHandler fh = new FileHandler(configuration);
        fh.save(writer);
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
    setValue(writer.toString().replaceAll("\n", PROPERTY_DELIMITER));
}

From source file:ubic.gemma.web.util.ConfigurationCookie.java

public void setProperty(String key, Object value) {
    this.configuration.setProperty(key, value);

    // Rewrite the value.
    StringWriter writer = new StringWriter();
    try {/*from w  w w .  j a  va2 s  .  c o  m*/
        FileHandler fh = new FileHandler(configuration);
        fh.save(writer);
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
    setValue(PROPERTY_DELIMITER + writer.toString().replaceAll("\n", PROPERTY_DELIMITER));
}