本文整理汇总了Java中org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder类的典型用法代码示例。如果您正苦于以下问题:Java FileBasedConfigurationBuilder类的具体用法?Java FileBasedConfigurationBuilder怎么用?Java FileBasedConfigurationBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileBasedConfigurationBuilder类属于org.apache.commons.configuration2.builder包,在下文中一共展示了FileBasedConfigurationBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showBoard
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入依赖的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.builder.FileBasedConfigurationBuilder; //导入依赖的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.builder.FileBasedConfigurationBuilder; //导入依赖的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.builder.FileBasedConfigurationBuilder; //导入依赖的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: createXmlConfiguration
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入依赖的package包/类
protected Pair<XMLConfiguration, URL> createXmlConfiguration(String fileName) {
List<Lookup> lookups = Arrays.asList(new SystemPropertiesLookup(), new HomeLookup(), new ConfigLookup());
Parameters params = new Parameters();
FallbackBasePathLocationStrategy locationStrategy =
new FallbackBasePathLocationStrategy(FileLocatorUtils.DEFAULT_LOCATION_STRATEGY, home);
FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class)
.configure(params.xml().setDefaultLookups(lookups).setLocationStrategy(locationStrategy).setFileName(fileName)
.setSchemaValidation(true).setEntityResolver(new ResourceSchemaResolver()));
try {
XMLConfiguration xmlConfiguration = builder.getConfiguration();
return new ImmutablePair<>(xmlConfiguration, locationStrategy.getLocatedUrl());
} catch (ConfigurationException e) {
throw new ConfigException(e);
}
}
示例6: getConfigurationBuilder
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入依赖的package包/类
private FileBasedConfigurationBuilder<XMLConfiguration> getConfigurationBuilder() {
if (this.configurationBuilder == null) {
final Parameters params = new Parameters();
this.configurationBuilder = new FileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class)
.configure(params.xml()
.setURL(this.getFileName())
.setValidating(false));
this.configurationBuilder.setAutoSave(true);
// If the file has not yet been written to the disk, as this is the first execution or the file has been deleted (deletion is a legitimate way to "reset to factory settings"), write it now.
if (this.isConfigurationInitialisationEnabled() && !this.getDefaultFile().exists()) {
// Reinitialise in order to pick up the newly created file.
this.propertiesFile = null;
this.save();
this.configurationBuilder = null;
this.getConfigurationBuilder();
}
}
return this.configurationBuilder;
}
示例7: Config
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入依赖的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);
}
}
示例8: buildFromConfig
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入依赖的package包/类
/**
* Builds the Configuration object from the properties file (apache commons
* properties file format). <br>
* The values provided in the config file will be overwritten environment
* variables (if present)
*
* List of the properties <br>
* loginsight.host = host name <br>
* loginsight.port = port number <br>
* loginsight.user = User name <br>
* loginsight.password = password <br>
* loginsight.ingestion.agentId = agentId <br>
* loginsight.connection.scheme = http protocol scheme <br>
* loginsight.ingestion.port = Ingestion port number <br>
*
* @param configFileName
* Name of the config file to read
* @return Newly created Configuration object
*/
public static Configuration buildFromConfig(String configFileName) {
try {
List<FileLocationStrategy> subs = Arrays.asList(new ProvidedURLLocationStrategy(),
new FileSystemLocationStrategy(), new ClasspathLocationStrategy());
FileLocationStrategy strategy = new CombinedLocationStrategy(subs);
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(
PropertiesConfiguration.class).configure(
new Parameters().fileBased().setLocationStrategy(strategy).setFileName(configFileName));
PropertiesConfiguration propConfig = builder.getConfiguration();
Map<String, String> propMap = new HashMap<String, String>();
Iterator<String> keys = propConfig.getKeys();
keys.forEachRemaining(key -> {
logger.info(key + ":" + propConfig.getString(key));
propMap.put(key, propConfig.getString(key));
});
Configuration config = Configuration.buildConfig(propMap);
config.loadFromEnv();
return config;
} catch (ConfigurationException e1) {
throw new RuntimeException("Unable to load config", e1);
}
}
示例9: testOverride
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入依赖的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();
}
}
示例10: readFromBuilder
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入依赖的package包/类
@Test
public void readFromBuilder() throws ConfigurationException {
// Arrange
final FileBasedBuilderParameters params = new Parameters()
.fileBased()
.setThrowExceptionOnMissing(true)
.setEncoding("UTF-8")
.setFileName(Resources.getResource("example.json").toString());
// Act
final FileBasedConfigurationBuilder<JsonConfiguration> builder = new FileBasedConfigurationBuilder<>(
JsonConfiguration.class);
final JsonConfiguration sut = builder.configure(params).getConfiguration();
// Assert
assertThat(sut.getString("name"), is("testName"));
}
示例11: modifyAndSave
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入依赖的package包/类
/**
* Applies the specified function to the specified set of parameters contained in the input file.
*
* @param input The specified name of file to encrypt
* @param mustBeModified the specified set of parameters
* @param function the specified function to apply to the set of specified parameters
*/
private void modifyAndSave(String input, Set<String> mustBeModified, Function<String, String> function) {
Path inputFilePath = Paths.get(input);
if (Files.exists(inputFilePath) && Files.isRegularFile(inputFilePath) && Files.isReadable(inputFilePath)) {
try {
Parameters params = new Parameters();
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = //
new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) //
.configure(params.fileBased() //
.setFile(inputFilePath.toFile())); //
PropertiesConfiguration config = builder.getConfiguration();
mustBeModified.stream().filter(config::containsKey)
.forEach(key -> config.setProperty(key, function.apply(config.getString(key))));
builder.save();
} catch (ConfigurationException e) {
LOGGER.error("unable to read {} {}", input, e);
}
} else {
LOGGER.debug("No readable file at {}", input);
}
}
示例12: AliceRecognition
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入依赖的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());
}
}
示例13: init
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入依赖的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();
}
示例14: init
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入依赖的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();
}
示例15: init
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入依赖的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();
}