Java 类org.apache.commons.configuration.FileConfiguration 实例源码

项目:distributedlog    文件:ConfigurationSubscription.java   
private boolean initConfig() {
    if (fileConfigs.isEmpty()) {
        try {
            for (FileConfigurationBuilder fileConfigBuilder : fileConfigBuilders) {
                FileConfiguration fileConfig = fileConfigBuilder.getConfiguration();
                FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
                reloadingStrategy.setRefreshDelay(0);
                fileConfig.setReloadingStrategy(reloadingStrategy);
                fileConfigs.add(fileConfig);
            }
        } catch (ConfigurationException ex) {
            if (!fileNotFound(ex)) {
                LOG.error("Config init failed {}", ex);
            }
        }
    }
    return !fileConfigs.isEmpty();
}
项目:batmass    文件:Map2DOptions.java   
/**
 * The combined config = current user config + defaults for non-specified properties.
 * TODO: instead of re-reading user config every time, it would be better
 *       to set up Commons Configuration listeners on the userfile.
 * @return even if reading user config fails, will return default config
 */
public CompositeConfiguration getConfig() {

    // try loading user config
    FileConfiguration userConfig = null;
    try {
        userConfig = BmConfig.forClass(BaseMap2D.class);
    } catch (ConfigurationException | IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    CompositeConfiguration compositeConfig = new CompositeConfiguration();
    // the order of adding configurations to combined configuration is important
    // whoever is added first "shadows" the same key in all subsequently added
    // configuraions. Thus, add the DEFAULTs at the very end
    if (userConfig != null) {
        compositeConfig.addConfiguration(userConfig);
    }
    compositeConfig.addConfiguration(defaultConfig);

    return compositeConfig;
}
项目:LSChatServer    文件:ApplicationRootContext.java   
@Bean
public FileConfiguration configuration() throws IOException, ConfigurationException {
    Path configFile = Paths.get("config");
    if (!configFile.toFile().exists()) {
        Files.createFile(configFile);
    }
    PropertiesConfiguration config = new PropertiesConfiguration();
    config.setFileName(configFile.toString());
    config.setAutoSave(true);
    config.load();
    return config;
}
项目:distributedlog    文件:ConfigurationSubscription.java   
private void loadView(FileConfiguration fileConfig) {
    Iterator fileIter = fileConfig.getKeys();
    while (fileIter.hasNext()) {
        String key = (String) fileIter.next();
        setViewProperty(fileConfig, key, fileConfig.getProperty(key));
    }
}
项目:distributedlog    文件:ConfigurationSubscription.java   
private void setViewProperty(FileConfiguration fileConfig,
                             String key,
                             Object value) {
    if (!viewConfig.containsKey(key) || !viewConfig.getProperty(key).equals(value)) {
        LOG.debug("Setting property, key={} value={}", key, fileConfig.getProperty(key));
        viewConfig.setProperty(key, fileConfig.getProperty(key));
    }
}
项目:herd    文件:ReloadablePropertySourceTest.java   
/**
 * Gets a new properties configuration that will re-load the properties from a file every time it is called.
 *
 * @return the properties configuration.
 * @throws ConfigurationException if the properties configuration couldn't be created.
 */
private PropertiesConfiguration getNewPropertiesConfiguration() throws ConfigurationException
{
    // Create a new properties configuration.
    // We are using this instead of a database configuration for easier testing.
    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(propertiesFile);

    // Create a reloading strategy that will always reload when asked.
    // There were some problems using the FileChangedReloadingStrategy where it wasn't detecting changed files and causing some methods in this
    // JUnit to fail.
    propertiesConfiguration.setReloadingStrategy(new ReloadingStrategy()
    {
        @Override
        public void setConfiguration(FileConfiguration configuration)
        {
        }

        @Override
        public void init()
        {
        }

        @Override
        public boolean reloadingRequired()
        {
            // Tell the caller that the properties should always be reloaded.
            return true;
        }

        @Override
        public void reloadingPerformed()
        {
        }
    });

    return propertiesConfiguration;
}
项目:Portofino    文件:CommonsConfigurationUtils.java   
public static void save(Configuration configuration) throws ConfigurationException {
    FileConfiguration fileConfiguration =
            getWritableFileConfiguration(configuration);
    if (fileConfiguration == null) {
        throw new ConfigurationException("Cannot save configuration");
    } else {
        fileConfiguration.save();
    }
}
项目:Portofino    文件:CommonsConfigurationUtils.java   
public static FileConfiguration getWritableFileConfiguration(Configuration configuration) {
    if (configuration instanceof FileConfiguration) {
        return (FileConfiguration)configuration;
    } else if (configuration instanceof CompositeConfiguration) {
        CompositeConfiguration compositeConfiguration =
                (CompositeConfiguration)configuration;
        Configuration inMemoryConfigutation =
                compositeConfiguration.getInMemoryConfiguration();
        return getWritableFileConfiguration(inMemoryConfigutation);
    } else {
        return null;
    }
}
项目:otroslogviewer    文件:ConfigComponent.java   
public void reload() {
  boolean mainConfigLoaded = false;
  for (ConfigView configView : configViews) {
    Configuration configurationForView;

    try {
      configurationForView = configurationProvider.getConfigurationForView(configView);
      if (configurationForView instanceof DataConfiguration) {
        DataConfiguration dc = (DataConfiguration) configurationForView;
        configurationForView = dc.getConfiguration();
      }
      if (configurationForView instanceof FileConfiguration) {
        FileConfiguration fc = (FileConfiguration) configurationForView;
        if (configView instanceof InMainConfig) {
          if (!mainConfigLoaded) {
            fc.reload();
            mainConfigLoaded = true;
          }
        } else {
          fc.reload();
        }
        configView.loadConfiguration(fc);
      }
    } catch (ConfigurationException e1) {
      //TODO ??
      e1.printStackTrace();
    }
  }
}
项目:batmass    文件:Map2DOptions.java   
public Configuration flushUserConfigToDefault() {
    FileConfiguration userConfig = null;
    try {
        userConfig = BmConfig.forClass(BaseMap2D.class);
        userConfig.clear();
        userConfig.save();
        userConfig = BmConfig.forClass(BaseMap2D.class);
    } catch (ConfigurationException | IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    defaultConfig = readDefaultConfig();
    return userConfig;
}
项目:batmass    文件:Map2DOptions.java   
/**
 * Gets only the properties stored in user.dir in Netbeans App.
 * @return null if something went wrong during retrieving userconfig
 */
public FileConfiguration getUserConfig() {
    try {
        return BmConfig.forClass(BaseMap2D.class);
    } catch (ConfigurationException | IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return null;
}
项目:batmass    文件:Map2DOptionsPanel.java   
void store() throws ConfigurationException, IOException {
    updateConfigToUIState();

    FileConfiguration userConfig = BmConfig.forClass(BaseMap2D.class);
    for (Iterator<String> i = config.getKeys(); i.hasNext();) {
        String key = i.next();
        Object value = config.getProperty(key);
        userConfig.setProperty(key, value);
    }
    userConfig.save();
}
项目:manydesigns.cn    文件:SettingsAction.java   
@Button(list = "settings", key = "update", order = 1, type = Button.TYPE_PRIMARY)
public Resolution update() {
    setupFormAndBean();
    form.readFromRequest(context.getRequest());
    if (form.validate()) {
        logger.debug("Applying settings to model");
        try {
            FileConfiguration fileConfiguration = (FileConfiguration) configuration;
            Settings settings = new Settings();
            form.writeToObject(settings);
            fileConfiguration.setProperty(PortofinoProperties.APP_NAME, settings.appName);
            fileConfiguration.setProperty(PortofinoProperties.LANDING_PAGE, settings.landingPage);
            fileConfiguration.setProperty(PortofinoProperties.LOGIN_PAGE, settings.loginPage);
            if(!settings.preloadGroovyPages ||
               fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES) != null) {
                fileConfiguration.setProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES, settings.preloadGroovyPages);
            }
            if(!settings.preloadGroovyClasses ||
               fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES) != null) {
                fileConfiguration.setProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES, settings.preloadGroovyClasses);
            }
            fileConfiguration.save();
            logger.info("Configuration saved to " + fileConfiguration.getFile().getAbsolutePath());
        } catch (Exception e) {
            logger.error("Configuration not saved", e);
            SessionMessages.addErrorMessage(ElementsThreadLocals.getText("the.configuration.could.not.be.saved"));
            return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp");
        }
        SessionMessages.addInfoMessage(ElementsThreadLocals.getText("configuration.updated.successfully"));
        return new RedirectResolution(this.getClass());
    } else {
        return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp");
    }
}
项目:manydesigns.cn    文件:CrudAction4ReportExport.java   
@Button(list = "settings", key = "update", order = 1, type = Button.TYPE_PRIMARY)
public Resolution update() {
    setupFormAndBean();
    form.readFromRequest(context.getRequest());
    if (form.validate()) {
        logger.debug("Applying settings to model");
        try {
            FileConfiguration fileConfiguration = (FileConfiguration) configuration;
            Settings settings = new Settings();
            form.writeToObject(settings);
            fileConfiguration.setProperty(PortofinoProperties.APP_NAME, settings.appName);
            fileConfiguration.setProperty(PortofinoProperties.LANDING_PAGE, settings.landingPage);
            fileConfiguration.setProperty(PortofinoProperties.LOGIN_PAGE, settings.loginPage);
            if (!settings.preloadGroovyPages
                    || fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES) != null) {
                fileConfiguration
                        .setProperty(PortofinoProperties.GROOVY_PRELOAD_PAGES, settings.preloadGroovyPages);
            }
            if (!settings.preloadGroovyClasses
                    || fileConfiguration.getProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES) != null) {
                fileConfiguration.setProperty(PortofinoProperties.GROOVY_PRELOAD_CLASSES,
                        settings.preloadGroovyClasses);
            }
            fileConfiguration.save();
            logger.info("Configuration saved to " + fileConfiguration.getFile().getAbsolutePath());
        } catch (Exception e) {
            logger.error("Configuration not saved", e);
            SessionMessages.addErrorMessage(ElementsThreadLocals.getText("the.configuration.could.not.be.saved"));
            return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp");
        }
        SessionMessages.addInfoMessage(ElementsThreadLocals.getText("configuration.updated.successfully"));
        return new RedirectResolution(this.getClass());
    } else {
        return new ForwardResolution("/m/pageactions/actions/admin/settings.jsp");
    }
}
项目:xnx3    文件:ConfigManagerUtil.java   
public FileConfiguration getFileConfiguration(){
    return this.config;
}
项目:grakn    文件:GraknSparkComputer.java   
public static void main(final String[] args) throws Exception {
    final FileConfiguration configuration = new PropertiesConfiguration(args[0]);
    new GraknSparkComputer(HadoopGraph.open(configuration))
            .program(VertexProgram.createVertexProgram(HadoopGraph.open(configuration), configuration))
            .submit().get();
}
项目:LiteGraph    文件:GiraphGraphComputer.java   
public static void main(final String[] args) throws Exception {
    final FileConfiguration configuration = new PropertiesConfiguration(args[0]);
    new GiraphGraphComputer(HadoopGraph.open(configuration)).program(VertexProgram.createVertexProgram(HadoopGraph.open(configuration), configuration)).submit().get();
}
项目:LiteGraph    文件:SparkGraphComputer.java   
public static void main(final String[] args) throws Exception {
    final FileConfiguration configuration = new PropertiesConfiguration(args[0]);
    new SparkGraphComputer(HadoopGraph.open(configuration)).program(VertexProgram.createVertexProgram(HadoopGraph.open(configuration), configuration)).submit().get();
}
项目:distributedlog    文件:PropertiesConfigurationBuilder.java   
@Override
public FileConfiguration getConfiguration() throws ConfigurationException {
    return new PropertiesConfiguration(url);
}
项目:Contact-Manager-System    文件:ConfigurationHandler.java   
public FileConfiguration getConfiguration() {
    return configuration;
}
项目:batmass    文件:BmConfig.java   
public static FileConfiguration forClass(Class<?> clazz) throws ConfigurationException, IOException {
//         return new XMLConfiguration(getConfigFile(clazz));
         return new PropertiesConfiguration(getConfigFile(clazz));
    }
项目:tinkerpop    文件:GiraphGraphComputer.java   
public static void main(final String[] args) throws Exception {
    final FileConfiguration configuration = new PropertiesConfiguration(args[0]);
    new GiraphGraphComputer(HadoopGraph.open(configuration)).program(VertexProgram.createVertexProgram(HadoopGraph.open(configuration), configuration)).submit().get();
}
项目:tinkerpop    文件:SparkGraphComputer.java   
public static void main(final String[] args) throws Exception {
    final FileConfiguration configuration = new PropertiesConfiguration(args[0]);
    new SparkGraphComputer(HadoopGraph.open(configuration)).program(VertexProgram.createVertexProgram(HadoopGraph.open(configuration), configuration)).submit().get();
}
项目:flickring    文件:ApiKeysCommand.java   
@Inject
public ApiKeysCommand(final Configuration config, final Flickr flickr) {
  this.config = (FileConfiguration) config;
  this.flickr = flickr;
}
项目:manydesigns.cn    文件:ModuleRegistry.java   
public ModuleRegistry(FileConfiguration configuration) {
    this.configuration = configuration;
}
项目:manydesigns.cn    文件:BaseContextUtils.java   
/**
 * @return configuration - {return content description}
 */
public static FileConfiguration getConfiguration() {
    return configuration;
}
项目:manydesigns.cn    文件:BaseContextUtils.java   
/**
 * @param configuration - {parameter description}.
 */
public static void setConfiguration(FileConfiguration configuration) {
    BaseContextUtils.configuration = configuration;
}
项目:ABRAID-MP    文件:BaseConfigurationService.java   
protected FileConfiguration getConfigFile() {
    return basicProperties;
}
项目:flickring    文件:ApiKeysCommand.java   
@Inject
public ApiKeysCommand(final Configuration config, final Flickr flickr) {
  this.config = (FileConfiguration) config;
  this.flickr = flickr;
}
项目:MaduraConfiguration    文件:MaduraConfiguration.java   
public void setConfiguration(Configuration configuration)
{
    m_configuration = (FileConfiguration)configuration;
}
项目:distributedlog    文件:FileConfigurationBuilder.java   
FileConfiguration getConfiguration() throws ConfigurationException;