当前位置: 首页>>代码示例>>Java>>正文


Java FileConfiguration类代码示例

本文整理汇总了Java中org.apache.commons.configuration.FileConfiguration的典型用法代码示例。如果您正苦于以下问题:Java FileConfiguration类的具体用法?Java FileConfiguration怎么用?Java FileConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileConfiguration类属于org.apache.commons.configuration包,在下文中一共展示了FileConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initConfig

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
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();
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:19,代码来源:ConfigurationSubscription.java

示例2: getConfig

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:chhh,项目名称:batmass,代码行数:27,代码来源:Map2DOptions.java

示例3: configuration

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
@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;
}
 
开发者ID:shilongdai,项目名称:LSChatServer,代码行数:13,代码来源:ApplicationRootContext.java

示例4: loadView

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
private void loadView(FileConfiguration fileConfig) {
    Iterator fileIter = fileConfig.getKeys();
    while (fileIter.hasNext()) {
        String key = (String) fileIter.next();
        setViewProperty(fileConfig, key, fileConfig.getProperty(key));
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:8,代码来源:ConfigurationSubscription.java

示例5: setViewProperty

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
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));
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:9,代码来源:ConfigurationSubscription.java

示例6: getNewPropertiesConfiguration

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:43,代码来源:ReloadablePropertySourceTest.java

示例7: save

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
public static void save(Configuration configuration) throws ConfigurationException {
    FileConfiguration fileConfiguration =
            getWritableFileConfiguration(configuration);
    if (fileConfiguration == null) {
        throw new ConfigurationException("Cannot save configuration");
    } else {
        fileConfiguration.save();
    }
}
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:10,代码来源:CommonsConfigurationUtils.java

示例8: getWritableFileConfiguration

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
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;
    }
}
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:14,代码来源:CommonsConfigurationUtils.java

示例9: reload

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
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();
    }
  }
}
 
开发者ID:otros-systems,项目名称:otroslogviewer,代码行数:30,代码来源:ConfigComponent.java

示例10: flushUserConfigToDefault

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
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;
}
 
开发者ID:chhh,项目名称:batmass,代码行数:14,代码来源:Map2DOptions.java

示例11: getUserConfig

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:chhh,项目名称:batmass,代码行数:13,代码来源:Map2DOptions.java

示例12: store

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
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();
}
 
开发者ID:chhh,项目名称:batmass,代码行数:12,代码来源:Map2DOptionsPanel.java

示例13: update

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
@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");
    }
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:35,代码来源:SettingsAction.java

示例14: update

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
@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");
	}
}
 
开发者ID:hongliangpan,项目名称:manydesigns.cn,代码行数:37,代码来源:CrudAction4ReportExport.java

示例15: getFileConfiguration

import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
public FileConfiguration getFileConfiguration(){
	return this.config;
}
 
开发者ID:xnx3,项目名称:xnx3,代码行数:4,代码来源:ConfigManagerUtil.java


注:本文中的org.apache.commons.configuration.FileConfiguration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。