Java 类org.apache.commons.configuration2.builder.fluent.Parameters 实例源码

项目:ProjectAltaria    文件:ConfigurationManager.java   
private void loadConfigurationManager() {
    log.trace(() -> "Initializing configuration cache.");

    @NotNull Parameters params = new Parameters();

    FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
            new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
                    .configure(params.properties()
                            .setFileName(PROPERTIES_FILE));

    try {
        this.config = builder.getConfiguration();
    } catch (ConfigurationException e) {
        log.fatal(e);
        throw new RuntimeException("Couldnt load configuration file " + PROPERTIES_FILE);
    }
}
项目:cas-5.1.0    文件:CasConfigurationPropertiesEnvironmentManager.java   
/**
 * Save property for standalone profile.
 *
 * @param pair the pair
 */
public void savePropertyForStandaloneProfile(final Pair<String, String> pair) {
    try {
        final File file = getStandaloneProfileConfigurationDirectory();
        final Parameters params = new Parameters();

        final FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
                new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
                        .configure(params.properties().setFile(new File(file, getApplicationName() + ".properties")));

        final Configuration config = builder.getConfiguration();
        config.setProperty(pair.getKey(), pair.getValue());
        builder.save();
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
项目:beadledom    文件:PropertiesConfigurationSource.java   
private static FileBasedConfiguration createPropertiesConfiguration(Reader reader)
    throws ConfigurationException, IOException {
  if (reader == null) {
    throw new NullPointerException("reader: null");
  }

  FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
      new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
          .configure(new Parameters()
              .properties()
              .setListDelimiterHandler(new DefaultListDelimiterHandler(',')));

  FileBasedConfiguration config = builder.getConfiguration();
  config.read(reader);
  return config;
}
项目:beadledom    文件:XmlConfigurationSource.java   
private static FileBasedConfiguration createConfiguration(Reader reader)
    throws ConfigurationException {
  if (reader == null) {
    throw new NullPointerException("reader: null");
  }

  FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
      new FileBasedConfigurationBuilder<FileBasedConfiguration>(XMLConfiguration.class)
          .configure(new Parameters().xml());

  FileBasedConfiguration fileBasedConfiguration = builder.getConfiguration();

  FileHandler handler = new FileHandler(fileBasedConfiguration);
  handler.load(reader);
  return fileBasedConfiguration;
}
项目:sponge    文件:DefaultConfigurationManager.java   
protected Pair<XMLConfiguration, URL> createXmlConfiguration(String fileName) {
    List<Lookup> lookups = Arrays.asList(new SystemPropertiesLookup(), new HomeLookup(), new ConfigLookup());

    Parameters params = new Parameters();
    FallbackBasePathLocationStrategy locationStrategy =
            new FallbackBasePathLocationStrategy(FileLocatorUtils.DEFAULT_LOCATION_STRATEGY, home);
    FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class)
            .configure(params.xml().setDefaultLookups(lookups).setLocationStrategy(locationStrategy).setFileName(fileName)
                    .setSchemaValidation(true).setEntityResolver(new ResourceSchemaResolver()));

    try {
        XMLConfiguration xmlConfiguration = builder.getConfiguration();

        return new ImmutablePair<>(xmlConfiguration, locationStrategy.getLocatedUrl());
    } catch (ConfigurationException e) {
        throw new ConfigException(e);
    }
}
项目:yadaframework    文件:YadaAppConfig.java   
/**
     * Ritorna una istanza di YadaConfiguration. Il progetto deve dichiarare la sua sottoclasse specifica in configuration.xml e fare un override
     * di questo metodo per ritornare il tipo castato alla sottoclasse, oltre ad aggiungere @Bean
     * @return
     * @throws ConfigurationException 
     */
    protected void makeCombinedConfiguration(YadaConfiguration yadaConfiguration) throws ConfigurationException {
        Parameters params = new Parameters();
        ReloadingCombinedConfigurationBuilder builder = new ReloadingCombinedConfigurationBuilder()
            .configure(
                params.fileBased()
                    .setFile(new File("configuration.xml"))
                );
        yadaConfiguration.setBuilder(builder);
//      yadaConfiguration.setConfiguration(ConfigurationUtils.unmodifiableConfiguration(builder.getConfiguration()));

//      builder.addEventListener(ConfigurationBuilderEvent.CONFIGURATION_REQUEST, new EventListener<Event>() {
//          @Override
//          public void onEvent(Event event) {
//              builder.getReloadingController().checkForReloading(null);
////                try {
////                    yadaConfiguration.setConfiguration(ConfigurationUtils.unmodifiableConfiguration(builder.getConfiguration()));
////                } catch (ConfigurationException e) {
////                    log.error("Can't reload configuration (ignored)", e);
////                }
//          }
//      });
    }
项目:MockTCPServer    文件:ConfigurationSettings.java   
private FileBasedConfigurationBuilder<XMLConfiguration> getConfigurationBuilder() {
    if (this.configurationBuilder == null) {
        final Parameters params = new Parameters();
        this.configurationBuilder = new FileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class)
                .configure(params.xml()
                        .setURL(this.getFileName())
                        .setValidating(false));
        this.configurationBuilder.setAutoSave(true);

        // If the file has not yet been written to the disk, as this is the first execution or the file has been deleted (deletion is a legitimate way to "reset to factory settings"), write it now.
        if (this.isConfigurationInitialisationEnabled() && !this.getDefaultFile().exists()) {
            // Reinitialise in order to pick up the newly created file.
            this.propertiesFile = null;
            this.save();
            this.configurationBuilder = null;
            this.getConfigurationBuilder();
        }
    }

    return this.configurationBuilder;
}
项目: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);
    }
}
项目:personal    文件:PropertyOverrideTest.java   
@Test
public void testOverride() {

    Parameters params = new Parameters();
    FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
            new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
                    .configure(params.properties()
                            .setFileName("file.properties"));
    Configuration config = null;
    try {
        config = builder.getConfiguration();
        config.setProperty("somekey", "somevalue");
        builder.save();
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
}
项目:commons-configuration2-jackson    文件:JsonConfigurationTests.java   
@Test
public void readFromBuilder() throws ConfigurationException {
    // Arrange
    final FileBasedBuilderParameters params = new Parameters()
            .fileBased()
            .setThrowExceptionOnMissing(true)
            .setEncoding("UTF-8")
            .setFileName(Resources.getResource("example.json").toString());

    // Act
    final FileBasedConfigurationBuilder<JsonConfiguration> builder = new FileBasedConfigurationBuilder<>(
            JsonConfiguration.class);
    final JsonConfiguration sut = builder.configure(params).getConfiguration();

    // Assert
    assertThat(sut.getString("name"), is("testName"));
}
项目:data-prep    文件:PropertiesEncryption.java   
/**
 * Applies the specified function to the specified set of parameters contained in the input file.
 *
 * @param input The specified name of file to encrypt
 * @param mustBeModified the specified set of parameters
 * @param function the specified function to apply to the set of specified parameters
 */
private void modifyAndSave(String input, Set<String> mustBeModified, Function<String, String> function) {
    Path inputFilePath = Paths.get(input);
    if (Files.exists(inputFilePath) && Files.isRegularFile(inputFilePath) && Files.isReadable(inputFilePath)) {
        try {
            Parameters params = new Parameters();
            FileBasedConfigurationBuilder<PropertiesConfiguration> builder = //
                    new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) //
                            .configure(params.fileBased() //
                                    .setFile(inputFilePath.toFile())); //
            PropertiesConfiguration config = builder.getConfiguration();
            mustBeModified.stream().filter(config::containsKey)
                    .forEach(key -> config.setProperty(key, function.apply(config.getString(key))));

            builder.save();
        } catch (ConfigurationException e) {
            LOGGER.error("unable to read {} {}", input, e);
        }
    } else {
        LOGGER.debug("No readable file at {}", input);
    }
}
项目:carina    文件:AliceRecognition.java   
private AliceRecognition()
{
    try
    {
        CombinedConfiguration config = new CombinedConfiguration(new MergeCombiner());
        config.addConfiguration(new SystemConfiguration());
        config.addConfiguration(new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
                                      .configure(new Parameters().properties().setFileName(ALICE_PROPERTIES)).getConfiguration());

        this.enabled = config.getBoolean(ALICE_ENABLED, false);
        String url = config.getString(ALICE_SERVICE_URL, null); 
        String accessToken = config.getString(ALICE_ACCESS_TOKEN, null); 
        String command = config.getString(ALICE_COMMAND, null); 

        if(enabled && !StringUtils.isEmpty(url) && !StringUtils.isEmpty(accessToken))
        {
            this.client = new AliceClient(url, command);
            this.client.setAuthToken(accessToken);
            this.enabled = this.client.isAvailable();
        }
    }
    catch (Exception e) 
    {
        LOGGER.error("Unable to initialize Alice: " + e.getMessage());
    }
}
项目:sirocco    文件:ConfigurationManager.java   
private ConfigurationManager() throws ConfigurationException{
    FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
        new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class)
            .configure(new Parameters().properties()
            .setFileName(configFilePath)
            .setThrowExceptionOnMissing(true)
            .setListDelimiterHandler(new DefaultListDelimiterHandler(';'))
            .setIncludesAllowed(false));
    config = builder.getConfiguration();
}
项目:selenium-camp-17    文件:Configuration.java   
private static PropertiesConfiguration getPropertiesConfiguration(final String fileName) throws ConfigurationException {
    val propertiesPath = ofNullable(ClassLoader.getSystemClassLoader().getResource(fileName))
            .map(URL::getFile)
            .orElseThrow(IllegalArgumentException::new);

    return new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class)
            .configure(new Parameters().properties().setFile(new File(propertiesPath)))
            .getConfiguration();
}
项目:pm-home-station    文件:Config.java   
private Config() {

        // https://issues.apache.org/jira/browse/CONFIGURATION-677
        /*BuilderParameters params = new Parameters().properties()
            .setFileName(CONFIG_NAME)
            .setLocationStrategy(new HomeDirectoryLocationStrategy())
            .setEncoding("UTF-8");*/

        // workaround:
        HomeDirectoryLocationStrategy location = new HomeDirectoryLocationStrategy();
        File configFile = new File(location.getHomeDirectory(), CONFIG_NAME);
        BuilderParameters params = new Parameters().properties()
                .setFile(configFile)
                .setEncoding("UTF-8");

        builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(
                PropertiesConfiguration.class, params.getParameters(), true);
        builder.setAutoSave(true);

        try {
            config = builder.getConfiguration();
            logger.info("User configuration has been loaded from: {}", configFile);
        } catch(ConfigurationException cex) {
            logger.error("Error loading configuration", cex);
            throw new IllegalStateException("Error loading/creating configuration");
        }
    }
项目:hybris-maven-plugin    文件:ExtensionFactoryTest.java   
private Set<String> readExtensionNames(final File folder) throws Exception {
    try (final InputStream extensionsXML = getClass().getResourceAsStream("extensions.xml")) {
        new File(folder, "bin/platform").mkdirs();
        Files.copy(extensionsXML, new File(folder, "bin/platform/extensions.xml").toPath());
    }

    final File hybrisPlatformDirectory = new File(folder, "bin/platform");
    final File platformExtensionsFile = new File(hybrisPlatformDirectory, "extensions.xml");
    final FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(
            XMLConfiguration.class).configure(new Parameters().xml().setFile(platformExtensionsFile));
    final XMLConfiguration platformExtensionsConfiguration = builder.getConfiguration();
    final List<String> extensionNames = Lists
            .newArrayList(platformExtensionsConfiguration.getList(String.class, "extensions.extension[@name]"));
    return new HashSet<>(extensionNames);
}
项目: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;
}
项目:heapSpank    文件:ApacheCommonsConfigFile.java   
private Configuration getHomeFolderConfiguration() throws ConfigurationException {
    File homeDir = new File( System.getProperty("user.home"));

    File heapSpankProperties = new File(homeDir, this.PROPERTIES_FILE);
    Parameters params = new Parameters();

    FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
            new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
            .configure(params.properties()
                .setFile(heapSpankProperties));
    return builder.getConfiguration();
}
项目:heapSpank    文件:ApacheCommonsConfigFile.java   
private Configuration getCurrentFolderConfiguration() throws ConfigurationException {

    URL location = ApacheCommonsConfigFile.class.getProtectionDomain().getCodeSource().getLocation();
    File heapSpankjarFile = new File(location.getFile());
    File dirOfHeapSpankjarFile = new File(location.getFile()).getParentFile();
    File heapSpankProperties = new File(dirOfHeapSpankjarFile, this.PROPERTIES_FILE);
    Parameters params = new Parameters();

    FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
            new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
            .configure(params.properties()
                .setFile(heapSpankProperties));
    return builder.getConfiguration();
}
项目:feedrdr    文件:ApplicationConfig.java   
private ApplicationConfig() {
    Parameters params = new Parameters();
    FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(
            PropertiesConfiguration.class)
                    .configure(params.properties()
                            .setFileName("application.properties"));
    try {
        config = builder.getConfiguration();
    } catch (ConfigurationException e) {
        logger.error("failed to load application.properties: {}", e, e.getMessage());
    }
}
项目:commons-configuration2-jackson    文件:JsonConfigurationTests.java   
@Test
public void readCombinedConfig() throws ConfigurationException {
    // Arrange
    final ConfigurationBuilderProvider provider = new JacksonConfigurationBuilderProvider<>(JsonConfiguration.class);

    final Parameters params = new Parameters();
    final CombinedBuilderParameters combinedBuilderParameters = params.combined()
            .setDefinitionBuilderParameters(
                    params.fileBased().setFileName(Resources.getResource("combined.xml").toString())
            )
            .registerProvider("json", provider);

    // Act
    final CombinedConfigurationBuilder builder = new CombinedConfigurationBuilder();
    final CombinedConfiguration sut = builder.configure(combinedBuilderParameters).getConfiguration();

    // Assert
    assertThat(sut.getString("someFolder"), is("default"));
    assertThat(sut.getString("name"), is("testName"));
    assertThat(sut.getString("obj.name"), is("test"));
    assertThat(sut.getInt("obj.value"), is(1));
    assertThat(sut.getString("listOfObjs(0).name"), is("testname"));
    assertThat(sut.getInt("listOfObjs(0).value"), is(4));
    assertThat(sut.getString("listOfObjs(1).name"), is("other"));
    assertThat(sut.getInt("listOfObjs(1).value"), is(20));
    assertThat(sut.getStringArray("listOfObjs.name"), is(new String[]{"testname", "other"}));
    assertThat(sut.getProperty("nullValue"), is(nullValue()));
    assertThat(sut.getProperty("emptyList"), is(nullValue()));
}
项目:Wolpertinger    文件:SolverFactory.java   
private SolverFactory() {
    Configuration configuration = null;

    try {
        String baseDir = System.getProperty("user.dir");
        FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
                new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class)
                .configure(new Parameters().properties()
                    .setFileName(String.format("%s%s%s", baseDir, File.separator, PROPERTY_FILE)));
        configuration = builder.getConfiguration();
    } catch (Exception ce) {
        //log.error("There went something wrong while reading the clingo configuration. Using Default configruation.", ce);
    }

    if (configuration!=null) {
        clingoParameters = getClingoParameters(configuration);
        clingoExec = configuration.getString("clingo.exec", "clingo.exe");
    } else {
        //defaults
        if (OsUtils.isUnix())
            clingoExec = "clingo";
        else if (OsUtils.isWindows())
            clingoExec = "clingo.exe";

        clingoParameters = new String[] {"--warn=no-atom-undefined", "--quiet=0,2,2", "--verbose=0", "--project"};
    }
}
项目:aptasuite    文件:Configuration.java   
/**
 * Adds the configuration stored on disk to the current set of parameters. The
 * file <code>fileName</code> must be a valid configuration file as per Javas
 * <code>Properties</code> class.
 * 
 * @param fileName
 */
public static void setConfiguration(String fileName) {

    try {
        AptaLogger.log(Level.INFO, Configuration.class, "Reading configuration from file.");

        builder = new FileBasedConfigurationBuilder<org.apache.commons.configuration2.FileBasedConfiguration>(
                PropertiesConfiguration.class)
                        .configure(new Parameters().properties().setFileName(fileName)
                                .setListDelimiterHandler(new DefaultListDelimiterHandler(',')));


        // Create a composite configuration which allows to keep user parameters and defaults separated
        CompositeConfiguration  cc = new CompositeConfiguration(); 

        cc.addConfiguration(builder.getConfiguration(), true); // changes will be saved in the user config
        cc.addConfiguration(getDefaultParametersBuilder().getConfiguration(), false);

        parameters = cc;

    } catch (Exception e) {

        AptaLogger.log(Level.SEVERE, Configuration.class,
                "Error, could not read configuration file. Please check it for correctness");
        AptaLogger.log(Level.SEVERE, Configuration.class, e);
        e.printStackTrace();
    }


    // TODO: Sanity checks!
}
项目:aptasuite    文件:Configuration.java   
/**
 * Creates an empty configuration and configures the class 
 * @param filename location at which the config should be stored in the future
 */
public static void createConfiguration(Path filePath) {

    try {

        builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
            .configure(new Parameters().properties()
                //.setFile(filePath.toFile())
                .setListDelimiterHandler(new DefaultListDelimiterHandler(',')));

        org.apache.commons.configuration2.Configuration userParameters = builder.getConfiguration();


        //We need to explicitly save the file before setting it in the builder, for whatever reason...
        builder.getFileHandler().save(filePath.toFile());
        builder.getFileHandler().setFile(filePath.toFile());

        // Create a composite configuration which allows to keep user parameters and defaults separated
        CompositeConfiguration  cc = new CompositeConfiguration();

        cc.addConfiguration(builder.getConfiguration(), true); // changes will be saved in the user config
        cc.addConfiguration(getDefaultParametersBuilder().getConfiguration(), false);

        parameters = cc;

    } catch (Exception e) {

        AptaLogger.log(Level.SEVERE, Configuration.class,
                "Error, could not create configuration file.");
        AptaLogger.log(Level.SEVERE, Configuration.class, e);
        e.printStackTrace();
    }

}