本文整理汇总了Java中org.apache.commons.configuration2.PropertiesConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java PropertiesConfiguration类的具体用法?Java PropertiesConfiguration怎么用?Java PropertiesConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PropertiesConfiguration类属于org.apache.commons.configuration2包,在下文中一共展示了PropertiesConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showBoard
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的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.PropertiesConfiguration; //导入依赖的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.PropertiesConfiguration; //导入依赖的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: Config
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的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);
}
}
示例5: buildFromConfig
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的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);
}
}
示例6: testOverride
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的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: modifyAndSave
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的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);
}
}
示例8: AliceRecognition
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的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());
}
}
示例9: init
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的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();
}
示例10: init
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的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();
}
示例11: init
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的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();
}
示例12: firstInit
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的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();
}
示例13: loadConfigurationManager
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的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);
}
}
示例14: ConfigurationManager
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的package包/类
private ConfigurationManager() throws ConfigurationException{
FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class)
.configure(new Parameters().properties()
.setFileName(configFilePath)
.setThrowExceptionOnMissing(true)
.setListDelimiterHandler(new DefaultListDelimiterHandler(';'))
.setIncludesAllowed(false));
config = builder.getConfiguration();
}
示例15: getPropertiesConfiguration
import org.apache.commons.configuration2.PropertiesConfiguration; //导入依赖的package包/类
private static PropertiesConfiguration getPropertiesConfiguration(final String fileName) throws ConfigurationException {
val propertiesPath = ofNullable(ClassLoader.getSystemClassLoader().getResource(fileName))
.map(URL::getFile)
.orElseThrow(IllegalArgumentException::new);
return new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class)
.configure(new Parameters().properties().setFile(new File(propertiesPath)))
.getConfiguration();
}