本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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));
}
}
示例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));
}
}
示例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;
}
示例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();
}
}
示例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;
}
}
示例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();
}
}
}
示例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;
}
示例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;
}
示例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();
}
示例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");
}
}
示例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");
}
}
示例15: getFileConfiguration
import org.apache.commons.configuration.FileConfiguration; //导入依赖的package包/类
public FileConfiguration getFileConfiguration(){
return this.config;
}