commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Molozian (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CONFIGURATION-480) Reading Manifest files using PropertiesConfiguration
Date Mon, 27 Feb 2012 12:37:48 GMT

    [ https://issues.apache.org/jira/browse/CONFIGURATION-480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13217169#comment-13217169
] 

Chris Molozian commented on CONFIGURATION-480:
----------------------------------------------

Apologies for the late response, I've embedded the code that's attempting to parse the MANIFEST.MF
file:

{code}
PropertiesConfiguration manifestConf = new PropertiesConfiguration();
manifestConf.setIOFactory(new ManifestIOFactory());
manifestConf.setFileName("/META-INF/MANIFEST.MF");
manifestConf.load();
{code}

You didn't really answer my other question, is there anything within Apache Commons Configuration
that supports the parsing of the MANIFEST.MF format?

Thanks.
                
> 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
>
> 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 is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message