List of usage examples for org.apache.commons.configuration PropertiesConfiguration save
public void save(Writer writer) throws ConfigurationException
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 ww w. jav a2 s . co 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 w w. j ava 2 s .c om*/ 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.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 {/* w w w . ja v a 2 s . co m*/ 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 w w.j a va2 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.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 ww . j a v a2 s .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(); }
From source file:com.liferay.ide.sdk.core.SDK.java
protected void persistAppServerProperties(Map<String, String> properties) throws FileNotFoundException, IOException, ConfigurationException { IPath loc = getLocation();/*from ww w . ja v a 2s.c o m*/ // check for build.<username>.properties String userName = System.getProperty("user.name"); //$NON-NLS-1$ File userBuildFile = loc.append("build." + userName + ".properties").toFile(); //$NON-NLS-1$ //$NON-NLS-2$ if (userBuildFile.exists()) { /* * the build file exists so we need to check the following conditions 1. if the header in the comment * contains the text written by a previous SDK operation then we can write it again 2. if the file was not * previously written by us we will need to prompt the user with permission yes/no to update the * build.<username>.properties file */ PropertiesConfiguration propsConfig = new PropertiesConfiguration(userBuildFile); String header = propsConfig.getHeader(); boolean shouldUpdateBuildFile = false; if (header != null && header.contains(MSG_MANAGED_BY_LIFERAY_IDE)) { shouldUpdateBuildFile = true; } else { String overwrite = getPrefStore().get(SDKCorePlugin.PREF_KEY_OVERWRITE_USER_BUILD_FILE, ALWAYS); if (ALWAYS.equals(overwrite)) { shouldUpdateBuildFile = true; } else { shouldUpdateBuildFile = false; } } if (shouldUpdateBuildFile) { for (String key : properties.keySet()) { propsConfig.setProperty(key, properties.get(key)); } propsConfig.setHeader(MSG_MANAGED_BY_LIFERAY_IDE); propsConfig.save(userBuildFile); } } else { Properties props = new Properties(); props.putAll(properties); props.store(new FileOutputStream(userBuildFile), MSG_MANAGED_BY_LIFERAY_IDE); } }
From source file:com.mirth.connect.server.controllers.DefaultConfigurationController.java
private void saveConfigurationProperties(Map<String, ConfigurationProperty> map) throws ControllerException { try {/*from w ww . jav a2 s. co m*/ PropertiesConfiguration configurationMapProperties = new PropertiesConfiguration(); configurationMapProperties.setDelimiterParsingDisabled(true); configurationMapProperties.setListDelimiter((char) 0); configurationMapProperties.clear(); PropertiesConfigurationLayout layout = configurationMapProperties.getLayout(); Map<String, ConfigurationProperty> sortedMap = new TreeMap<String, ConfigurationProperty>( String.CASE_INSENSITIVE_ORDER); sortedMap.putAll(map); 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)) { configurationMapProperties.addProperty(key, value); layout.setComment(key, StringUtils.isBlank(comment) ? null : comment); } } configurationMapProperties.save(new File(configurationFile)); } catch (Exception e) { throw new ControllerException(e); } }
From source file:evaluation.simulator.conf.service.SimulationConfigService.java
public void writeConfig(File outputFile) { PropertiesConfiguration props; try {//from www . jav a2 s.c o m props = new PropertiesConfiguration("inputOutput/simulator/config/experiment_template.cfg"); props.setProperty("EDF_VERSION", 1); // static part Map<String, String> plugins = this.simPropRegistry.getActivePlugins(true); logger.log(Level.DEBUG, "Active plugins are:"); for (String key : plugins.keySet()) { logger.log(Level.DEBUG, key + " with " + plugins.get(key)); props.setProperty(key, plugins.get(key)); } // Properties to vary for (Entry<String, String> s : this.simPropRegistry.getPropertiesToVary().entrySet()) { logger.log(Level.DEBUG, s.getKey() + "=" + s.getValue().toString()); props.setProperty(s.getKey(), s.getValue()); } // dynamic part for (Entry<String, SimProp> s : this.simPropRegistry.getAllSimProps()) { try { if (s.getValue().getValueType() == Integer.class && ((IntProp) (s.getValue())).getAuto()) { logger.log(Level.DEBUG, s.getKey() + "=AUTO"); props.setProperty(s.getKey(), "AUTO"); } else if (s.getValue().getValueType() == Integer.class && ((IntProp) (s.getValue())).getUnlimited()) { logger.log(Level.DEBUG, s.getKey() + "=UNLIMITED"); props.setProperty(s.getKey(), "UNLIMITED"); } else if (s.getValue().getValueType() == Float.class && ((FloatProp) (s.getValue())).getAuto()) { logger.log(Level.DEBUG, s.getKey() + "=AUTO"); props.setProperty(s.getKey(), "AUTO"); } else if (s.getValue().getValueType() == Float.class && ((FloatProp) (s.getValue())).getUnlimited()) { logger.log(Level.DEBUG, s.getKey() + "=UNLIMITED"); props.setProperty(s.getKey(), "UNLIMITED"); } else if (s.getValue().getValueType() == Double.class && ((DoubleProp) (s.getValue())).getAuto()) { logger.log(Level.DEBUG, s.getKey() + "=AUTO"); props.setProperty(s.getKey(), "AUTO"); } else if (s.getValue().getValueType() == Double.class && ((DoubleProp) (s.getValue())).getUnlimited()) { logger.log(Level.DEBUG, s.getKey() + "=UNLIMITED"); props.setProperty(s.getKey(), "UNLIMITED"); } else { logger.log(Level.DEBUG, s.getKey() + "=" + s.getValue().getValue().toString()); props.setProperty(s.getKey(), s.getValue().getValue().toString().trim()); } } catch (Exception e) { logger.log(Level.DEBUG, s.getKey() + " has no associated property -> SKIP"); } } props.save(outputFile); } catch (ConfigurationException e) { e.printStackTrace(); } }
From source file:ninja.utils.NinjaPropertiesImplTool.java
/** * This method checks that your configurations have set a * application.secret=23r213r12r123//from www . j av a2 s .com * * If application.secret is missing or is empty it will do the following: * - In dev and test mode it'll generate a new application secret and write the secret * to both src/main/java/conf/application.conf and the classes dir were the compiled stuff * goes. * - In prod it will throw a runtime exception and stop the server. */ public static void checkThatApplicationSecretIsSet(boolean isProd, String baseDirWithoutTrailingSlash, PropertiesConfiguration defaultConfiguration, Configuration compositeConfiguration) { String applicationSecret = compositeConfiguration.getString(NinjaConstant.applicationSecret); if (applicationSecret == null || applicationSecret.isEmpty()) { // If in production we stop the startup process. It simply does not make // sense to run in production if the secret is not set. if (isProd) { String errorMessage = "Fatal error. Key application.secret not set. Please fix that."; logger.error(errorMessage); throw new RuntimeException(errorMessage); } logger.info("Key application.secret not set. Generating new one and setting in conf/application.conf."); // generate new secret String secret = SecretGenerator.generateSecret(); // set in overall composite configuration => this enables this instance to // start immediately. Otherwise we would have another build cycle. compositeConfiguration.setProperty(NinjaConstant.applicationSecret, secret); // defaultConfiguration is: conf/application.conf (not prefixed) defaultConfiguration.setProperty(NinjaConstant.applicationSecret, secret); try { // STEP 1: Save in source directories: // save to compiled version => in src/main/target/ String pathToApplicationConfInSrcDir = baseDirWithoutTrailingSlash + File.separator + "src" + File.separator + "main" + File.separator + "java" + File.separator + NinjaProperties.CONF_FILE_LOCATION_BY_CONVENTION; Files.createParentDirs(new File(pathToApplicationConfInSrcDir)); // save to source defaultConfiguration.save(pathToApplicationConfInSrcDir); // STEP 2: Save in classes dir (target/classes or similar). // save in target directory (compiled version aka war aka classes dir) defaultConfiguration.save(); } catch (ConfigurationException e) { logger.error("Error while saving new secret to application.conf.", e); } catch (IOException e) { logger.error("Error while saving new secret to application.conf.", e); } } }
From source file:org.apache.accumulo.core.client.ClientConfiguration.java
public String serialize() { PropertiesConfiguration propConfig = new PropertiesConfiguration(); propConfig.copy(this); StringWriter writer = new StringWriter(); try {// w ww .j a v a 2s . c o m propConfig.save(writer); } catch (ConfigurationException e) { // this should never happen throw new IllegalStateException(e); } return writer.toString(); }