[jboss-svn-commits] JBL Code SVN: r18682 - in labs/jbossrules/trunk/drools-decisiontables/src: test/java/org/drools/decisiontable/parser and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Mar 4 23:42:14 EST 2008


Author: michael.neale at jboss.com
Date: 2008-03-04 23:42:13 -0500 (Tue, 04 Mar 2008)
New Revision: 18682

Modified:
   labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/xls/PropertiesSheetListener.java
   labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/PropertiesSheetListenerTest.java
Log:
JBRULES-1495 Properties and case sensitivity

Modified: labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/xls/PropertiesSheetListener.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/xls/PropertiesSheetListener.java	2008-03-05 01:13:28 UTC (rev 18681)
+++ labs/jbossrules/trunk/drools-decisiontables/src/main/java/org/drools/decisiontable/parser/xls/PropertiesSheetListener.java	2008-03-05 04:42:13 UTC (rev 18682)
@@ -2,13 +2,13 @@
 
 /*
  * Copyright 2005 JBoss Inc
- * 
+ *
  * Licensed 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.
@@ -25,16 +25,16 @@
 
 /**
  * Reads an Excel sheet as key-value properties.
- * 
+ *
  * Treats the first non-empty cell on a row as a key and any subsequent
  * non-empty cell as a value. Any cells defined after the second cell are
  * ignored as comments.
- * 
+ *
  * Could be easily adapted to accept multiple values per key but the semantics
  * were kept in line with Properties.
- * 
+ *
  * @author <a href="mailto:shaun.addison at gmail.com"> Shaun Addison </a>
- * 
+ *
  */
 public class PropertiesSheetListener
     implements
@@ -44,13 +44,13 @@
 
     private final Map                 _rowProperties = new HashMap();
 
-    private final Properties          _properties    = new Properties();
+    private final Properties  _properties = new CaseInsensitiveMap();
 
     /**
      * Return the key value pairs. If this is called before the sheet is
      * finished, then it will build the properties map with what is known.
      * Subsequent calls will update the properties map.
-     * 
+     *
      * @return properties
      */
     public Properties getProperties() {
@@ -62,7 +62,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see my.hssf.util.SheetListener#startSheet(java.lang.String)
      */
     public void startSheet(final String name) {
@@ -70,20 +70,20 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see my.hssf.util.SheetListener#finishSheet()
      */
     public void finishSheet() {
         for ( final Iterator iter = this._rowProperties.keySet().iterator(); iter.hasNext(); ) {
             final String[] keyValue = (String[]) this._rowProperties.get( iter.next() );
-            this._properties.setProperty( keyValue[0],
+            this._properties.put( keyValue[0],
                                      keyValue[1] );
         }
     }
 
     /**
      * Enter a new row. This is ignored.
-     * 
+     *
      * @param rowNumber
      *            The row number.
      * @param columns
@@ -96,7 +96,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see my.hssf.util.SheetListener#newCell(int, int, java.lang.String)
      */
     public void newCell(final int row,
@@ -124,4 +124,35 @@
         return value == null || value.trim().equals( "" );
     }
 
-}
\ No newline at end of file
+    public static class CaseInsensitiveMap extends Properties {
+
+
+    	@Override
+    	public String getProperty(String key) {
+    		if (this.containsKey(key)) {
+    			return super.getProperty(key);
+    		}
+    		return get(key);
+    	}
+
+    	@Override
+    	public String getProperty(String key, String defaultValue) {
+    		String r  = getProperty(key);
+    		return (r != null) ? r : defaultValue;
+    	}
+
+    	private String get(String key) {
+
+    		for (Iterator iterator = this.keySet().iterator(); iterator.hasNext();) {
+    			String k = (String) iterator.next();
+    			if (key.equalsIgnoreCase(k)) {
+    				return super.getProperty(k);
+    			}
+    		}
+    		return null;
+    	}
+
+    }
+
+}
+

Modified: labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/PropertiesSheetListenerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/PropertiesSheetListenerTest.java	2008-03-05 01:13:28 UTC (rev 18681)
+++ labs/jbossrules/trunk/drools-decisiontables/src/test/java/org/drools/decisiontable/parser/PropertiesSheetListenerTest.java	2008-03-05 04:42:13 UTC (rev 18682)
@@ -2,13 +2,13 @@
 
 /*
  * Copyright 2005 JBoss Inc
- * 
+ *
  * Licensed 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.
@@ -60,9 +60,28 @@
                           "key3", SheetListener.NON_MERGED );
 
         assertEquals( "value1",
-                      props.getProperty( "key1" ) );
+                      props.getProperty( "Key1" ) );
         assertEquals( "value2",
                       props.getProperty( "key2" ) );
 
     }
+
+    public void testCaseInsensitive() {
+    	Properties map = new PropertiesSheetListener.CaseInsensitiveMap();
+    	map.setProperty("x3", "hey");
+    	map.setProperty("x4", "wHee");
+    	map.setProperty("XXx", "hey2");
+
+    	assertNull(map.getProperty("x"));
+    	assertEquals("hey", map.getProperty("x3"));
+    	assertEquals("hey", map.getProperty("X3"));
+    	assertEquals("wHee", map.getProperty("x4"));
+    	assertEquals("hey2", map.getProperty("xxx"));
+    	assertEquals("hey2", map.getProperty("XXX"));
+    	assertEquals("hey2", map.getProperty("XXx"));
+
+    	assertEquals("Whee2", map.getProperty("x", "Whee2"));
+
+    }
+
 }
\ No newline at end of file




More information about the jboss-svn-commits mailing list