List of usage examples for org.apache.commons.configuration PropertiesConfigurationLayout isSingleLine
public boolean isSingleLine(String key)
From source file:com.francetelecom.clara.cloud.logicalmodel.LogicalConfigServiceUtils.java
/** * * * @param reader/* w w w . ja v a 2 s.com*/ * @return */ public StructuredLogicalConfigServiceContent parseConfigContent(Reader reader) throws InvalidConfigServiceException { List<ConfigEntry> parsedEntries = new ArrayList<ConfigEntry>(); PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); try { propertiesConfiguration.load(reader); } catch (ConfigurationException e) { InvalidConfigServiceException invalidConfigServiceException = new InvalidConfigServiceException( "Invalid config content. Caught:" + e, e); throw invalidConfigServiceException; } PropertiesConfigurationLayout layout = propertiesConfiguration.getLayout(); String headerComment = layout.getHeaderComment(); Set<String> keys = layout.getKeys(); Set<String> duplicates = new HashSet<String>(); for (String key : keys) { String comment = layout.getComment(key); if (comment != null) { comment = escapesPoundsInComments(comment); } if (!layout.isSingleLine(key)) { //reject the duplicate key duplicates.add(key); } else { String value = propertiesConfiguration.getString(key); parsedEntries.add(new ConfigEntry(key, value, comment)); } } if (duplicates.size() > 0) { InvalidConfigServiceException invalidConfigServiceException = new InvalidConfigServiceException( "Collisions! " + duplicates); invalidConfigServiceException.setType(ErrorType.DUPLICATE_KEYS); invalidConfigServiceException.getDuplicateKeys().addAll(duplicates); throw invalidConfigServiceException; } List<ConfigEntry> configEntries = parsedEntries; StructuredLogicalConfigServiceContent structuredLogicalConfigServiceContent = new StructuredLogicalConfigServiceContent( headerComment, configEntries); return structuredLogicalConfigServiceContent; }