Java 类org.apache.commons.configuration2.io.ClasspathLocationStrategy 实例源码

项目:opennlp-enhancer    文件:Config.java   
/**
 * Instantiates a new config.
 */
private Config() {
    try {
        Parameters params = new Parameters();
        FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(
                PropertiesConfiguration.class);
        builder.configure(params.fileBased().setFileName("nlp.properties")
                .setLocationStrategy(new ClasspathLocationStrategy()));
        configuration = builder.getConfiguration();
        // Adding TEKSTO_HOME path to Configuration
        String homePath = System.getenv(TEKSTO_HOME);
        if (homePath != null && !homePath.isEmpty()) {
            configuration.setProperty(MODEL_PATH, homePath + "/Models");
        }
    } catch (ConfigurationException e) {
        LOG.error(e, e);
    }
}
项目:loginsight-java-api    文件:Configuration.java   
/**
 * Builds the Configuration object from the properties file (apache commons
 * properties file format). <br>
 * The values provided in the config file will be overwritten environment
 * variables (if present)
 * 
 * List of the properties <br>
 * loginsight.host = host name <br>
 * loginsight.port = port number <br>
 * loginsight.user = User name <br>
 * loginsight.password = password <br>
 * loginsight.ingestion.agentId = agentId <br>
 * loginsight.connection.scheme = http protocol scheme <br>
 * loginsight.ingestion.port = Ingestion port number <br>
 * 
 * @param configFileName
 *            Name of the config file to read
 * @return Newly created Configuration object
 */
public static Configuration buildFromConfig(String configFileName) {
    try {
        List<FileLocationStrategy> subs = Arrays.asList(new ProvidedURLLocationStrategy(),
                new FileSystemLocationStrategy(), new ClasspathLocationStrategy());
        FileLocationStrategy strategy = new CombinedLocationStrategy(subs);

        FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(
                PropertiesConfiguration.class).configure(
                        new Parameters().fileBased().setLocationStrategy(strategy).setFileName(configFileName));
        PropertiesConfiguration propConfig = builder.getConfiguration();
        Map<String, String> propMap = new HashMap<String, String>();
        Iterator<String> keys = propConfig.getKeys();
        keys.forEachRemaining(key -> {
            logger.info(key + ":" + propConfig.getString(key));
            propMap.put(key, propConfig.getString(key));
        });
        Configuration config = Configuration.buildConfig(propMap);
        config.loadFromEnv();
        return config;
    } catch (ConfigurationException e1) {
        throw new RuntimeException("Unable to load config", e1);
    }
}
项目:MockTCPServer    文件:ConfigurationSettings.java   
/**
 * The file {@link URL} can be absolute or relative to the working folder. The configuration file is located using a {@link FileLocatorUtils#DEFAULT_LOCATION_STRATEGY strategy} that uses a number of techniques to determine the file location.
 * <p>
 * If no file is found, the {@link #FILENAME resource file} is used.
 *
 * @return the configuration file {@link URL}.
 */
public URL getFileName() {
    if (this.propertiesFile == null) {
        final List<FileLocationStrategy> subs = Arrays.asList(
                new ProvidedURLLocationStrategy(),
                new FileSystemLocationStrategy(),
                new ClasspathLocationStrategy());
        final FileLocationStrategy strategy = new CombinedLocationStrategy(subs);

        FileLocator fileLocator = FileLocatorUtils.fileLocator()
                .basePath(this.getDefaultFile().getParent())
                .fileName(this.getDefaultFile().getName())
                .create();

        if (!new File(FileLocatorUtils.locate(fileLocator).getFile()).exists()) {
            fileLocator = FileLocatorUtils.fileLocator()
                    .fileName(this.getDefaultFile().getName())
                    .locationStrategy(strategy)
                    .create();
        }

        this.propertiesFile = FileLocatorUtils.locate(fileLocator);

        // Ensure that the ConfigurationBuilder is now initialised as that may force a re-initialisation of this FileLocator.
        this.getConfigurationBuilder();
    }

    return this.propertiesFile;
}
项目:pdf-segmenter    文件:Config.java   
/**
 * Instantiates a new config.
 */
private Config() {
    try {
        Parameters params = new Parameters();
        FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(
                PropertiesConfiguration.class);
        builder.configure(params.fileBased().setFileName("pdf2xml.properties").setLocationStrategy(new ClasspathLocationStrategy()));
        configuration = builder.getConfiguration();
    } catch (ConfigurationException e) {
        LOG.error(e, e);
    }
}
项目:heapSpank    文件:ApacheCommonsConfigFile.java   
private Configuration getHeapSpankJarConfiguration() throws ConfigurationException {
    Parameters params = new Parameters();
    FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
        new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
            .configure(params.properties()
            .setFileName(PROPERTIES_FILE)
            .setLocationStrategy(new ClasspathLocationStrategy())
            );      
    Configuration config = builder.getConfiguration();      
    return config;
}