You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2008/10/28 15:29:56 UTC

svn commit: r708583 - in /incubator/sling/trunk/extensions/jcrinstall/src: main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/

Author: bdelacretaz
Date: Tue Oct 28 07:29:55 2008
New Revision: 708583

URL: http://svn.apache.org/viewvc?rev=708583&view=rev
Log:
SLING-715 - support typed properties in jcrinstall cfg files

Added:
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/DefaultConverter.java   (with props)
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyConverter.java   (with props)
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyValue.java   (with props)
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/SimpleTypeConverter.java   (with props)
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/StringArrayConverter.java   (with props)
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverter.java   (with props)
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverterException.java   (with props)
Modified:
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/DictionaryReader.java
    incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/DictionaryReaderTest.java

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java?rev=708583&r1=708582&r2=708583&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java (original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java Tue Oct 28 07:29:55 2008
@@ -26,7 +26,6 @@
 import java.util.Dictionary;
 import java.util.Map;
 
-import org.apache.felix.cm.file.ConfigurationHandler;
 import org.apache.sling.jcr.jcrinstall.osgi.OsgiResourceProcessor;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.cm.Configuration;
@@ -41,6 +40,7 @@
     public static final String CONFIG_EXTENSION = ".cfg";
     private final ConfigurationAdmin configurationAdmin;
     private final Logger log = LoggerFactory.getLogger(this.getClass());
+    private final DictionaryReader reader = new DictionaryReader();
     
     ConfigResourceProcessor(ConfigurationAdmin ca) {
         configurationAdmin = ca;
@@ -54,7 +54,7 @@
     public int installOrUpdate(String uri, Map<String, Object> attributes, InputStream data) throws Exception {
         
         // Load configuration properties
-        final Dictionary dict = DictionaryReader.load(data);
+        final Dictionary dict = reader.load(data);
         
         // Get pids from node name
         final ConfigurationPid pid = new ConfigurationPid(uri);

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/DictionaryReader.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/DictionaryReader.java?rev=708583&r1=708582&r2=708583&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/DictionaryReader.java (original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/DictionaryReader.java Tue Oct 28 07:29:55 2008
@@ -1,24 +1,45 @@
+/*
+ * 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.sling.jcr.jcrinstall.osgi.impl;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Properties;
 
+import org.apache.sling.jcr.jcrinstall.osgi.impl.propertyconverter.PropertyConverter;
+import org.apache.sling.jcr.jcrinstall.osgi.impl.propertyconverter.PropertyValue;
+import org.apache.sling.jcr.jcrinstall.osgi.impl.propertyconverter.ValueConverterException;
+
 /** Reads a Dictionary from an InputStream, using the
  *  syntax of the Properties class, enhanced to support
- *  multivalued properties.
+ *  multivalued properties and types supported by the PropertyConverter
  */
 public class DictionaryReader {
-    public static final String ARRAY_MARKER = "[]";
+    private final PropertyConverter converter = new PropertyConverter();
     
     /** Read Dictionary from the given InputStream,
      *  which is *not* closed before returning
      */
-    public static Dictionary<?,?> load(InputStream is) throws IOException {
+    public Dictionary<?,?> load(InputStream is) throws IOException {
         final Properties p = new Properties();
         p.load(is);
         return convert(p);
@@ -29,65 +50,14 @@
      *  lists of values, and are converted to an Array. The []
      *  is removed from the property name. 
      */
-    public static Dictionary<?,?> convert(Properties p) {
+    public Dictionary<?,?> convert(Properties p) throws ValueConverterException {
         final Hashtable <String, Object> result = new Hashtable<String, Object>();
         
         for(Map.Entry<Object, Object> e : p.entrySet()) {
-            final String key = (String)e.getKey();
-            if(key.trim().endsWith(ARRAY_MARKER)) {
-                final String newKey = key.substring(0, key.length() - ARRAY_MARKER.length()).trim();
-                result.put(newKey, convertValue((String)e.getValue()));
-            } else {
-                result.put(key, e.getValue());
-            }
-        }
-        
-        return result;
-    }
-    
-    /** Convert value to a String[], trimming all values */
-    public static String [] convertValue(String value) {
-        
-        if(value.trim().length() == 0) {
-            return new String[0];
+            final PropertyValue v = converter.convert((String)e.getKey(), (String)e.getValue());
+            result.put(v.getKey(), v.getValue());
         }
         
-        return splitWithEscapes(value, ',');
-    }
-    
-    /** Split string, ignoring separators that directly follow a backslash.
-     *  All values are trimmed
-     */
-    public static String [] splitWithEscapes(String str, char separator) {
-        final ArrayList<String> a = new ArrayList<String>();
-        StringBuffer current = new StringBuffer();
-        char lastChar = 0;
-        for(int i=0; i < str.length(); i++) {
-            final char c = str.charAt(i);
-            
-            if(c == separator) {
-                if(lastChar == '\\') {
-                    // replace lastchar with c
-                    current.setCharAt(current.length() - 1, c);
-                } else if(current.length() > 0) {
-                    a.add(current.toString());
-                    current = new StringBuffer();
-                }
-            } else {
-                current.append(c);
-            }
-            
-            lastChar = c;
-        }
-        if(current.length() > 0) {
-            a.add(current.toString());
-        }
-        
-        final String [] result = new String[a.size()];
-        int i=0;
-        for(String s : a) {
-            result[i++] = s.trim();
-        }
         return result;
     }
 }

Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/DefaultConverter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/DefaultConverter.java?rev=708583&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/DefaultConverter.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/DefaultConverter.java Tue Oct 28 07:29:55 2008
@@ -0,0 +1,35 @@
+/*
+ * 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.sling.jcr.jcrinstall.osgi.impl.propertyconverter;
+
+/** Do-nothing conversion, just trims values */
+class DefaultConverter implements ValueConverter {
+
+    public boolean appliesTo(String key) {
+        return true;
+    }
+
+    public PropertyValue convert(String key, String value) {
+        if(value != null) {
+            value = value.trim();
+        }
+        return new PropertyValue(key, value);
+    }
+
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/DefaultConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/DefaultConverter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyConverter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyConverter.java?rev=708583&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyConverter.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyConverter.java Tue Oct 28 07:29:55 2008
@@ -0,0 +1,83 @@
+/*
+ * 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.sling.jcr.jcrinstall.osgi.impl.propertyconverter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/** Convert key/value Strings to various data types, used
+ *  for SLING-707 to enhance the Properties format with multi-value
+ *  and typed properties. 
+ */
+public class PropertyConverter {
+    private final List<ValueConverter> converters;
+    
+    public PropertyConverter() {
+        converters = new ArrayList<ValueConverter>();
+        
+        converters.add(new StringArrayConverter());
+        
+        converters.add(new SimpleTypeConverter("boolean") {
+            protected Object convertValue(String key, String value) throws ValueConverterException {
+                try {
+                    return Boolean.valueOf(value);
+                } catch(Exception e) {
+                    throw new ValueConverterException("Invalid Boolean value", key, value);
+                }
+            }
+        });
+        
+        converters.add(new SimpleTypeConverter("integer") {
+            protected Object convertValue(String key, String value) throws ValueConverterException {
+                try {
+                    return Integer.valueOf(value);
+                } catch(Exception e) {
+                    throw new ValueConverterException("Invalid Integer value", key, value);
+                }
+            }
+        });
+        
+        converters.add(new SimpleTypeConverter("double") {
+            protected Object convertValue(String key, String value) throws ValueConverterException {
+                try {
+                    return Double.valueOf(value);
+                } catch(Exception e) {
+                    throw new ValueConverterException("Invalid Double value", key, value);
+                }
+            }
+        });
+        
+        // This must be the last one
+        converters.add(new DefaultConverter());
+    }
+    
+    public PropertyValue convert(String key, String value) throws ValueConverterException {
+        PropertyValue result = null;
+        
+        for(ValueConverter vc : converters) {
+            if(vc.appliesTo(key)) {
+                result = vc.convert(key, value);
+                break;
+            }
+        }
+        
+        return result;
+    }
+    
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyConverter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyValue.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyValue.java?rev=708583&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyValue.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyValue.java Tue Oct 28 07:29:55 2008
@@ -0,0 +1,37 @@
+/*
+ * 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.sling.jcr.jcrinstall.osgi.impl.propertyconverter;
+
+public class PropertyValue {
+    private final String key;
+    private final Object value;
+    
+    public PropertyValue(String key, Object value) {
+        this.key = key;
+        this.value = value;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public Object getValue() {
+        return value;
+    }
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/PropertyValue.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/SimpleTypeConverter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/SimpleTypeConverter.java?rev=708583&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/SimpleTypeConverter.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/SimpleTypeConverter.java Tue Oct 28 07:29:55 2008
@@ -0,0 +1,41 @@
+/*
+ * 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.sling.jcr.jcrinstall.osgi.impl.propertyconverter;
+
+/** Base class for simple type conversions using (type) marker */
+abstract class SimpleTypeConverter implements ValueConverter {
+
+    private final String typePattern;
+    
+    SimpleTypeConverter(String typeName) {
+        this.typePattern = "(" + typeName + ")";
+    }
+    
+    public boolean appliesTo(String key) {
+        return key.endsWith(typePattern);
+    }
+
+    public PropertyValue convert(final String key, String value) throws ValueConverterException {
+        final int pos = key.indexOf(typePattern);
+        final String modifiedKey = key.substring(0, pos).trim();
+        return new PropertyValue(modifiedKey, convertValue(key, value));
+    }
+    
+    protected abstract Object convertValue(String key, String value) throws ValueConverterException;
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/SimpleTypeConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/SimpleTypeConverter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/StringArrayConverter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/StringArrayConverter.java?rev=708583&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/StringArrayConverter.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/StringArrayConverter.java Tue Oct 28 07:29:55 2008
@@ -0,0 +1,80 @@
+/*
+ * 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.sling.jcr.jcrinstall.osgi.impl.propertyconverter;
+
+import java.util.ArrayList;
+
+/** Convert arrays of Strings */
+class StringArrayConverter implements ValueConverter {
+
+    public boolean appliesTo(String key) {
+        return key.endsWith("[]") || key.endsWith("[string]");
+    }
+
+    public PropertyValue convert(String key, String value) throws ValueConverterException {
+        PropertyValue result = null;
+        
+        final int pos = key.lastIndexOf('[');
+        key = key.substring(0, pos).trim();
+        
+        if(value.trim().length() == 0) {
+            result = new PropertyValue(key, new String[0]);
+        } else {
+            result = new PropertyValue(key, splitWithEscapes(value, ',')); 
+        }
+        
+        return result;
+    }
+
+    /** Split string, ignoring separators that directly follow a backslash.
+     *  All values are trimmed
+     */
+    static String [] splitWithEscapes(String str, char separator) {
+        final ArrayList<String> a = new ArrayList<String>();
+        StringBuffer current = new StringBuffer();
+        char lastChar = 0;
+        for(int i=0; i < str.length(); i++) {
+            final char c = str.charAt(i);
+            
+            if(c == separator) {
+                if(lastChar == '\\') {
+                    // replace lastchar with c
+                    current.setCharAt(current.length() - 1, c);
+                } else if(current.length() > 0) {
+                    a.add(current.toString());
+                    current = new StringBuffer();
+                }
+            } else {
+                current.append(c);
+            }
+            
+            lastChar = c;
+        }
+        if(current.length() > 0) {
+            a.add(current.toString());
+        }
+        
+        final String [] result = new String[a.size()];
+        int i=0;
+        for(String s : a) {
+            result[i++] = s.trim();
+        }
+        return result;
+    }
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/StringArrayConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/StringArrayConverter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverter.java?rev=708583&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverter.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverter.java Tue Oct 28 07:29:55 2008
@@ -0,0 +1,25 @@
+/*
+ * 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.sling.jcr.jcrinstall.osgi.impl.propertyconverter;
+
+/** Convert a single Property value */
+interface ValueConverter {
+    boolean appliesTo(String key);
+    PropertyValue convert(String key, String value) throws ValueConverterException;
+}
\ No newline at end of file

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverterException.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverterException.java?rev=708583&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverterException.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverterException.java Tue Oct 28 07:29:55 2008
@@ -0,0 +1,28 @@
+/*
+ * 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.sling.jcr.jcrinstall.osgi.impl.propertyconverter;
+
+import java.io.IOException;
+
+@SuppressWarnings("serial")
+public class ValueConverterException extends IOException {
+    public ValueConverterException(String reason, String key, String value) {
+        super(reason + " (key=" + key + ", value=" + value + ")");
+    }
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverterException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/propertyconverter/ValueConverterException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/DictionaryReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/DictionaryReaderTest.java?rev=708583&r1=708582&r2=708583&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/DictionaryReaderTest.java (original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/DictionaryReaderTest.java Tue Oct 28 07:29:55 2008
@@ -26,6 +26,9 @@
 import java.util.Dictionary;
 import java.util.Properties;
 
+import org.apache.sling.jcr.jcrinstall.osgi.impl.propertyconverter.PropertyConverter;
+import org.apache.sling.jcr.jcrinstall.osgi.impl.propertyconverter.ValueConverterException;
+
 /** Test the DictionaryReader */
 public class DictionaryReaderTest {
     
@@ -39,34 +42,38 @@
         }
     }
     
-    @org.junit.Test public void testConvertValue() {
-        assertArray("one two", new String[] { "one", "two" }, DictionaryReader.convertValue("one, two\t"));
-        assertArray("one", new String[] { "one" }, DictionaryReader.convertValue("\t one "));
-        assertArray("empty array", new String[] { }, DictionaryReader.convertValue("\t \n"));
-    }
-    
-    @org.junit.Test public void testConvertValueWithEscapes() {
-        assertArray("one two", new String[] { "one", "two,three" }, DictionaryReader.convertValue("one, two\\,three"));
-        assertArray("one", new String[] { "one,two,three" }, DictionaryReader.convertValue("one\\,two\\,three"));
-    }
-    
-    @org.junit.Test public void testSplitWithEscapes() {
-        assertArray("empty", new String[0], DictionaryReader.splitWithEscapes("", ','));
-        assertArray("a", new String[] { "a" }, DictionaryReader.splitWithEscapes("a", ','));
-        assertArray("multi", new String[] { "a\\,,b\\" }, DictionaryReader.splitWithEscapes("a\\\\,\\,b\\", ','));
-        assertArray("a,b", new String[] { "a", "b" }, DictionaryReader.splitWithEscapes("a, b\t", ','));
-        assertArray("a,b,c", new String[] { "a", "b, c" }, DictionaryReader.splitWithEscapes("a, b\\, c\t", ','));
-        assertArray("a,b,c,d", new String[] { "a", "b, c ,", "d" }, DictionaryReader.splitWithEscapes("a, b\\, c \\,,d ", ','));
+    @org.junit.Test public void testConvertValue() throws ValueConverterException {
+        final PropertyConverter c = new PropertyConverter();
+        assertArray("one two", new String[] { "one", "two" }, c.convert("x[]", "one, two\t").getValue());
+        assertArray("one", new String[] { "one" }, c.convert("x[]", "\t one ").getValue());
+        assertArray("empty array", new String[] { }, c.convert("x []", "\t \n").getValue());
+    }
+    
+    @org.junit.Test public void testConvertValueWithEscapes() throws ValueConverterException {
+        final PropertyConverter c = new PropertyConverter();
+        assertArray("one two", new String[] { "one", "two,three" }, c.convert("x[]", "one, two\\,three").getValue());
+        assertArray("one", new String[] { "one,two,three" }, c.convert("x[]", "one\\,two\\,three").getValue());
+    }
+    
+    @org.junit.Test public void testSplitWithEscapes() throws ValueConverterException {
+        final PropertyConverter c = new PropertyConverter();
+        assertArray("empty", new String[0], c.convert("x[]", "").getValue());
+        assertArray("a", new String[] { "a" }, c.convert("x[]", "a").getValue());
+        assertArray("multi", new String[] { "a\\,,b\\" }, c.convert("x[]", "a\\\\,\\,b\\").getValue());
+        assertArray("a,b", new String[] { "a", "b" }, c.convert("x[]", "a, b\t").getValue());
+        assertArray("a,b,c", new String[] { "a", "b, c" }, c.convert("x[]", "a, b\\, c\t").getValue());
+        assertArray("a,b,c,d", new String[] { "a", "b, c ,", "d" }, c.convert("x[]", "a, b\\, c \\,,d ").getValue());
     }
      
-    @org.junit.Test public void testConvertProperties() {
+    @org.junit.Test public void testConvertProperties() throws ValueConverterException {
         final Properties p = new Properties();
         p.setProperty("a", "1");
         p.setProperty("b", "2");
         p.setProperty("c[]", "1, 2, 3");
         p.setProperty("d []", "4, 5, 6");
         
-        final Dictionary<?, ?> d = DictionaryReader.convert(p);
+        final DictionaryReader r = new DictionaryReader();
+        final Dictionary<?, ?> d = r.convert(p);
         assertEquals("a", d.get("a"), "1");
         assertEquals("b", d.get("b"), "2");
         
@@ -85,9 +92,10 @@
             ;
         
         final ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        final DictionaryReader r = new DictionaryReader();
         Dictionary<?, ?> d = null;
         try {
-            d = DictionaryReader.load(is);
+            d = r.load(is);
         } finally {
             is.close();
         }
@@ -99,4 +107,31 @@
         assertArray("c", new String[] { "1", "2,A", "3" }, d.get("c"));
         assertEquals("d", d.get("d"), "12");
     }
-}
+    
+    @org.junit.Test public void testDataTypes() throws IOException {
+        final String data =
+            "a = 1\n"
+            + "b(integer) = 242\n"
+            + "# a comment\n"
+            + "c(boolean) = true\n"
+            + "d(double) = 14.23\n"
+            + "e = My Value\n"
+            ;
+        
+        final ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        final DictionaryReader r = new DictionaryReader();
+        Dictionary<?, ?> d = null;
+        try {
+            d = r.load(is);
+        } finally {
+            is.close();
+        }
+        
+        assertEquals("Number of entries must match", 5, d.size());
+        assertEquals("String value matches", "1", d.get("a"));
+        assertEquals("Integer value matches", new Integer(242), d.get("b"));
+        assertEquals("Boolean value matches", new Boolean(true), d.get("c"));
+        assertEquals("Double value matches", new Double(14.24), d.get("d"));
+        assertEquals("String value matches", "My Value", d.get("e"));
+    }
+}
\ No newline at end of file