felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r899374 - in /felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver: CapabilityImpl.java cs/SimpleFilter.java
Date Thu, 14 Jan 2010 19:41:34 GMT
Author: rickhall
Date: Thu Jan 14 19:41:33 2010
New Revision: 899374

URL: http://svn.apache.org/viewvc?rev=899374&view=rev
Log:
Make parsing more robust.

Modified:
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java
    felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/SimpleFilter.java

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java?rev=899374&r1=899373&r2=899374&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java
(original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java
Thu Jan 14 19:41:33 2010
@@ -133,6 +133,10 @@
 
     public String toString()
     {
+        if (m_module == null)
+        {
+            return m_attrs.toString();
+        }
         if (m_namespace.equals(Capability.PACKAGE_NAMESPACE))
         {
             return "[" + m_module + "] "

Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/SimpleFilter.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/SimpleFilter.java?rev=899374&r1=899373&r2=899374&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/SimpleFilter.java
(original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/cs/SimpleFilter.java
Thu Jan 14 19:41:33 2010
@@ -97,12 +97,14 @@
     {
         filter = filter.trim();
 
-        // Assume we have a value that is something like:
-        // (&(n1=v1)(n2=v2)(|(n3=v3)(n4=v4)))
-
-        // Find the first ending ')' variable delimiter, which
-        // will correspond to the first deepest nested variable
-        // placeholder.
+        if ((filter == null) || (filter.length() == 0))
+        {
+            throw new IllegalArgumentException("Null or empty filter.");
+        }
+        else if (filter.charAt(0) != '(')
+        {
+            throw new IllegalArgumentException("Missing opening parenthesis: " + filter);
+        }
 
         SimpleFilter sf = null;
         List stack = new ArrayList();
@@ -149,45 +151,62 @@
                 else if (!stack.isEmpty() && (stack.get(0) instanceof SimpleFilter))
                 {
                     ((List) ((SimpleFilter) stack.get(0)).m_value).add(
-                        SimpleFilter.subfilter(filter.substring(((Integer) top).intValue()
+ 1, i)));
+                        SimpleFilter.subfilter(filter, ((Integer) top).intValue() + 1, i));
                 }
                 else
                 {
-                    sf = SimpleFilter.subfilter(filter.substring(((Integer) top).intValue()
+ 1, i));
+                    sf = SimpleFilter.subfilter(filter, ((Integer) top).intValue() + 1, i);
                 }
             }
         }
+
+        if (sf == null)
+        {
+            throw new IllegalArgumentException("Missing closing parenthesis: " + filter);
+        }
+
         return sf;
     }
 
-    private static SimpleFilter subfilter(String subfilter)
+    private static SimpleFilter subfilter(String filter, int startIdx, int endIdx)
     {
         final String opChars = "=<>";
         String attr = null, value = null;
         int op = -1;
-        for (int i = 0; i < subfilter.length(); i++)
+        for (int i = 0; i < (endIdx - startIdx); i++)
         {
-            if (opChars.indexOf(subfilter.charAt(i)) >= 0)
+            if (opChars.indexOf(filter.charAt(startIdx + i)) >= 0)
             {
-                switch (subfilter.charAt(i))
+                switch (filter.charAt(startIdx + i))
                 {
                     case '=':
-                        attr = subfilter.substring(0, i);
+                        attr = filter.substring(startIdx, startIdx + i);
                         op = EQ;
-                        value = subfilter.substring(i + 1);
+                        value = filter.substring(startIdx + i + 1, endIdx);
                         break;
                     case '<':
-                        attr = subfilter.substring(0, i);
+                        if (filter.charAt(startIdx + i + 1) != '=')
+                        {
+                            throw new IllegalArgumentException(
+                                "Unknown operator: " + filter.substring(startIdx, endIdx));
+                        }
+                        attr = filter.substring(startIdx, startIdx + i);
                         op = LTE;
-                        value = subfilter.substring(i + 2);
+                        value = filter.substring(startIdx + i + 2, endIdx);
                         break;
                     case '>':
-                        attr = subfilter.substring(0, i);
+                        if (filter.charAt(startIdx + i + 1) != '=')
+                        {
+                            throw new IllegalArgumentException(
+                                "Unknown operator: " + filter.substring(startIdx, endIdx));
+                        }
+                        attr = filter.substring(startIdx, startIdx + i);
                         op = GTE;
-                        value = subfilter.substring(i + 2);
+                        value = filter.substring(startIdx + i + 2, endIdx);
                         break;
                     default:
-                        throw new IllegalArgumentException("Unknown operator: " + subfilter);
+                        throw new IllegalArgumentException(
+                            "Unknown operator: " + filter.substring(startIdx, endIdx));
                 }
                 break;
             }



Mime
View raw message