Example usage for org.apache.commons.configuration PropertiesConfigurationLayout getComment

List of usage examples for org.apache.commons.configuration PropertiesConfigurationLayout getComment

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfigurationLayout getComment.

Prototype

public String getComment(String key) 

Source Link

Document

Returns the comment for the specified property key.

Usage

From source file:com.liferay.ide.ui.editor.LiferayPropertiesSourceViewerConfiguration.java

private PropKey[] parseKeys(InputStream inputStream) throws ConfigurationException, IOException {
    List<PropKey> parsed = new ArrayList<PropKey>();

    final PortalPropertiesConfiguration config = new PortalPropertiesConfiguration();
    config.load(inputStream);/*from  w w  w .  j a v  a  2s .  c o m*/
    inputStream.close();

    final Iterator<?> keys = config.getKeys();
    final PropertiesConfigurationLayout layout = config.getLayout();

    while (keys.hasNext()) {
        final String key = keys.next().toString();
        final String comment = layout.getComment(key);

        parsed.add(new PropKey(key, comment == null ? null : comment.replaceAll("\n", "\n<br/>")));
    }

    final PropKey[] parsedKeys = parsed.toArray(new PropKey[0]);

    Arrays.sort(parsedKeys, new Comparator<PropKey>() {
        public int compare(PropKey o1, PropKey o2) {
            return o1.getKey().compareTo(o2.getKey());
        }
    });

    return parsedKeys;
}

From source file:com.francetelecom.clara.cloud.logicalmodel.LogicalConfigServiceUtils.java

/**
 *
 *
 * @param reader/* w  w  w.j  av a 2s. c om*/
 * @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;
}