Author: cziegeler Date: Thu Jun 18 06:07:55 2015 New Revision: 1686141 URL: http://svn.apache.org/r1686141 Log: FELIX-4917 : FilePersistenceManager doesn't support comments
Added: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/ConfigurationHandlerTest.java (with props) Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java?rev=1686141&r1=1686140&r2=1686141&view=diff ============================================================================== --- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java (original) +++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/file/ConfigurationHandler.java Thu Jun 18 06:07:55 2015 @@ -75,6 +75,8 @@ public class ConfigurationHandler protected static final int TOKEN_VAL_OPEN = '"'; // '{'; protected static final int TOKEN_VAL_CLOS = '"'; // '}'; + protected static final int TOKEN_COMMENT = '#'; + // simple types (string & primitive wrappers) protected static final int TOKEN_SIMPLE_STRING = 'T'; protected static final int TOKEN_SIMPLE_INTEGER = 'I'; @@ -290,12 +292,12 @@ public class ConfigurationHandler Hashtable configuration = new Hashtable(); token = 0; - while ( nextToken( pr ) == TOKEN_NAME ) + while ( nextToken( pr, true ) == TOKEN_NAME ) { String key = tokenValue; // expect equal sign - if ( nextToken( pr ) != TOKEN_EQ ) + if ( nextToken( pr, false ) != TOKEN_EQ ) { throw readFailure( token, TOKEN_EQ ); } @@ -566,8 +568,7 @@ public class ConfigurationHandler } } - - private int nextToken( PushbackReader pr ) throws IOException + private int nextToken( PushbackReader pr, final boolean newLine ) throws IOException { int c = ignorableWhiteSpace( pr ); @@ -577,6 +578,22 @@ public class ConfigurationHandler return ( token = c ); } + // check for comment + if ( newLine && c == TOKEN_COMMENT ) + { + // skip everything until end of line + do + { + c = read( pr ); + } while ( c != -1 && c != '\n' ); + if ( c == -1 ) + { + return ( token = c); + } + // and start over + return nextToken( pr, true ); + } + // check whether there is a name if ( NAME_CHARS.get( c ) || !TOKEN_CHARS.get( c ) ) { Added: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/ConfigurationHandlerTest.java URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/ConfigurationHandlerTest.java?rev=1686141&view=auto ============================================================================== --- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/ConfigurationHandlerTest.java (added) +++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/ConfigurationHandlerTest.java Thu Jun 18 06:07:55 2015 @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.cm.file; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.Dictionary; + +import junit.framework.TestCase; + +public class ConfigurationHandlerTest extends TestCase +{ + + private static final String PAR_1 = "mongouri"; + private static final String VAL_1 = "127.0.0.1:27017"; + private static final String PAR_2 = "customBlobStore"; + private static final String VAL_2 = "true"; + + private static final String CONFIG = + "#mongodb URI\n" + + PAR_1 + "=\"" + VAL_1 + "\"\n" + + "\n" + + " # custom datastore\n" + + PAR_2 + "=B\"" + VAL_2 + "\"\n"; + + public void testComments() throws IOException + { + final Dictionary dict = ConfigurationHandler.read(new ByteArrayInputStream(CONFIG.getBytes("UTF-8"))); + assertEquals(2, dict.size()); + assertEquals(VAL_1, dict.get(PAR_1)); + assertEquals(VAL_2, dict.get(PAR_2).toString()); + } +} Propchange: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/ConfigurationHandlerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/file/ConfigurationHandlerTest.java ------------------------------------------------------------------------------ svn:keywords = author date id revision rev url