本文整理汇总了Java中org.apache.commons.configuration2.FileBasedConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java FileBasedConfiguration类的具体用法?Java FileBasedConfiguration怎么用?Java FileBasedConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileBasedConfiguration类属于org.apache.commons.configuration2包,在下文中一共展示了FileBasedConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showBoard
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
@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();
}
示例2: savePropertyForStandaloneProfile
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
/**
* 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);
}
}
示例3: createPropertiesConfiguration
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
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;
}
示例4: createConfiguration
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
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;
}
示例5: Config
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
/**
* 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);
}
}
示例6: testOverride
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
@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();
}
}
示例7: AliceRecognition
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
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());
}
}
示例8: init
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
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();
}
示例9: init
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
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();
}
示例10: init
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
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();
}
示例11: firstInit
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
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();
}
示例12: loadConfigurationManager
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
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);
}
}
示例13: PropertiesConfigurationSource
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
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;
}
示例14: XmlConfigurationSource
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
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;
}
示例15: Config
import org.apache.commons.configuration2.FileBasedConfiguration; //导入依赖的package包/类
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");
}
}