Java 类org.apache.commons.configuration2.FileBasedConfiguration 实例源码

项目: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;
}
项目:sbc-qsystem    文件:OrangeMainboard.java   
@Override
public void showBoard() {
    File paramFile = new File("config/mainboardfx.properties");
    try {
        final FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(
            PropertiesConfiguration.class)
            .configure(
                new FileBasedBuilderParametersImpl().setFile(paramFile).setEncoding("utf8"));
        cfg = builder.getConfiguration();
    } catch (ConfigurationException ex) {
        QLog.l().logger()
            .error("Не загружен файл конфигурации " + paramFile.getAbsolutePath(), ex);
        throw new ServerException(
            "Не загружен файл конфигурации " + paramFile.getAbsolutePath());
    }

    super.showBoard();
}
项目: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);
    }
}
项目: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();
    }
}
项目: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());
    }
}
项目:fwm    文件:HotkeyController.java   
public static void init() throws ConfigurationException {
    configManager = new Configurations();
    builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
            .configure(configManager.getParameters().fileBased().setFile(App.appFileUtil.getHotkeysFile()));
    config = builder.getConfiguration();
    loadHotkeys();
}
项目:fwm    文件:WorldConfig.java   
public static void init(String worldLocation) throws ConfigurationException {
    log.debug("World Location for properties: " + worldLocation);
    configManager = new Configurations();
    if(worldLocation == null){
        builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
            .configure(configManager.getParameters().fileBased().setFileName(defaultWorldPropertiesLocation));
    }else
    {
        builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
                .configure(configManager.getParameters().fileBased().setFileName(worldLocation));
    }
    config = builder.getConfiguration();        
}
项目:fwm    文件:AppConfig.java   
public static void init() throws ConfigurationException {
    configManager = new Configurations();
    builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
            .configure(configManager.getParameters().fileBased().setFile(App.appFileUtil.getAppPropFile()));

    config = builder.getConfiguration();        
}
项目:fwm    文件:AppConfig.java   
public static void firstInit() throws Exception{
    configManager = new Configurations();

    builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
            .configure(configManager.getParameters().fileBased().setFileName("src/main/resources/app.properties"));

    config = builder.getConfiguration();
}
项目:beadledom    文件:PropertiesConfigurationSource.java   
private PropertiesConfigurationSource(FileBasedConfiguration configuration, int priority) {
  if (configuration == null) {
    throw new NullPointerException("configuration: null");
  }
  if (priority < 0) {
    throw new IllegalArgumentException("priority of a configuration cannot be negative");
  }

  this.configuration = configuration;
  this.priority = priority;
}
项目:beadledom    文件:XmlConfigurationSource.java   
private XmlConfigurationSource(FileBasedConfiguration configuration, int priority) {
  if (configuration == null) {
    throw new NullPointerException("configuration: null");
  }
  if (priority < 0) {
    throw new IllegalArgumentException("priority of a configuration cannot be negative");
  }

  this.configuration = configuration;
  this.priority = priority;
}
项目: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");
        }
    }
项目: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());
    }
}
项目: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();
    }

}