geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r158800 - geronimo/trunk/specs/activation/src/java/javax/activation/MailcapCommandMap.java
Date Wed, 23 Mar 2005 17:12:50 GMT
Author: jboynes
Date: Wed Mar 23 09:12:48 2005
New Revision: 158800

URL: http://svn.apache.org/viewcvs?view=rev&rev=158800
Log:
support wildcarded preferred commands

Modified:
    geronimo/trunk/specs/activation/src/java/javax/activation/MailcapCommandMap.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=158799&r2=158800
==============================================================================
--- geronimo/trunk/specs/activation/src/java/javax/activation/MailcapCommandMap.java (original)
+++ geronimo/trunk/specs/activation/src/java/javax/activation/MailcapCommandMap.java Wed Mar
23 09:12:48 2005
@@ -31,6 +31,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Collections;
 
 /**
  * @version $Rev$ $Date$
@@ -260,17 +261,37 @@
     public synchronized CommandInfo[] getPreferredCommands(String mimeType) {
         Map commands = (Map) preferredCommands.get(mimeType.toLowerCase());
         if (commands == null) {
-            return null;
+            commands = (Map) preferredCommands.get(getWildcardMimeType(mimeType));
+        }
+        if (commands == null) {
+            return new CommandInfo[0];
         }
         return (CommandInfo[]) commands.values().toArray(new CommandInfo[commands.size()]);
     }
 
     public synchronized CommandInfo[] getAllCommands(String mimeType) {
-        List commands = (List) allCommands.get(mimeType.toLowerCase());
-        return (CommandInfo[]) commands.toArray(new CommandInfo[commands.size()]);
+        mimeType = mimeType.toLowerCase();
+        List exactCommands = (List) allCommands.get(mimeType);
+        if (exactCommands == null) {
+            exactCommands = Collections.EMPTY_LIST;
+        }
+        List wildCommands = (List) allCommands.get(getWildcardMimeType(mimeType));
+        if (wildCommands == null) {
+            wildCommands = Collections.EMPTY_LIST;
+        }
+        CommandInfo[] result = new CommandInfo[exactCommands.size() + wildCommands.size()];
+        int j = 0;
+        for (int i = 0; i < exactCommands.size(); i++) {
+            result[j++] = (CommandInfo) exactCommands.get(i);
+        }
+        for (int i = 0; i < wildCommands.size(); i++) {
+            result[j++] = (CommandInfo) wildCommands.get(i);
+        }
+        return result;
     }
 
     public synchronized CommandInfo getCommand(String mimeType, String cmdName) {
+        mimeType = mimeType.toLowerCase();
         // strip any parameters from the supplied mimeType
         int i = mimeType.indexOf(';');
         if (i != -1) {
@@ -280,18 +301,21 @@
         // search for an exact match
         Map commands = (Map) preferredCommands.get(mimeType.toLowerCase());
         if (commands == null) {
-            i = mimeType.indexOf('/');
-            if (i == -1) {
-                mimeType = mimeType + "/*";
-            } else {
-                mimeType = mimeType.substring(0, i + 1) + "*";
-            }
-            commands = (Map) preferredCommands.get(mimeType.toLowerCase());
+            commands = (Map) preferredCommands.get(getWildcardMimeType(mimeType));
         }
         if (commands == null) {
             return null;
         }
         return (CommandInfo) commands.get(cmdName.toLowerCase());
+    }
+
+    private String getWildcardMimeType(String mimeType) {
+        int i = mimeType.indexOf('/');
+        if (i == -1) {
+            return mimeType + "/*";
+        } else {
+            return mimeType.substring(0, i + 1) + "*";
+        }
     }
 
     public synchronized DataContentHandler createDataContentHandler(String mimeType) {



Mime
View raw message