Example usage for org.apache.commons.configuration2.builder.fluent Configurations properties

List of usage examples for org.apache.commons.configuration2.builder.fluent Configurations properties

Introduction

In this page you can find the example usage for org.apache.commons.configuration2.builder.fluent Configurations properties.

Prototype

public PropertiesConfiguration properties(final String path) throws ConfigurationException 

Source Link

Document

Creates a PropertiesConfiguration instance from the content of the file identified by the given path.

Usage

From source file:io.github.swagger2markup.cli.Application.java

public void run() {

    Swagger2MarkupConfig swagger2MarkupConfig = null;
    if (StringUtils.isNotBlank(configFile)) {
        Configurations configs = new Configurations();
        Configuration config;//from w w  w. j a v a  2  s .  c  o m
        try {
            config = configs.properties(configFile);
        } catch (ConfigurationException e) {
            throw new IllegalArgumentException("Failed to read configFile", e);
        }
        swagger2MarkupConfig = new Swagger2MarkupConfigBuilder(config).build();
    }
    Swagger2MarkupConverter.Builder converterBuilder = Swagger2MarkupConverter
            .from(URIUtils.create(swaggerInput));
    if (swagger2MarkupConfig != null) {
        converterBuilder.withConfig(swagger2MarkupConfig);
    }
    Swagger2MarkupConverter converter = converterBuilder.build();

    if (StringUtils.isNotBlank(outputFile)) {
        converter.toFile(Paths.get(outputFile).toAbsolutePath());
    } else if (StringUtils.isNotBlank(outputDir)) {
        converter.toFolder(Paths.get(outputDir).toAbsolutePath());
    } else {
        throw new IllegalArgumentException("Either outputFile or outputDir option must be used");
    }
}

From source file:io.github.swagger2markup.DocumentationTest.java

public void swagger2MarkupConfigFromCommonsConfiguration() throws IOException, ConfigurationException {
    Path localSwaggerFile = Paths.get("/path/to/swagger.yaml");

    // tag::swagger2MarkupConfigFromCommonsConfiguration[]
    Configurations configs = new Configurations();
    Configuration configuration = configs.properties("config.properties"); //<1>

    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configuration) //<2>
            .build();//from  w w  w  . j  av a2  s .  c om

    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(localSwaggerFile).withConfig(config)
            .build();
    // end::swagger2MarkupConfigFromCommonsConfiguration[]
}

From source file:database.DataBaseMySQL.java

/**
 *
 * @param null//from   www  .j  a  v a2s  .c  o m
 */
public DataBaseMySQL(String config_file) {
    Configurations configs = new Configurations();
    try {
        Configuration config = configs.properties(new File(config_file));

        dbHost = config.getString("database.host");
        dbUser = config.getString("database.user");
        dbPass = config.getString("database.password");

        dbConnect();

    } catch (ConfigurationException cex) {
        System.out.print(cex.getMessage());
    }
}

From source file:io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder.java

/**
 * Loads the default properties from the classpath.
 *
 * @return the default properties//from  w  w  w  .jav  a2 s .c  o  m
 */
private Configuration getDefaultConfiguration() {
    Configurations configs = new Configurations();
    try {
        return configs.properties(PROPERTIES_DEFAULT);
    } catch (ConfigurationException e) {
        throw new RuntimeException(String.format("Can't load default properties '%s'", PROPERTIES_DEFAULT), e);
    }
}

From source file:com.sikulix.core.SX.java

private static void loadOptions() {
    boolean success = true;
    URL urlOptions = SX.class.getClassLoader().getResource("Settings/sxoptions.txt");
    if (!isNull(urlOptions)) {
        Configurations configs = new Configurations();
        try {// w  w  w  .ja v  a  2 s. c  om
            sxOptions = configs.properties(urlOptions);
        } catch (ConfigurationException cex) {
            success = false;
        }
    } else {
        success = false;
    }
    if (!success) {
        terminate(1, "loadOptions: SX Options not available: %s", urlOptions);
    }
    setOptions(sxOptions);

    PropertiesConfiguration extraOptions = null;

    File aFile = null;
    String argFile = getArg("o");
    if (!isNull(argFile)) {
        aFile = getFile(argFile);
        if (!aFile.isDirectory()) {
            if (aFile.exists()) {
                fOptions = aFile;
                trace("loadOptions: arg: %s (from arg -o)", aFile);
            } else {
                fnOptions = aFile.getName();
                trace("loadOptions: file name given: %s (from arg -o)", fnOptions);
            }
        }
    }

    if (isNull(fOptions)) {
        for (String sFile : new String[] { getUSERWORK(), getUSERHOME(), getSXSTORE() }) {
            if (isNull(sFile)) {
                continue;
            }
            aFile = getFile(sFile);
            trace("loadOptions: check: %s", aFile);
            fOptions = new File(aFile, fnOptions);
            if (fOptions.exists()) {
                break;
            } else {
                fOptions = null;
            }
        }
    }
    if (fOptions != null) {
        trace("loadOptions: found Options file at: %s", fOptions);
        Configurations configs = new Configurations();
        try {
            extraOptions = configs.properties(fOptions);
        } catch (ConfigurationException cex) {
            error("loadOptions: Options not valid: %s", cex.getMessage());
        }
        if (!isNull(extraOptions)) {
            setOptions(extraOptions);
            mergeExtraOptions(sxOptions, extraOptions);
        }
    } else {
        trace("loadOptions: no extra Options file found");
    }
}

From source file:odyssey.Odyssey.java

/**
 * @param args the command line arguments
 *///w ww  . j  a  v  a 2 s .  co m
public static void main(String[] args) {

    Configurations configs = new Configurations();
    if (0 < args.length) {
        String propFileName = args[0];
        File props = new File(propFileName);
        if (props.exists()) {
            try {
                Configuration config = configs.properties(props);

                System.out.println("Using properties file: " + props);
                System.out.println("Prop1: " + config.getString("test.property1"));
                System.out.println("Prop1: " + config.getString("test.property2"));
            } catch (Exception e) {
                System.out.println("Error: " + e.toString());
            }
        } else {
            System.out.println("Error: The specified properties file does not exist: " + propFileName);
        }
    } else {
        System.out.println("Error: A required properties file was not specified.");
    }
}

From source file:org.eclipse.winery.repository.configuration.Environment.java

/**
 * Overwrite configuration parameters by using the given file
 *
 * @param path a path pointing to a file where the configuration should be read from
 *//*from ww  w. j a  v  a  2s. co  m*/
public static void copyConfiguration(Path path) throws Exception {
    Configurations configs = new Configurations();
    Configuration configuration = configs.properties(path.toFile());
    copyConfiguration(configuration);
}

From source file:org.eclipse.winery.repository.configuration.Environment.java

/**
 * Overwrite configuration parameters by using the given URL
 *
 * @param url a URL pointing to a file where the configuration should be read from
 *///from   w w w  . j  a v  a2  s .c  om
public static void copyConfiguration(URL url) throws Exception {
    Configurations configs = new Configurations();
    Configuration configuration = configs.properties(url);
    copyConfiguration(configuration);
}