You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Oliver Heger (JIRA)" <ji...@apache.org> on 2016/03/24 21:13:26 UTC
[jira] [Updated] (CONFIGURATION-480) Reading Manifest files using
PropertiesConfiguration
[ https://issues.apache.org/jira/browse/CONFIGURATION-480?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oliver Heger updated CONFIGURATION-480:
---------------------------------------
Fix Version/s: (was: 2.0)
2.x
> Reading Manifest files using PropertiesConfiguration
> ----------------------------------------------------
>
> Key: CONFIGURATION-480
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-480
> Project: Commons Configuration
> Issue Type: Bug
> Affects Versions: 1.7
> Reporter: Chris Molozian
> Fix For: 2.x
>
>
> I've searched through the documentation and online with Google. The documentation for PropertiesConfiguration explains that it can parse files with '=' or ':' or ' ' as delimiters. I have a MANIFEST.MF file with the following format:
> {code:title=MANIFEST.MF|borderStyle=solid}
> Manifest-Version: 1.0
> Implementation-Title: webapp
> Implementation-Version: 0.0.1
> Created-By: Gradle 1.0-milestone-6
> Build-Jdk: 1.6.0_26
> {code}
> I've tried to use the PropertiesConfiguration to parse this file, assuming that the ' ' delimiter would be used to divide key-value pairs. Instead I get the following error:
> {code}
> java.lang.IllegalArgumentException: Key for add operation must be defined!
> at org.apache.commons.configuration.tree.DefaultExpressionEngine.prepareAdd(DefaultExpressionEngine.java:420)
> at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:383)
> at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:147)
> at org.apache.commons.configuration.AbstractConfiguration.addPropertyValues(AbstractConfiguration.java:423)
> at org.apache.commons.configuration.AbstractConfiguration.append(AbstractConfiguration.java:1271)
> {code}
> At the moment I've created a (very rough) custom PropertiesReader as suggested by the User Guide for handling "unconventional formats".
> {code}
> private static class ManifestPropertiesReader
> extends PropertiesConfiguration.PropertiesReader {
> public ManifestPropertiesReader(final Reader in, final char delimiter) {
> super(in, delimiter);
> }
> @Override
> protected void parseProperty(final String line) {
> final int pos = line.indexOf(':');
> final String key = line.substring(0, pos).trim();
> final String value = line.substring(pos + 1).trim();
> initPropertyName(key);
> initPropertyValue(value);
> }
> }
> {code}
> And:
> {code}
> private static class ManifestIOFactory
> extends PropertiesConfiguration.DefaultIOFactory {
> /** Use a custom {@code PropertiesReader} for Manifest files. */
> @Override
> public PropertiesReader createPropertiesReader(final Reader in,
> final char delimiter) {
> return new ManifestPropertiesReader(in, delimiter);
> }
> }
> {code}
> Should all this be necessary to parse MANIFEST.MF files or have I missed something?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)