本文整理汇总了Java中org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder.getConfiguration方法的典型用法代码示例。如果您正苦于以下问题:Java FileBasedConfigurationBuilder.getConfiguration方法的具体用法?Java FileBasedConfigurationBuilder.getConfiguration怎么用?Java FileBasedConfigurationBuilder.getConfiguration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder
的用法示例。
在下文中一共展示了FileBasedConfigurationBuilder.getConfiguration方法的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: 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);
}
}
示例7: 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);
}
}
示例8: 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();
}
}
示例9: 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);
}
}
示例10: loadConfigurationManager
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入方法依赖的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);
}
}
示例11: ConfigurationManager
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入方法依赖的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();
}
示例12: loadConfiguration
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入方法依赖的package包/类
private static Configuration loadConfiguration() throws IOException, ConfigurationException {
Configurations configurations = new Configurations();
File file = Constants.SETTINGS_FILE_XML;
if (!file.exists()) {
XMLConfiguration tempConfiguration = new XMLConfiguration();
new FileHandler(tempConfiguration).save(file);
}
FileBasedConfigurationBuilder<XMLConfiguration> builder = configurations.xmlBuilder(file);
builder.setAutoSave(true);
return builder.getConfiguration();
}
示例13: readExtensionNames
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入方法依赖的package包/类
private Set<String> readExtensionNames(final File folder) throws Exception {
try (final InputStream extensionsXML = getClass().getResourceAsStream("extensions.xml")) {
new File(folder, "bin/platform").mkdirs();
Files.copy(extensionsXML, new File(folder, "bin/platform/extensions.xml").toPath());
}
final File hybrisPlatformDirectory = new File(folder, "bin/platform");
final File platformExtensionsFile = new File(hybrisPlatformDirectory, "extensions.xml");
final FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(
XMLConfiguration.class).configure(new Parameters().xml().setFile(platformExtensionsFile));
final XMLConfiguration platformExtensionsConfiguration = builder.getConfiguration();
final List<String> extensionNames = Lists
.newArrayList(platformExtensionsConfiguration.getList(String.class, "extensions.extension[@name]"));
return new HashSet<>(extensionNames);
}
示例14: 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("pdf2xml.properties").setLocationStrategy(new ClasspathLocationStrategy()));
configuration = builder.getConfiguration();
} catch (ConfigurationException e) {
LOG.error(e, e);
}
}
示例15: getHeapSpankJarConfiguration
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; //导入方法依赖的package包/类
private Configuration getHeapSpankJarConfiguration() throws ConfigurationException {
Parameters params = new Parameters();
FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
.configure(params.properties()
.setFileName(PROPERTIES_FILE)
.setLocationStrategy(new ClasspathLocationStrategy())
);
Configuration config = builder.getConfiguration();
return config;
}