List of usage examples for org.apache.commons.configuration PropertiesConfiguration save
public void save() throws ConfigurationException
From source file:org.apache.ranger.ldapconfigcheck.LdapConfig.java
public void updateInputPropFile(String ldapUrl, String bindDn, String bindPassword, String userSearchBase, String userSearchFilter, String authUser, String authPass) { try {/*w ww .j a va2s . co m*/ PropertiesConfiguration config = new PropertiesConfiguration(CONFIG_FILE); // Update properties in memory and update the file as well prop.setProperty(LGSYNC_LDAP_URL, ldapUrl); prop.setProperty(LGSYNC_LDAP_BIND_DN, bindDn); prop.setProperty(LGSYNC_LDAP_BIND_PASSWORD, bindPassword); prop.setProperty(LGSYNC_USER_SEARCH_BASE, userSearchBase); prop.setProperty(LGSYNC_USER_SEARCH_FILTER, userSearchFilter); prop.setProperty(AUTH_USERNAME, authUser); prop.setProperty(AUTH_PASSWORD, authPass); config.setProperty(LGSYNC_LDAP_URL, ldapUrl); config.setProperty(LGSYNC_LDAP_BIND_DN, bindDn); //config.setProperty(LGSYNC_LDAP_BIND_PASSWORD, bindPassword); config.setProperty(LGSYNC_USER_SEARCH_BASE, userSearchBase); config.setProperty(LGSYNC_USER_SEARCH_FILTER, userSearchFilter); config.setProperty(AUTH_USERNAME, authUser); config.setProperty(AUTH_PASSWORD, authPass); config.save(); } catch (ConfigurationException e) { System.out.println("Failed to update " + CONFIG_FILE + ": " + e); } }
From source file:org.apache.wookie.server.ContextListener.java
public void contextInitialized(ServletContextEvent event) { try {/* w w w. j av a 2 s .c o m*/ ServletContext context = event.getServletContext(); /* * load the widgetserver.properties file and put it into this context * as an attribute 'properties' available to all resources */ PropertiesConfiguration configuration; File localPropsFile = new File( System.getProperty("user.dir") + File.separator + "local.widgetserver.properties"); if (localPropsFile.exists()) { configuration = new PropertiesConfiguration(localPropsFile); _logger.info("Using local widget server properties file: " + localPropsFile.toString()); } else { configuration = new PropertiesConfiguration("widgetserver.properties"); configuration.setFile(localPropsFile); configuration.save(); _logger.info("Using default widget server properties, configure your local server using: " + localPropsFile.toString()); } context.setAttribute("properties", (Configuration) configuration); /* * Merge in system properties overrides */ Iterator<Object> systemKeysIter = System.getProperties().keySet().iterator(); while (systemKeysIter.hasNext()) { String key = systemKeysIter.next().toString(); if (configuration.containsKey(key) || key.startsWith("widget.")) { String setting = configuration.getString(key); String override = System.getProperty(key); if ((override != null) && (override.length() > 0) && !override.equals(setting)) { configuration.setProperty(key, override); if (setting != null) { _logger.info("Overridden server configuration property: " + key + "=" + override); } } } } /* * Initialize persistence manager factory now, not on first request */ PersistenceManagerFactory.initialize(configuration); /* * Initialise the locale handler */ LocaleHandler.getInstance().initialize(configuration); final Locale locale = new Locale(configuration.getString("widget.default.locale")); final Messages localizedMessages = LocaleHandler.getInstance().getResourceBundle(locale); /* * load the opensocial.properties file and put it into this context * as an attribute 'opensocial' available to all resources */ PropertiesConfiguration opensocialConfiguration; File localOpenSocialPropsFile = new File( System.getProperty("user.dir") + File.separator + "local.opensocial.properties"); if (localOpenSocialPropsFile.exists()) { opensocialConfiguration = new PropertiesConfiguration(localOpenSocialPropsFile); _logger.info("Using local open social properties file: " + localOpenSocialPropsFile.toString()); } else { opensocialConfiguration = new PropertiesConfiguration("opensocial.properties"); opensocialConfiguration.setFile(localOpenSocialPropsFile); opensocialConfiguration.save(); _logger.info("Using default open social properties, configure your local server using: " + localOpenSocialPropsFile.toString()); } context.setAttribute("opensocial", (Configuration) opensocialConfiguration); /* * Load installed features */ PropertiesConfiguration featuresConfiguration; File localFeaturesPropsFile = new File( System.getProperty("user.dir") + File.separator + "local.features.properties"); if (localFeaturesPropsFile.exists()) { featuresConfiguration = new PropertiesConfiguration(localFeaturesPropsFile); _logger.info("Loading local features file: " + localOpenSocialPropsFile.toString()); } else { featuresConfiguration = new PropertiesConfiguration("features.properties"); featuresConfiguration.setFile(localFeaturesPropsFile); featuresConfiguration.save(); _logger.info("Loading default features, configure your local server using: " + localFeaturesPropsFile.toString()); } FeatureLoader.loadFeatures(featuresConfiguration); /* * Run diagnostics */ Diagnostics.run(context, configuration); /* * Start hot-deploy widget watcher */ if (configuration.getBoolean("widget.hot_deploy")) { startWatcher(context, configuration, localizedMessages); } else { _logger.info(localizedMessages.getString("WidgetHotDeploy.0")); } } catch (ConfigurationException ex) { _logger.error("ConfigurationException thrown: " + ex.toString()); } }
From source file:org.codetrack.database.DatabaseConfiguration.java
/** * Save database configuration// w w w. ja v a 2 s .co m * * @param databaseParameters */ public void saveRegisteredDatabase(DatabaseParameters databaseParameters) { try { String databasePropertiesName = getCodetrackConfigPath() + FILE_SEPARATOR + "database-" + databaseParameters.getName() + ".properties"; File file = new File(databasePropertiesName); if (!file.exists()) file.createNewFile(); PropertiesConfiguration dbpc = new PropertiesConfiguration(file); dbpc.setProperty("name", databaseParameters.getName()); dbpc.setProperty("engine", databaseParameters.getEngine().name()); dbpc.setProperty("user", databaseParameters.getUser()); dbpc.setProperty("password", databaseParameters.getPassword()); dbpc.setProperty("url", databaseParameters.getUrl()); dbpc.setProperty("path", databaseParameters.getPath()); dbpc.save(); } catch (Exception e) { throw new DatabaseError("Error on load database properties file", e, DatabaseError.DATABASE_OPEN_CONFIG_ERROR); } }
From source file:org.dspace.statistics.content.StatisticsDataWorkflow.java
protected Date getOldestWorkflowItemDate() throws SolrServerException { ConfigurationService configurationService = new DSpace().getConfigurationService(); String workflowStartDate = configurationService.getProperty("usage-statistics.workflow-start-date"); if (workflowStartDate == null) { //Query our solr for it ! QueryResponse oldestRecord = SolrLogger.query(getQuery(), null, null, 1, 0, null, null, null, null, "time", true); if (0 < oldestRecord.getResults().getNumFound()) { SolrDocument solrDocument = oldestRecord.getResults().get(0); Date oldestDate = (Date) solrDocument.getFieldValue("time"); //Store the date, we only need to retrieve this once ! try { //Also store it in the solr-statics configuration file, the reason for this being that the sort query //can be very time consuming & we do not want this delay each time we want to see workflow statistics String solrConfigDir = configurationService.getProperty("dspace.dir") + File.separator + "config" + File.separator + "modules" + File.separator + "usage-statistics.cfg"; PropertiesConfiguration config = new PropertiesConfiguration(solrConfigDir); config.setProperty("workflow-start-date", new DCDate(oldestDate)); config.save(); } catch (ConfigurationException e) { log.error("Error while storing workflow start date", e); }/*from w ww . j a v a 2s .c om*/ //ALso store it in our local config ! configurationService.setProperty("usage-statistics.workflow-start-date", new DCDate(oldestDate).toString()); //Write to file return oldestDate; } else { return null; } } else { return new DCDate(workflowStartDate).toDate(); } }
From source file:org.jboss.qa.jcontainer.fuse.test.FuseContainerPortTest.java
@AfterClass public static void afterClass() throws Exception { if (container != null) { container.stop();/*from ww w.j a va2 s. com*/ final File propsFile = new File(container.getConfiguration().getDirectory(), "etc" + File.separator + "org.apache.karaf.shell.cfg"); final PropertiesConfiguration propConf = new PropertiesConfiguration(propsFile); propConf.setProperty("sshPort", FuseConfiguration.DEFAULT_SSH_PORT); propConf.save(); } }
From source file:org.jboss.qa.jcontainer.karaf.KarafContainer.java
protected void setEtcProperty(String key, Object value, String config) throws Exception { final File propsFile = getConfigFile(config); final PropertiesConfiguration propConf = new PropertiesConfiguration(propsFile); propConf.setProperty(key, value);//w ww .ja va 2 s . c om propConf.save(); }
From source file:org.jboss.qa.jcontainer.karaf.KarafContainerPortTest.java
@AfterClass public static void afterClass() throws Exception { if (container != null) { container.stop();//from w w w . j a v a 2 s .co m final File propsFile = container.getConfigFile("org.apache.karaf.shell"); final PropertiesConfiguration propConf = new PropertiesConfiguration(propsFile); propConf.setProperty("sshPort", KarafConfiguration.DEFAULT_SSH_PORT); propConf.save(); } }
From source file:org.jboss.qa.jcontainer.wildfly.WildflyContainer.java
@Override public void addUser(V user) throws Exception { if (user.getRealm() == null) { user.setRealm(WildflyUser.Realm.MANAGEMENT_REALM); }/* w w w.j a va 2 s . c o m*/ checkMandatoryProperty("username", user.getUsername()); checkMandatoryProperty("password", user.getUsername()); File usersFile; File rolesFile; if (user.getRealm().equals(WildflyUser.Realm.APPLICATION_REALM)) { usersFile = new File(configuration.getConfigurationFolder(), "application-users.properties"); rolesFile = new File(configuration.getConfigurationFolder(), "application-roles.properties"); } else { usersFile = new File(configuration.getConfigurationFolder(), "mgmt-users.properties"); rolesFile = new File(configuration.getConfigurationFolder(), "mgmt-groups.properties"); } final PropertiesConfiguration propConfUsers = new PropertiesConfiguration(usersFile); propConfUsers.setProperty(user.getUsername(), DigestUtils.md5Hex( String.format("%s:%s:%s", user.getUsername(), user.getRealm().getValue(), user.getPassword()))); propConfUsers.save(); final PropertiesConfiguration propConfRoles = new PropertiesConfiguration(rolesFile); propConfRoles.setProperty(user.getUsername(), StringUtils.join(user.getRoles(), ",")); propConfRoles.save(); }
From source file:org.jenkinsci.test.acceptance.utils.pluginreporter.TextFileExercisedPluginReporter.java
@Override public void log(String testName, String pluginName, String pluginVersion) { PropertiesConfiguration config = null; try {/* w w w. j av a 2 s . com*/ config = new PropertiesConfiguration(file); } catch (ConfigurationException e) { LOGGER.error(e.getMessage()); return; } config.setProperty(testName + "$" + pluginName, pluginVersion); try { config.save(); } catch (ConfigurationException e) { LOGGER.error(e.getMessage()); return; } }
From source file:org.jspare.core.config.CommonsConfigImpl.java
@Override public void store() { try {/*from w w w. j a v a 2 s . co m*/ PropertiesConfiguration targetConfiguration = new PropertiesConfiguration(this.fileToLoad); configuration.getKeys() .forEachRemaining(k -> targetConfiguration.setProperty(k, configuration.getProperties(k))); targetConfiguration.save(); } catch (ConfigurationException e) { log.error("Error when trying to save a configuration [{}] - Message [{}]", this.fileToLoad, e.getMessage()); } }