FELIX-3335 Properly list filter mappings

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1239578 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpWhiteboardWebConsolePlugin.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpWhiteboardWebConsolePlugin.java
index 14a07d0..f5e56f7 100755
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpWhiteboardWebConsolePlugin.java
+++ b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpWhiteboardWebConsolePlugin.java
@@ -22,8 +22,10 @@
 import java.io.PrintWriter;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Comparator;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.TreeSet;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -131,7 +133,7 @@
         }
     }
 
-    private void printFilterMappings(PrintWriter pw, Map<String, FilterMapping> mappings)
+    private void printFilterMappings(PrintWriter pw, Set<FilterMapping> mappings)
     {
         pw.println("<tr>");
         pw.println("<th class='content container' colspan='4'>Registered Filter Services</td>");
@@ -143,7 +145,7 @@
         pw.println("<th class='content'>HttpContext</td>");
         pw.println("</tr>");
 
-        for (FilterMapping fm: mappings.values())
+        for (FilterMapping fm : mappings)
         {
             pw.println("<tr class='content'>");
             pw.println("<td class='content'>" + fm.getPattern() + "</td>");
@@ -228,10 +230,10 @@
         pw.println();
     }
 
-    private void printFilterMappingsTxt(PrintWriter pw, Map<String, FilterMapping> mappings)
+    private void printFilterMappingsTxt(PrintWriter pw, Set<FilterMapping> mappings)
     {
         pw.println("Registered Filter Services");
-        for (FilterMapping fm : mappings.values())
+        for (FilterMapping fm : mappings)
         {
             pw.printf("  %s ==> %s (%s, %s, %s, %s)%n", fm.getPattern(), fm.getFilter(),
                 fm.isRegistered() ? "registered" : "unregistered", fm.getRanking(), fm.getInitParams(), fm.getContext());
@@ -298,14 +300,40 @@
         return mappings;
     }
 
-    private Map<String, FilterMapping> getFilters()
+    private Set<FilterMapping> getFilters()
     {
-        Map<String, FilterMapping> mappings = new TreeMap<String, FilterMapping>();
+        Set<FilterMapping> mappings = new TreeSet<FilterMapping>(new Comparator<FilterMapping>()
+        {
+            public int compare(FilterMapping o1, FilterMapping o2)
+            {
+                if (o1 == o2)
+                {
+                    return 0;
+                }
+                int res = o1.getPattern().compareTo(o2.getPattern());
+                if (res == 0)
+                {
+                    if (o1.getRanking() > o2.getRanking())
+                    {
+                        res = -1;
+                    }
+                    else if (o1.getRanking() < o2.getRanking())
+                    {
+                        res = 1;
+                    }
+                    else
+                    {
+                        res = o1.getFilter().toString().compareTo(o2.getFilter().toString());
+                    }
+                }
+                return res;
+            }
+        });
         for (AbstractMapping mapping : this.extMgr.getMappings().values())
         {
             if (mapping instanceof FilterMapping)
             {
-                mappings.put(((FilterMapping) mapping).getPattern(), (FilterMapping) mapping);
+                mappings.add((FilterMapping) mapping);
             }
         }
         return mappings;