Example usage for org.apache.commons.configuration ConfigurationUtils fileFromURL

List of usage examples for org.apache.commons.configuration ConfigurationUtils fileFromURL

Introduction

In this page you can find the example usage for org.apache.commons.configuration ConfigurationUtils fileFromURL.

Prototype

public static File fileFromURL(URL url) 

Source Link

Document

Tries to convert the specified URL to a file object.

Usage

From source file:com.vmware.bdd.specpolicy.TemplateClusterSpec.java

private static void init() {
    String homeDir = System.getProperties().getProperty("serengeti.home.dir");
    File templateFile = null;/*ww w.  jav  a2 s  .  com*/
    if (homeDir != null && homeDir.length() > 0) {
        StringBuilder builder = new StringBuilder();
        builder.append(homeDir).append(File.separator).append("conf").append(File.separator)
                .append(TEMPLATE_CLUSTER_SPEC_JSON);
        templateFile = new File(builder.toString());
    } else {
        URL filePath = ConfigurationUtils.locate(TEMPLATE_CLUSTER_SPEC_JSON);
        if (filePath != null) {
            templateFile = ConfigurationUtils.fileFromURL(filePath);
        }
    }

    if (templateFile == null) {
        logger.error("cluster template spec is not found, using the default cluster value.");
        loadDefaultValue();
    }
    try {
        Reader fileReader = new FileReader(templateFile);
        createTemplate(fileReader);
    } catch (FileNotFoundException e) {
        logger.error("cluster template spec is not found, using the default cluster value.");
        loadDefaultValue();
    }
}

From source file:com.vmware.bdd.utils.CommonUtil.java

public static File getConfigurationFile(final String filename, final String typeName) {
    // try to locate file directly
    File specFile = new File(filename);
    if (specFile.exists()) {
        return specFile;
    }/*from w w  w . java2 s  .co m*/

    // search ${serengeti.home.dir}/conf directory
    String homeDir = System.getProperties().getProperty("serengeti.home.dir");
    if (homeDir != null && !homeDir.trim().isEmpty()) {
        StringBuilder builder = new StringBuilder();
        builder.append(getConfDir()).append(File.separator).append(filename);
        specFile = new File(builder.toString());

        if (!specFile.exists()) {
            logger.warn(typeName + " file does not exist: " + builder);
        } else {
            return specFile;
        }
    }

    // search in class paths
    URL filePath = ConfigurationUtils.locate(filename);
    if (filePath != null) {
        specFile = ConfigurationUtils.fileFromURL(filePath);
    }

    if (!specFile.exists()) {
        String errorMsg = "Can not find file " + filename;
        logger.fatal(errorMsg);
        throw new RuntimeException(errorMsg);
    }

    return specFile;
}

From source file:com.vmware.bdd.specpolicy.ClusterSpecFactory.java

private static File locateSpecFile(String filename, String appManagerType) {
    // try to locate file directly
    File specFile = new File(filename);
    if (specFile.exists()) {
        return specFile;
    }//from   ww  w . ja va 2s.c o  m

    // search ${serengeti.home.dir}/conf directory
    String homeDir = System.getProperties().getProperty("serengeti.home.dir");
    if (homeDir != null && !homeDir.trim().isEmpty()) {
        StringBuilder builder = new StringBuilder();
        builder.append(homeDir).append(File.separator).append("conf").append(File.separator)
                .append(appManagerType).append(File.separator).append("spec-templates").append(File.separator)
                .append(filename);
        specFile = new File(builder.toString());
    }

    if (!specFile.exists()) {
        logger.warn("template cluster file does not exist: " + specFile.getAbsolutePath());
        // search in class paths
        URL filePath = ConfigurationUtils.locate(filename);
        if (filePath != null) {
            specFile = ConfigurationUtils.fileFromURL(filePath);
        }
    }

    if (!specFile.exists()) {
        throw BddException.INTERNAL(null, "Can not find template cluster spec file " + filename);
    }

    return specFile;
}