geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r149311 - in geronimo/trunk/specs/activation: README-IMPORTANT-DEVELOPERS.txt src/java/javax/activation/MailcapCommandMap.java src/test/javax/activation/MailcapCommandMapTest.java
Date Mon, 31 Jan 2005 22:45:09 GMT
Author: jboynes
Date: Mon Jan 31 14:45:06 2005
New Revision: 149311

URL: http://svn.apache.org/viewcvs?view=rev&rev=149311
Log:
support wildcards a bit better

Removed:
    geronimo/trunk/specs/activation/README-IMPORTANT-DEVELOPERS.txt
Modified:
    geronimo/trunk/specs/activation/src/java/javax/activation/MailcapCommandMap.java
    geronimo/trunk/specs/activation/src/test/javax/activation/MailcapCommandMapTest.java

Modified: geronimo/trunk/specs/activation/src/java/javax/activation/MailcapCommandMap.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/java/javax/activation/MailcapCommandMap.java?view=diff&r1=149310&r2=149311
==============================================================================
--- geronimo/trunk/specs/activation/src/java/javax/activation/MailcapCommandMap.java (original)
+++ geronimo/trunk/specs/activation/src/java/javax/activation/MailcapCommandMap.java Mon Jan
31 14:45:06 2005
@@ -31,8 +31,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Collection;
-import java.util.Collections;
 
 /**
  * @version $Rev$ $Date$
@@ -273,14 +271,20 @@
     }
 
     public synchronized CommandInfo getCommand(String mimeType, String cmdName) {
-        HashMap commands = (HashMap) preferredCommands.get(mimeType.toLowerCase());
-        if(commands != null)
+        // search for an exact match
+        Map commands = (Map) preferredCommands.get(mimeType.toLowerCase());
+        if(commands != null) {
             return (CommandInfo) commands.get(cmdName.toLowerCase());
+        }
         int i = mimeType.indexOf('/');
-        String mimeType2 = mimeType.substring(0, i + 1) + "*";
-        HashMap commands2 = (HashMap) preferredCommands.get(mimeType2.toLowerCase());
-        if(commands2 != null)
-            return (CommandInfo) commands2.get(cmdName.toLowerCase());
+        if (i == -1) {
+            mimeType = mimeType + "/*";
+        } else {
+            mimeType = mimeType.substring(0, i + 1) + "*";
+        }
+        commands = (Map) preferredCommands.get(mimeType.toLowerCase());
+        if(commands != null)
+            return (CommandInfo) commands.get(cmdName.toLowerCase());
         return null;
     }
 

Modified: geronimo/trunk/specs/activation/src/test/javax/activation/MailcapCommandMapTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/specs/activation/src/test/javax/activation/MailcapCommandMapTest.java?view=diff&r1=149310&r2=149311
==============================================================================
--- geronimo/trunk/specs/activation/src/test/javax/activation/MailcapCommandMapTest.java (original)
+++ geronimo/trunk/specs/activation/src/test/javax/activation/MailcapCommandMapTest.java Mon
Jan 31 14:45:06 2005
@@ -40,9 +40,39 @@
         assertEquals("Bar", info.getCommandClass());
     }
 
+    public void testExplicitWildcard() {
+        map.addMailcap("foo/bar ;; x-java-view=Bar");
+        map.addMailcap("foo/* ;; x-java-view=Star");
+        CommandInfo info = map.getCommand("foo/bar", "view");
+        assertEquals("view", info.getCommandName());
+        assertEquals("Bar", info.getCommandClass());
+        info = map.getCommand("foo/foo", "view");
+        assertEquals("view", info.getCommandName());
+        assertEquals("Star", info.getCommandClass());
+        info = map.getCommand("foo/*", "view");
+        assertEquals("view", info.getCommandName());
+        assertEquals("Star", info.getCommandClass());
+        info = map.getCommand("foo", "view");
+        assertEquals("view", info.getCommandName());
+        assertEquals("Star", info.getCommandClass());
+    }
+
+    public void testImplicitWildcard() {
+        map.addMailcap("foo/bar ;; x-java-view=Bar");
+        map.addMailcap("foo ;; x-java-view=Star");
+        CommandInfo info = map.getCommand("foo/bar", "view");
+        assertEquals("view", info.getCommandName());
+        assertEquals("Bar", info.getCommandClass());
+        info = map.getCommand("foo/foo", "view");
+        assertEquals("view", info.getCommandName());
+        assertEquals("Star", info.getCommandClass());
+        info = map.getCommand("foo", "view");
+        assertEquals("view", info.getCommandName());
+        assertEquals("Star", info.getCommandClass());
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
         map = new MailcapCommandMap();
     }
-
 }



Mime
View raw message