Copyright 2012-02-25 Werner Randelshofer

ch.randelshofer.activation
Class BasicCommandMap

java.lang.Object
  extended by javax.activation.CommandMap
      extended by ch.randelshofer.activation.BasicCommandMap
Direct Known Subclasses:
HierarchicCommandMap

public class BasicCommandMap
extends javax.activation.CommandMap

This CommandMap supports multiple commands for the same MIME type.

Version:
1.3 2006-07-20 Reworked for Java 1.5.
1.2 2002-02-12 Return application/octet-stream' when data type can not be determined.
1.1.1 2002-02-05 Methods in class ch.randelshofer.util.Strings have been renamed.
1.1 2000-09-24 Method addCommands(Reader) added.
1.0 1999-10-19
Author:
Werner Randelshofer, Hausmatt 10, CH-6405 Immensee, Switzerland.

Constructor Summary
BasicCommandMap()
           
 
Method Summary
 void addCommand(java.lang.String mimeType, java.lang.String cmdVerb, java.lang.String cmdClass)
          Adds a command to the map.
 void addCommandInfo(java.lang.String mimeType, javax.activation.CommandInfo info)
          Adds a command info to the map.
 void addCommands(java.io.Reader in)
          Adds commands provided by the input stream to the map.
 javax.activation.DataContentHandler createDataContentHandler(java.lang.String mimeType)
          Locate a DataContentHandler that corresponds to the MIME type.
 javax.activation.CommandInfo[] getAllCommands(java.lang.String mimeType)
          Get all available commands for this type.
 javax.activation.CommandInfo getCommand(java.lang.String mimeType, java.lang.String cmdName)
          Get the default command corresponding to the MIME type.
 javax.activation.CommandInfo[] getPreferredCommands(java.lang.String mimeType)
          Get the preferred command list from a MIME type.
 
Methods inherited from class javax.activation.CommandMap
createDataContentHandler, getAllCommands, getCommand, getDefaultCommandMap, getMimeTypes, getPreferredCommands, setDefaultCommandMap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicCommandMap

public BasicCommandMap()
Method Detail

addCommand

public void addCommand(java.lang.String mimeType,
                       java.lang.String cmdVerb,
                       java.lang.String cmdClass)
Adds a command to the map.

Parameters:
mimeType - The MIME type of the command.
cmdVerb - The command verb.
cmdClass - The class name of the java bean that executes to verb.

addCommands

public void addCommands(java.io.Reader in)
                 throws java.io.IOException
Adds commands provided by the input stream to the map. The input stream must comply to the mailcap file format. When a mailcap file is parsed, the MailcapCommandMap recognizes certain parameter signatures, specifically those parameter names that beginw ith x-java-. The MailcapCommandMap uses this signature to find command entries for inclusion into its registries. Parameter names with the form x-java- are read by the MailcapCommandMap as identifying a command with the name name. The command implementation is specified by a fully qualified class name of a JavaBean(tm) component. For example; a command for viewing some data can be specified as: x-java-view=com.foo.ViewBean. MailcapCommandMap aware mailcap files have the following general form:

 # Comments begin with a '#' and continue to the end of the line.
<mime type>; ; <parameter list>
# Where a parameter list consists of one or more parameters,
# where parameters look like: x-java-view=com.sun.TextViewer
# and a parameter list looks like:
text/plain; ; x-java-view=com.sun.TextViewer; x-java-edit=com.sun.TextEdit
# Note that mailcap entries that do not contain 'x-java' parameters
# and comply to RFC 1524 are simply ignored:
image/gif; /usr/dt/bin/sdtimage %s

Parameters:
in - The Reader providing the commands.
Throws:
java.io.IOException

addCommandInfo

public void addCommandInfo(java.lang.String mimeType,
                           javax.activation.CommandInfo info)
Adds a command info to the map.

Parameters:
mimeType - The MIME type of the command.
info - A CommandInfo object representing the command.

getPreferredCommands

public javax.activation.CommandInfo[] getPreferredCommands(java.lang.String mimeType)
Get the preferred command list from a MIME type. If commands with the same command verb occur more than one time, then only the first command is returned.

Specified by:
getPreferredCommands in class javax.activation.CommandMap
Returns:
Returns the preferred commands for that MIME type.

getAllCommands

public javax.activation.CommandInfo[] getAllCommands(java.lang.String mimeType)
Get all available commands for this type.

Specified by:
getAllCommands in class javax.activation.CommandMap
Returns:
Returns all CommandInfo objects for the MIME type.

getCommand

public javax.activation.CommandInfo getCommand(java.lang.String mimeType,
                                               java.lang.String cmdName)
Get the default command corresponding to the MIME type.

Specified by:
getCommand in class javax.activation.CommandMap
Returns:
the CommandInfo corresponding to the command.

createDataContentHandler

public javax.activation.DataContentHandler createDataContentHandler(java.lang.String mimeType)
Locate a DataContentHandler that corresponds to the MIME type. The mechanism and semantics for determining this are determined by the implementation of the particular CommandMap.

Specified by:
createDataContentHandler in class javax.activation.CommandMap

Copyright 2012-02-25 Werner Randelshofer