List of usage examples for org.apache.commons.configuration PropertiesConfiguration setProperty
public void setProperty(String key, Object value)
From source file:com.uber.stream.kafka.mirrormaker.manager.rest.TestManagerTopicManagement.java
void updateHelixConfigFile(String zk, String instanceId, int id) { // load helix config from file String helixFileName = "src/test/resources/helix.properties"; PropertiesConfiguration helixConfigFromFile = new PropertiesConfiguration(); helixConfigFromFile.setDelimiterParsingDisabled(true); try {/*from ww w . ja v a 2s.com*/ helixConfigFromFile.load(helixFileName); } catch (Exception e) { throw new RuntimeException("Failed to load config from file " + helixFileName + ": " + e.getMessage()); } OutputStream output = null; try { output = new FileOutputStream("/tmp/helix.properties-" + id); // set the properties value helixConfigFromFile.setProperty("federated.deployment.name", DEPLOYMENT_NAME); helixConfigFromFile.setProperty("zkServer", zk); helixConfigFromFile.setProperty("instanceId", instanceId); // save properties to project tmp folder helixConfigFromFile.save(output); } catch (Exception io) { io.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:maltcms.ui.fileHandles.properties.tools.SceneExporter.java
/** * Layout: NAME/ NAME.properties NAME-general.properties (optional) * fragmentCommands/ 00_CLASSNAME/ CLASSNAME.properties 01_CLASSNAME/ * CLASSNAME.properties/* w ww . j av a 2 s.c o m*/ * * @param pipeline * @param general */ private void createConfigFiles(List<PipelineElementWidget> pipeline, PipelineGeneralConfigWidget general) { try { //create base config FileObject baseConfigFo = this.file.getFileObject(this.name + ".mpl"); File f = FileUtil.toFile(baseConfigFo); PropertiesConfiguration baseConfig = new PropertiesConfiguration(); File subDir = new File(f.getParent(), "xml"); FileUtil.createFolder(subDir); //retrieve general configuration Configuration generalConfig = general.getProperties(); //only create and link, if non-empty if (!generalConfig.isEmpty()) { ConfigurationUtils.copy(generalConfig, baseConfig); } //String list for pipeline elements List<String> pipelineElements = new LinkedList<>(); File pipelineXml = new File(subDir, this.name + ".xml"); for (PipelineElementWidget pw : pipeline) { //add full class name to pipeline elements pipelineElements.add(pw.getClassName()); //write configuration to that file PropertiesConfiguration pc = new PropertiesConfiguration(); } //set pipeline property baseConfig.setProperty("pipeline", pipelineElements); //set pipeline.properties property String pipelineXmlString = "file:${config.basedir}/xml/bipace.xml"; baseConfig.setProperty("pipeline.xml", pipelineXmlString); FileObject fo = FileUtil.toFileObject(f); try { baseConfig.save(new PrintStream(fo.getOutputStream())); } catch (ConfigurationException ex) { Exceptions.printStackTrace(ex); } } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
From source file:com.uber.stream.kafka.mirrormaker.manager.rest.TestManagerTopicManagement.java
void updateConsumerConfigFile(String zk, String instanceId, int id) { // load consumer config from file String consumerFileName = "src/test/resources/consumer.properties"; PropertiesConfiguration consumerConfigFromFile = new PropertiesConfiguration(); consumerConfigFromFile.setDelimiterParsingDisabled(true); try {/*from www . j a v a 2 s . c o m*/ consumerConfigFromFile.load(consumerFileName); } catch (Exception e) { throw new RuntimeException( "Failed to load config from file " + consumerFileName + ": " + e.getMessage()); } OutputStream output = null; try { output = new FileOutputStream("/tmp/consumer.properties-" + id); // set the properties value consumerConfigFromFile.setProperty("zookeeper.connect", zk); consumerConfigFromFile.setProperty("client.id", instanceId); // save properties to project tmp folder consumerConfigFromFile.save(output); } catch (Exception io) { io.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:com.uber.stream.kafka.mirrormaker.manager.rest.TestManagerTopicManagement.java
void updateProducerConfigFile(String instanceId, int id) { // load producer config from file String producerFileName = "src/test/resources/producer.properties"; PropertiesConfiguration producerConfigFromFile = new PropertiesConfiguration(); producerConfigFromFile.setDelimiterParsingDisabled(true); try {/*from w ww. j av a 2s. c o m*/ producerConfigFromFile.load(producerFileName); } catch (Exception e) { throw new RuntimeException( "Failed to load config from file " + producerFileName + ": " + e.getMessage()); } OutputStream output = null; try { output = new FileOutputStream("/tmp/producer.properties-" + id); // set the properties value producerConfigFromFile.setProperty("bootstrap.servers", KafkaStarterUtils.DEFAULT_KAFKA_BROKER); producerConfigFromFile.setProperty("client.id", instanceId); // save properties to project tmp folder producerConfigFromFile.save(output); } catch (Exception io) { io.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:com.liferay.portal.deploy.hot.ExtHotDeployListener.java
protected void mergePortalProperties(String portalWebDir, ServletContext servletContext) throws Exception { URL pluginPropsURL = servletContext .getResource("WEB-INF/ext-web/docroot/WEB-INF/classes/portal-ext.properties"); if (pluginPropsURL == null) { if (_log.isDebugEnabled()) { _log.debug("Ext Plugin's portal-ext.properties not found"); }//from www . j a va 2s .c o m return; } if (_log.isDebugEnabled()) { _log.debug("Loading portal-ext.properties from " + pluginPropsURL); } PropertiesConfiguration pluginProps = new PropertiesConfiguration(pluginPropsURL); PropertiesConfiguration portalProps = new PropertiesConfiguration( this.getClass().getClassLoader().getResource("portal.properties")); File extPluginPropsFile = new File(portalWebDir + "WEB-INF/classes/portal-ext-plugin.properties"); PropertiesConfiguration extPluginPortalProps = new PropertiesConfiguration(); if (extPluginPropsFile.exists()) { extPluginPortalProps.load(extPluginPropsFile); } for (Iterator it = pluginProps.getKeys(); it.hasNext();) { String key = (String) it.next(); List value = pluginProps.getList(key); if (key.endsWith("+")) { key = key.substring(0, key.length() - 1); List newValue = new ArrayList(); if (extPluginPortalProps.containsKey(key)) { // already rewrited newValue.addAll(extPluginPortalProps.getList(key)); } else { newValue.addAll(portalProps.getList(key)); } newValue.addAll(value); extPluginPortalProps.setProperty(key, newValue); } else { extPluginPortalProps.setProperty(key, value); } } extPluginPortalProps.save(extPluginPropsFile); }
From source file:com.ibm.replication.iidr.metadata.Settings.java
/** * Retrieve the settings from the given properties file. * //from www . j a v a 2s .com * @param propertiesFile * @throws ConfigurationException */ public Settings(String propertiesFile) throws ConfigurationException { PropertiesConfiguration config = new PropertiesConfiguration(propertiesFile); asHostName = config.getString("asHostName"); asUserName = config.getString("asUserName"); String encryptedAsPassword = config.getString("asPassword"); asPort = config.getInt("asPort", 10101); isHostName = config.getString("isHostName"); isUserName = config.getString("isUserName"); String encryptedISPassword = config.getString("isPassword"); isPort = config.getInt("isPort", 10101); bundleFilePath = config.getString("bundleFilePath"); defaultDataPath = config.getString("defaultDataPath"); trustSelfSignedCertificates = config.getBoolean("trustSelfSignedCertificates"); // Check if the password has already been encrypted // If not, encrypt and save the properties try { asPassword = Encryptor.decodeAndDecrypt(encryptedAsPassword); } catch (EncryptedDataException e) { logger.debug("Encrypting asPassword"); asPassword = encryptedAsPassword; encryptedAsPassword = Encryptor.encryptAndEncode(encryptedAsPassword); config.setProperty("asPassword", encryptedAsPassword); config.save(); } try { isPassword = Encryptor.decodeAndDecrypt(encryptedISPassword); } catch (EncryptedDataException e) { logger.debug("Encrypting isPassword"); isPassword = encryptedISPassword; encryptedISPassword = Encryptor.encryptAndEncode(encryptedISPassword); config.setProperty("isPassword", encryptedISPassword); config.save(); } // Now log the settings logSettings(config); }
From source file:com.vmware.aurora.global.Configuration.java
/** * /*from w w w . j av a 2 s. c o m*/ * @return a memory view of all properties inside serengeti.properties and vc.properties */ private static PropertiesConfiguration init() { PropertiesConfiguration config = null; String homeDir = System.getProperties().getProperty("serengeti.home.dir"); String ngcConfigFile = NGC_PROP_FILE; if (homeDir != null && homeDir.length() > 0) { StringBuilder builder = new StringBuilder(); builder.append(homeDir).append(File.separator).append("conf").append(File.separator); configFileName = builder.toString() + "serengeti.properties"; ngcConfigFile = builder.toString() + NGC_PROP_FILE; } else { configFileName = "serengeti.properties"; } try { URL url = ConfigurationUtils.locate(null, configFileName); logger.info("Reading properties file serengeti.properties from " + url.getPath()); serengetiCfg = new PropertiesConfiguration(); serengetiCfg.setEncoding("UTF-8"); serengetiCfg.setFileName(configFileName); serengetiCfg.load(); config = (PropertiesConfiguration) serengetiCfg.clone(); } catch (ConfigurationException ex) { String message = "Failed to load serengeti.properties file."; logger.fatal(message, ex); throw AuroraException.APP_INIT_ERROR(ex, message); } String propertyFilePrefix = System.getProperty("PROPERTY_FILE_PREFIX", "vc"); String propertyFileName = propertyFilePrefix + ".properties"; try { logger.info("Reading properties file " + propertyFileName); vcCfg = new PropertiesConfiguration(propertyFileName); Iterator<?> keys = vcCfg.getKeys(); while (keys.hasNext()) { String key = (String) keys.next(); config.setProperty(key, vcCfg.getProperty(key)); } } catch (ConfigurationException ex) { // error out if the configuration file is not there String message = "Failed to load vc.properties file."; logger.fatal(message, ex); throw AuroraException.APP_INIT_ERROR(ex, message); } // load ngc_registrar.properties try { logger.info("Reading properties file " + ngcConfigFile); ngcCfg = new PropertiesConfiguration(ngcConfigFile); ngcCfg.setEncoding("UTF-8"); Iterator<?> keys = ngcCfg.getKeys(); while (keys.hasNext()) { String key = (String) keys.next(); config.setProperty(key, ngcCfg.getProperty(key)); } } catch (ConfigurationException ex) { // error out if the configuration file is not there String message = "Failed to load file " + NGC_PROP_FILE; logger.fatal(message, ex); throw AuroraException.APP_INIT_ERROR(ex, message); } logConfig(config); return config; }
From source file:eu.tango.energymodeller.datasourceclient.ZabbixDirectDbDataSourceAdaptor.java
/** * This creates a new database connector for use. It establishes a database * connection immediately ready for use. */// w ww . j a va 2s . c o m public ZabbixDirectDbDataSourceAdaptor() { HISTORY_TABLES.add("history"); HISTORY_TABLES.add("history_str"); HISTORY_TABLES.add("history_uint"); HISTORY_TABLES.add("history_text"); try { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. databaseURL = config.getString("energy.modeller.zabbix.db.url", "jdbc:mysql://<ADD_ZABBIX_DB_SERVER_ADDRESS_HERE>:3306/zabbix"); config.setProperty("energy.modeller.zabbix.db.url", databaseURL); databaseDriver = config.getString("energy.modeller.zabbix.db.driver", databaseDriver); try { Class.forName(databaseDriver); } catch (ClassNotFoundException ex) { //If the driver is not found on the class path revert to MariaDB. databaseDriver = "com.mysql.jdbc.Driver"; } config.setProperty("energy.modeller.zabbix.db.driver", databaseDriver); databasePassword = config.getString("energy.modeller.zabbix.db.password", ""); config.setProperty("energy.modeller.zabbix.db.password", databasePassword); databaseUser = config.getString("energy.modeller.zabbix.db.user", databaseUser); config.setProperty("energy.modeller.zabbix.db.user", databaseUser); vmGroup = config.getString("energy.modeller.vm.group", vmGroup); config.setProperty("energy.modeller.vm.group", vmGroup); hostGroup = config.getString("energy.modeller.host.group", hostGroup); config.setProperty("energy.modeller.host.group", hostGroup); generalPowerConsumer = config.getString("energy.modeller.dfs.group", generalPowerConsumer); config.setProperty("energy.modeller.dfs.group", generalPowerConsumer); onlyAvailableHosts = config.getBoolean("energy.zabbix.only.available.hosts", onlyAvailableHosts); config.setProperty("energy.zabbix.only.available.hosts", onlyAvailableHosts); if (onlyAvailableHosts) { allZabbixHosts = allZabbixHosts + " AND h.available = 1"; } } catch (ConfigurationException ex) { DB_LOGGER.log(Level.SEVERE, "Error loading the configuration of the IaaS energy modeller", ex); } try { connection = getConnection(); } catch (IOException | SQLException | ClassNotFoundException ex) { DB_LOGGER.log(Level.SEVERE, "Failed to establish the connection to the Zabbix DB", ex); } }
From source file:eu.tango.energymodeller.datastore.DataGatherer.java
/** * This creates a data gather component for the energy modeller. * * @param datasource The data source that provides information about the * host resources and the virtual machines running on them. * @param connector The database connector used to do this. It is best to * give this component its own database connection as it will make heavy use * of it.//from w w w .j a v a 2 s. com */ public DataGatherer(HostDataSource datasource, DatabaseConnector connector) { this.datasource = datasource; this.database = connector; populateHostList(); try { PropertiesConfiguration config; if (new File(CONFIG_FILE).exists()) { config = new PropertiesConfiguration(CONFIG_FILE); } else { config = new PropertiesConfiguration(); config.setFile(new File(CONFIG_FILE)); } config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting. logVmsToDisk = config.getBoolean("energy.modeller.data.gatherer.log.vms", logVmsToDisk); config.setProperty("energy.modeller.data.gatherer.log.vms", logVmsToDisk); logAppsToDisk = config.getBoolean("energy.modeller.data.gatherer.log.apps", logAppsToDisk); config.setProperty("energy.modeller.data.gatherer.log.apps", logAppsToDisk); loggerOutputFile = config.getString("energy.modeller.data.gatherer.log.vms.filename", loggerOutputFile); config.setProperty("energy.modeller.data.gatherer.log.vms.filename", loggerOutputFile); loggerOutputFile = config.getString("energy.modeller.data.gatherer.log.apps.filename", appLoggerOutputFile); config.setProperty("energy.modeller.data.gatherer.log.apps.filename", appLoggerOutputFile); loggerConsiderIdleEnergy = config.getBoolean("energy.modeller.data.gatherer.log.consider_idle_energy", loggerConsiderIdleEnergy); config.setProperty("energy.modeller.data.gatherer.log.consider_idle_energy", loggerConsiderIdleEnergy); useWorkloadCache = config.getBoolean("energy.modeller.data.gatherer.log.use_workload_cache", useWorkloadCache); config.setProperty("energy.modeller.data.gatherer.log.use_workload_cache", useWorkloadCache); if (useWorkloadCache) { workloadCache = WorkloadStatisticsCache.getInstance(); workloadCache.setInUse(true); } } catch (ConfigurationException ex) { Logger.getLogger(DataGatherer.class.getName()).log(Level.INFO, "Error loading the configuration of the IaaS energy modeller", ex); } }
From source file:com.mirth.connect.client.ui.SettingsPanelMap.java
public void doExportMap() { if (isSaveEnabled()) { int option = JOptionPane.showConfirmDialog(this, "Would you like to save the settings first?"); if (option == JOptionPane.YES_OPTION) { if (!doSave()) { return; }/*from w w w . ja v a2s . c o m*/ } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) { return; } } final String workingId = getFrame().startWorking("Exporting " + getTabName() + " settings..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { private Map<String, ConfigurationProperty> configurationMap; public Void doInBackground() { try { File file = getFrame().createFileForExport(null, "PROPERTIES"); if (file != null) { PropertiesConfiguration properties = new PropertiesConfiguration(); properties.setDelimiterParsingDisabled(true); properties.setListDelimiter((char) 0); properties.clear(); PropertiesConfigurationLayout layout = properties.getLayout(); configurationMap = getFrame().mirthClient.getConfigurationMap(); Map<String, ConfigurationProperty> sortedMap = new TreeMap<String, ConfigurationProperty>( String.CASE_INSENSITIVE_ORDER); sortedMap.putAll(configurationMap); for (Entry<String, ConfigurationProperty> entry : sortedMap.entrySet()) { String key = entry.getKey(); String value = entry.getValue().getValue(); String comment = entry.getValue().getComment(); if (StringUtils.isNotBlank(key)) { properties.setProperty(key, value); layout.setComment(key, StringUtils.isBlank(comment) ? null : comment); } } properties.save(file); } } catch (Exception e) { getFrame().alertThrowable(getFrame(), e); } return null; } @Override public void done() { getFrame().stopWorking(workingId); } }; worker.execute(); }