shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r1006221 - in /shiro/trunk/core/src: main/java/org/apache/shiro/config/Ini.java test/java/org/apache/shiro/config/IniTest.java
Date Sat, 09 Oct 2010 19:37:02 GMT
Author: lhazlewood
Date: Sat Oct  9 19:37:01 2010
New Revision: 1006221

URL: http://svn.apache.org/viewvc?rev=1006221&view=rev
Log:
SHIRO-196 - Reverted changes that were intended as fixes for another issue (fix not 100% complete
yet)

Modified:
    shiro/trunk/core/src/main/java/org/apache/shiro/config/Ini.java
    shiro/trunk/core/src/test/java/org/apache/shiro/config/IniTest.java

Modified: shiro/trunk/core/src/main/java/org/apache/shiro/config/Ini.java
URL: http://svn.apache.org/viewvc/shiro/trunk/core/src/main/java/org/apache/shiro/config/Ini.java?rev=1006221&r1=1006220&r2=1006221&view=diff
==============================================================================
--- shiro/trunk/core/src/main/java/org/apache/shiro/config/Ini.java (original)
+++ shiro/trunk/core/src/main/java/org/apache/shiro/config/Ini.java Sat Oct  9 19:37:01 2010
@@ -26,8 +26,6 @@ import org.slf4j.LoggerFactory;
 
 import java.io.*;
 import java.util.*;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 /**
  * A class representing the <a href="http://en.wikipedia.org/wiki/INI_file">INI</a>
text configuration format.
@@ -303,36 +301,23 @@ public class Ini implements Map<String, 
         return new ByteArrayInputStream(bytes);
     }
 
-    private static final Pattern PATTERN = Pattern.compile("(\\S+)\\s*[\\s|:|=]\\s*(.+)");
-    private static Map<String, String> toProps(String content) {
-        Map<String, String> props = new LinkedHashMap<String, String>();
-        String line = null;
+    private static Properties toProps(String content) {
+        InputStream is = toInputStream(content);
+        Properties props = new Properties();
         try {
-            BufferedReader reader = new BufferedReader(new StringReader(content));
-            while ((line = reader.readLine()) != null) {
-                Matcher matcher = PATTERN.matcher(StringUtils.clean(line));
-                if (matcher.matches() && matcher.groupCount() != 2)
-                    throw new ConfigurationException("Missing property=value assignement
at line " + line);
-                String key = StringUtils.clean(matcher.group(1));
-                String value = StringUtils.clean(matcher.group(2));
-                if (key == null || value == null)
-                    throw new ConfigurationException("Missing property=value assignement
at line " + line);
-                props.put(key, value);
-            }
+            props.load(is);
         } catch (IOException e) {
             throw new ConfigurationException(e);
-        } catch (IllegalStateException e) {
-            throw new ConfigurationException("Missing property=value assignement at line
" + line);
         }
         return props;
     }
 
-    private void addSection(String name, CharSequence content) {
+    private void addSection(String name, StringBuffer content) {
         if (content.length() > 0) {
             String contentString = content.toString();
             String cleaned = StringUtils.clean(contentString);
             if (cleaned != null) {
-                Map<String, String> props = toProps(contentString);
+                Properties props = toProps(contentString);
                 if (!props.isEmpty()) {
                     sections.put(name, new Section(name, props));
                 }
@@ -349,7 +334,7 @@ public class Ini implements Map<String, 
     public void load(Scanner scanner) {
 
         String sectionName = DEFAULT_SECTION_NAME;
-        StringBuilder sectionContent = new StringBuilder();
+        StringBuffer sectionContent = new StringBuffer();
 
         while (scanner.hasNextLine()) {
 
@@ -367,7 +352,7 @@ public class Ini implements Map<String, 
                 addSection(sectionName, sectionContent);
 
                 //reset the buffer for the new section:
-                sectionContent = new StringBuilder();
+                sectionContent = new StringBuffer();
 
                 sectionName = newSectionName;
 
@@ -487,9 +472,16 @@ public class Ini implements Map<String, 
             this.props = new LinkedHashMap<String, String>();
         }
 
-        private Section(String name, Map<String, String> props) {
+        private Section(String name, Properties props) {
             this(name);
-            this.props.putAll(props);
+            Enumeration propNames = props.propertyNames();
+            while (propNames != null && propNames.hasMoreElements()) {
+                String key = propNames.nextElement().toString();
+                String value = props.getProperty(key);
+                if (value != null) {
+                    this.props.put(key, value.trim());
+                }
+            }
         }
 
         private Section(Section defaults) {

Modified: shiro/trunk/core/src/test/java/org/apache/shiro/config/IniTest.java
URL: http://svn.apache.org/viewvc/shiro/trunk/core/src/test/java/org/apache/shiro/config/IniTest.java?rev=1006221&r1=1006220&r2=1006221&view=diff
==============================================================================
--- shiro/trunk/core/src/test/java/org/apache/shiro/config/IniTest.java (original)
+++ shiro/trunk/core/src/test/java/org/apache/shiro/config/IniTest.java Sat Oct  9 19:37:01
2010
@@ -67,8 +67,8 @@ public class IniTest {
                 "prop2   value2" + NL +
                 "prop3:value3" + NL +
                 "prop4 : value 4" + NL +
-                //"prop5 some long \\" + NL +
-                //"      value " + NL +
+                "prop5 some long \\" + NL +
+                "      value " + NL +
                 "# comment.";
 
         Ini ini = new Ini();
@@ -80,11 +80,11 @@ public class IniTest {
         assertNotNull(section);
         assertEquals(sectionName, section.getName());
         assertFalse(section.isEmpty());
-        assertEquals(4, section.size());
+        assertEquals(5, section.size());
         assertEquals("value1", section.get("prop1"));
         assertEquals("value2", section.get("prop2"));
         assertEquals("value3", section.get("prop3"));
         assertEquals("value 4", section.get("prop4"));
-        //assertEquals("some long value", section.get("prop5"));
+        assertEquals("some long value", section.get("prop5"));
     }
 }



Mime
View raw message