List of usage examples for org.apache.commons.configuration PropertiesConfigurationLayout setComment
public void setComment(String key, String comment)
From source file:com.francetelecom.clara.cloud.logicalmodel.LogicalConfigServiceUtils.java
public void dumpConfigContent(StructuredLogicalConfigServiceContent content, Writer writer) throws InvalidConfigServiceException { try {//ww w. j av a 2s . c o m ValidatorUtil.validate(content); } catch (TechnicalException e) { throw new InvalidConfigServiceException("Invalid structured content:" + e, e); } PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); PropertiesConfigurationLayout layout = propertiesConfiguration.getLayout(); layout.setLineSeparator("\n"); String headerComment = content.getHeaderComment(); if (headerComment != null) { layout.setHeaderComment(headerComment); } for (ConfigEntry configEntry : content.configEntries) { String key = configEntry.getKey(); propertiesConfiguration.addProperty(key, configEntry.getValue()); String comment = configEntry.getComment(); layout.setSeparator(key, "="); if (comment != null) { layout.setComment(key, comment); } } try { propertiesConfiguration.save(writer); } catch (ConfigurationException e) { throw new InvalidConfigServiceException("Invalid structured content or output:" + e, e); } }
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 ww w. ja v a 2 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.mirth.connect.server.migration.ServerMigrator.java
private void runConfigurationMigrator(ConfigurationMigrator configurationMigrator, PropertiesConfiguration mirthConfig, Version version) { configurationMigrator.updateConfiguration(mirthConfig); HashMap<String, Object> addedProperties = new LinkedHashMap<String, Object>(); Map<String, Object> propertiesToAdd = configurationMigrator.getConfigurationPropertiesToAdd(); if (propertiesToAdd != null) { for (Entry<String, Object> propertyToAdd : propertiesToAdd.entrySet()) { if (!mirthConfig.containsKey(propertyToAdd.getKey())) { PropertiesConfigurationLayout layout = mirthConfig.getLayout(); String key = propertyToAdd.getKey(); Object value;//w w w . j ava2 s.co m String comment = ""; if (propertyToAdd.getValue() instanceof Pair) { // If a pair is used, get both the value and comment Pair<Object, String> pair = (Pair<Object, String>) propertyToAdd.getValue(); value = pair.getLeft(); comment = pair.getRight(); } else { // Only the value was specified value = propertyToAdd.getValue(); } mirthConfig.setProperty(key, value); // If this is the first added property, add a general comment about the added properties before it if (addedProperties.isEmpty()) { if (StringUtils.isNotEmpty(comment)) { comment = "\n\n" + comment; } comment = "The following properties were automatically added on startup for version " + version + comment; } if (StringUtils.isNotEmpty(comment)) { // When a comment is specified, always put a blank line before it layout.setBlancLinesBefore(key, 1); layout.setComment(key, comment); } addedProperties.put(key, value); } } } List<String> removedProperties = new ArrayList<String>(); String[] propertiesToRemove = configurationMigrator.getConfigurationPropertiesToRemove(); if (propertiesToRemove != null) { for (String propertyToRemove : propertiesToRemove) { if (mirthConfig.containsKey(propertyToRemove)) { mirthConfig.clearProperty(propertyToRemove); removedProperties.add(propertyToRemove); } } } if (!addedProperties.isEmpty() || !removedProperties.isEmpty()) { if (!addedProperties.isEmpty()) { logger.info("Adding properties in mirth.properties: " + addedProperties); } if (!removedProperties.isEmpty()) { logger.info("Removing properties in mirth.properties: " + removedProperties); } try { mirthConfig.save(); } catch (ConfigurationException e) { logger.error("There was an error updating mirth.properties.", e); if (!addedProperties.isEmpty()) { logger.error("The following properties should be added to mirth.properties manually: " + addedProperties.toString()); } if (!removedProperties.isEmpty()) { logger.error("The following properties should be removed from mirth.properties manually: " + removedProperties.toString()); } } } }
From source file:com.mirth.connect.server.controllers.DefaultConfigurationController.java
private void saveConfigurationProperties(Map<String, ConfigurationProperty> map) throws ControllerException { try {// w ww . j a va2 s . com 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:com.mirth.connect.cli.CommandLineInterface.java
private void commandExportMap(Token[] arguments) throws ClientException { if (hasInvalidNumberOfArguments(arguments, 1)) { return;/*from w w w. ja va2 s . c o m*/ } // file path String path = arguments[1].getText(); File file = new File(path); if (file != null) { try { PropertiesConfiguration properties = new PropertiesConfiguration(file); properties.clear(); PropertiesConfigurationLayout layout = properties.getLayout(); Map<String, ConfigurationProperty> configurationMap = client.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(); out.println("Configuration map export complete."); } catch (ConfigurationException e) { error("Unable to export configuration map.", e); } } }