List of usage examples for org.apache.commons.configuration2.builder.fluent Parameters properties
public PropertiesBuilderParameters properties()
From source file:hd3gtv.as5kpc.MainClass.java
static FileBasedConfiguration loadConf(String file) throws ConfigurationException { org.apache.commons.configuration2.builder.fluent.Parameters params = new org.apache.commons.configuration2.builder.fluent.Parameters(); PropertiesBuilderParameters pbp = params.properties().setFileName(file); pbp.setListDelimiterHandler(new DefaultListDelimiterHandler(',')); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class); builder.configure(pbp);//from w w w. j a v a 2 s . co m return builder.getConfiguration(); }
From source file:com.pnf.jebauto.AutoUtil.java
/** * Create an Apache properties object out of a JEB2 configuration file. * /*from w w w . j a v a 2 s . c om*/ * @param path path to a JEB2 configuration file, such as jeb-client.cfg or jeb-engines.cfg * @return */ public static PropertiesConfiguration createPropertiesConfiguration(String path) { File configfile = new File(path); if (!configfile.isFile()) { try { configfile.createNewFile(); } catch (IOException e) { throw new RuntimeException(e); } } Parameters params = new Parameters(); FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class).configure(params.properties().setFileName(path)); builder.setAutoSave(true); try { return builder.getConfiguration(); } catch (ConfigurationException e) { throw new RuntimeException(e); } }
From source file:com.github.mavogel.ilias.utils.ConfigurationsUtils.java
/** * Creates the login configuration and uses defaults if necessary. * * @param propertyFilename the name of the property file * @return the {@link LoginConfiguration} *//*from ww w. j ava2 s.c o m*/ public static LoginConfiguration createLoginConfiguration(final String propertyFilename) { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class).configure(params.properties().setFileName(propertyFilename)); LoginConfiguration.LOGIN_MODE loginMode = null; String endpoint, client, username, password, loginModeRaw = ""; int maxFolderDepth; Level logLevel; try { Configuration config = builder.getConfiguration(); loginModeRaw = config.getString("login.mode"); loginMode = LoginConfiguration.LOGIN_MODE.valueOf(loginModeRaw); endpoint = config.getString("endpoint"); client = config.getString("login.client"); username = config.getString("login.username"); password = config.getString("login.password"); maxFolderDepth = config.getString("maxFolderDepth", String.valueOf(Defaults.MAX_FOLDER_DEPTH)).isEmpty() ? Defaults.MAX_FOLDER_DEPTH : Integer .valueOf(config.getString("maxFolderDepth", String.valueOf(Defaults.MAX_FOLDER_DEPTH))); logLevel = Level.toLevel(config.getString("log.level", Defaults.LOG_LEVEL.toString()), Defaults.LOG_LEVEL); if (password == null || password.isEmpty()) { Console console = System.console(); if (console != null) { password = String.valueOf(console.readPassword("Enter your password: ")); } else { throw new Exception("Console is not available!"); } } } catch (IllegalArgumentException iae) { throw new RuntimeException(String.format("Login mode '%s' is unknown. Use one of %s", loginModeRaw, Arrays.stream(LoginConfiguration.LOGIN_MODE.values()).map(lm -> lm.name()) .collect(Collectors.joining(", ")))); } catch (ConversionException ce) { throw new RuntimeException("maxFolderDepth property is not an integer"); } catch (Exception ex) { throw new RuntimeException(ex); } // == 1: set log level Logger.getRootLogger().setLevel(logLevel); // == 2: create login configuration switch (loginMode) { case STD: return LoginConfiguration.asStandardLogin(endpoint, client, username, password, maxFolderDepth); case LDAP: return LoginConfiguration.asLDAPLogin(endpoint, client, username, password, maxFolderDepth); case CAS: return LoginConfiguration.asCASLogin(); default: // should not happen return null; } }
From source file:com.rodaxsoft.mailgun.message.tools.MailgunSender.java
private static void initializeMailgun(CommandLine cmd) throws ContextedException, ConfigurationException { //Configure Mailgun account info FileBasedConfigurationBuilder<FileBasedConfiguration> builder; builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class); Parameters params = new Parameters(); builder.configure(params.properties().setFileName("config/mailgun.properties")); Configuration config = builder.getConfiguration(); DynaBean bean = new ConfigurationDynaBean(config); MailgunAccount acct = new MailgunAccount(bean); // Register the MailgunAccount object MailgunManager.register(acct);//w w w. j a v a2 s . co m LOG.info("Configured mailgun.properties"); //Set the default from email address setDefaultFromEmail(cmd); }
From source file:com.rodaxsoft.junit.mailgun.MailgunManagerTestCase.java
/** * @throws java.lang.Exception//from w w w.ja v a2 s .co m */ @BeforeClass public static void setUpBeforeClass() throws Exception { if (null == sMailingListAddress) { FileBasedConfigurationBuilder<FileBasedConfiguration> builder; builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class); Parameters params = new Parameters(); builder.configure(params.properties().setFileName(TESTCASE_PROPERTIES)); Configuration config = builder.getConfiguration(); DynaBean bean = new ConfigurationDynaBean(config); MailgunAccount acct = new MailgunAccount(bean); // Register the MailgunAccount object MailgunManager.register(acct); sMailingListAddress = config.getString("mailing.list"); sFrom = config.getString("email.from"); sTo = config.getString("email.to"); sCampaignId = config.getString("campaign.id"); LOG.info(acct); } }
From source file:com.rodaxsoft.mailgun.message.tools.MailgunSender.java
/** * Sets the default from email address or <code>sDefaultFromEmail</code> from the * properties file if no <code>-f</code> option exists. * @param cmd Command line arguments//from ww w . ja va 2 s . com */ private static void setDefaultFromEmail(CommandLine cmd) throws ContextedException { if (!cmd.hasOption(FROM_EMAIL_ADDRESS_OPT)) { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder; final Class<PropertiesConfiguration> propConfigClass = PropertiesConfiguration.class; builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(propConfigClass); builder.configure(params.properties().setFileName("config/mailgun-sender.properties")); try { FileBasedConfiguration config = builder.getConfiguration(); sDefaultFromEmail = config.getString(DEFAULT_FROM_EMAIL_PROP_KEY); if (null == sDefaultFromEmail) { throw new ContextedException("Missing " + DEFAULT_FROM_EMAIL_PROP_KEY + " key") .addContextValue(DEFAULT_FROM_EMAIL_PROP_KEY, sDefaultFromEmail).addContextValue("help", "Must set from email address with option -f or in the `mailgun-sender.properties` file"); } LOG.info("Configured mailgun-sender.properties"); } catch (ConfigurationException e) { throw new ContextedException("Error loading `mailgun-sender.properties`", e); } } }
From source file:me.dwtj.java.compiler.utils.CompilationTaskBuilder.java
/** * A helper method to create a configuration from the given Apache Commons Configuration * Properties file./*from w w w . j a va 2 s . c o m*/ * * @param configFile A valid Apache Commons Configuration Properties file. * * @return A {@link Configuration} corresponding to the given file. * * @see <a href=http://commons.apache.org/proper/commons-configuration/> * Apache Commons Configuration * </a> * @see <a href=http://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html> * Apache Commons Configuration: Properties Files * </a> */ public static PropertiesConfiguration compileProperties(File configFile) { Parameters paramUtils = new Parameters(); ListDelimiterHandler delim = new DefaultListDelimiterHandler(','); try { return new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) .configure(paramUtils.properties().setFile(configFile)).getConfiguration(); } catch (ConfigurationException ex) { throw new RuntimeException("Failed to create a configuration from file " + configFile); } }
From source file:eu.mangos.configuration.dao.impl.AuthConfigurationDAOImpl.java
@Override public AuthConfiguration readConfiguration() throws ConfigurationException { AuthConfiguration authConfig = new AuthConfiguration(); Parameters params = new Parameters(); this.builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties().setFile(new File(this.configuration.getSourcePath()))); Configuration config = this.builder.getConfiguration(); authConfig.setVersion(config.getString("ConfVersion")); if (authConfig.getVersion() == null) { logger.error("The selected file does not contain any ConfVersion property."); throw new ConfigurationException("The selected file does not contain any ConfVersion property."); }/*from ww w.j a v a 2 s . c o m*/ if (Long.parseLong(authConfig.getVersion()) != AuthConfiguration.CONF_VERSION) { logger.error("The selected file has a version number not compatible with this manager."); throw new ConfigurationException("The selected file is not compatible with this manager."); } String[] loginDBInfo = (config.getString("LoginDatabaseInfo", "").replace("\"", "")).split(";"); if (loginDBInfo.length != 5) { logger.warn("The selected file has a LoginDatabaseInfo property with not enough parameters."); } authConfig.setIp(loginDBInfo.length >= 1 ? loginDBInfo[0] : ""); authConfig.setPort(loginDBInfo.length >= 2 ? Integer.parseInt(loginDBInfo[1]) : 0); authConfig.setUser(loginDBInfo.length >= 3 ? loginDBInfo[2] : ""); authConfig.setPassword(loginDBInfo.length >= 4 ? loginDBInfo[3] : ""); authConfig.setSchema(loginDBInfo.length >= 5 ? loginDBInfo[4] : ""); authConfig.setLogsDirectory(config.getString("LogsDir", "").replace("\"", "")); authConfig.setPidFile(config.getString("PidFile", "").replace("\"", "")); authConfig.setMaxPing(config.getInt("MaxPingTime", 30)); authConfig.setRealmServerPort(config.getInt("RealmServerPort", 3724)); authConfig.setBindIP(config.getString("BindIP", "0.0.0.0").replace("\"", "")); authConfig.setLogConsoleLevel(LogLevel.convert(config.getInt("LogLevel"))); authConfig.setIncludeLogTime((config.getInt("LogTime", 0) != 0)); authConfig.setLogFile(config.getString("LogFile", "realm-list.log").replace("\"", "")); authConfig.setIncludeTimestamp((config.getInt("LogTimestamp", 0) != 0)); authConfig.setLogFileLevel(LogLevel.convert(config.getInt("LogFileLevel"))); String[] logColors = (config.getString("LogColors", "")).replace("\"", "").split(" "); if (logColors.length != 4) { logger.warn("The selected file has a LogColors property with not enough parameters."); } authConfig.setLogNormalColor( logColors.length >= 1 ? LogColor.convert(Integer.parseInt(logColors[0])) : LogColor.NONE); authConfig.setLogDetailsColor( logColors.length >= 2 ? LogColor.convert(Integer.parseInt(logColors[1])) : LogColor.NONE); authConfig.setLogDebugColor( logColors.length >= 3 ? LogColor.convert(Integer.parseInt(logColors[2])) : LogColor.NONE); authConfig.setLogErrorColor( logColors.length >= 4 ? LogColor.convert(Integer.parseInt(logColors[3])) : LogColor.NONE); authConfig.setUseProcessors(config.getInt("UseProcessors", 0)); authConfig.setProcessPriority(ProcessPriority.convert(config.getInt("ProcessPriority", 1))); authConfig.setWaitAtStartupError(config.getInt("WaitAtStartupError", 0) != 0); authConfig.setRealmStateUpdateDelay(config.getInt("RealmsStateUpdateDelay", 20)); authConfig.setNbWrongPass(config.getInt("WrongPass.MaxCount", 3)); authConfig.setBanTime(config.getInt("WrongPass.BanTime", 300)); authConfig.setBanType(BanType.convert(config.getInt("WrongPass.BanType", 0))); logger.info("Configuration file " + this.configuration.getName() + " has been loaded succesfully !"); return authConfig; }
From source file:com.haulmont.mp2xls.writer.LocalizationBatchFileWriter.java
/** * Writing all changed properties to the passed file. Using apache commons-configuration to write properties, * because it preserves the original file format unlike the java.util.Properties class. * * @param messagesFile - messages file// w w w .j a v a2 s . c o m * @param diffs - differences */ protected void mergeLocalizationProperties(File messagesFile, Collection<LocalizationLog> diffs) { if (diffs == null || diffs.isEmpty()) return; try { Parameters parameters = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>( PropertiesConfiguration.class) .configure(parameters.properties().setFile(messagesFile).setEncoding("UTF-8") .setIOFactory(new MessagePropertiesIOFactory()) .setLayout(new PropertiesConfigurationLayout())); Configuration configuration = builder.getConfiguration(); for (LocalizationLog diff : diffs) { if (LocalizationLog.Type.CHANGED.equals(diff.getType())) { configuration.setProperty(diff.getParameterName(), diff.getExcelValue()); } } builder.save(); } catch (Exception e) { throw new RuntimeException("Exception during properties file merging", e); } }
From source file:org.sdw.util.ConfigReader.java
/** * Single parameter constructor/*from w w w.jav a 2s .c om*/ * @param propertyFile : Absolute/ Relative path of property file to be read */ public ConfigReader(String propertyFile) { Parameters params = new Parameters(); builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class); builder.configure(params.properties().setFileName(propertyFile) .setListDelimiterHandler(new DefaultListDelimiterHandler(','))); }