Contents | Package | Class | Tree | Deprecated | Index | Help
PREV | NEXT SHOW LISTS | HIDE LISTS

Class javax.activation.MailcapCommandMap

java.lang.Object
    |
    +----javax.activation.CommandMap
            |
            +----javax.activation.MailcapCommandMap

public class MailcapCommandMap
extends CommandMap
The MailcapCommandMap implements the CommandMap abstract class. It implements a CommandMap where its configuration is based on mailcap files (RFC 1524). The MailcapCommandMap can be configured both programmatically and via configuration files.

Mailcap file search order:

The MailcapCommandMap looks in various places in the user's system for mailcap file entries. When requests are made to search for commands in the MailcapCommandMap, it searches mailcap files in the following order:

  1. Programatically added entries to the MailcapCommandMap instance.
  2. The mailcap file in the user's home directory.
  3. The mailcap file in the java.home's lib directory.
  4. The mailcap file in the resource "/META-INF/mailcap".
  5. The mailcap file in the resource "/META-INF/mailcap.default".

Mailcap file format:

Mailcap files must conform to the mailcap file (RFC 1524, A User Agent Configuration Mechanism For Multimedia Mail Format Information) specification. File format consists of entries corresponding to particular MIME types. In general, the specification specifies applications for clients to use when they themselves cannot operate on the specified MIME type. The MailcapCommandMap extends this specification by using a parameter mechanism in mailcap files that allows JavaBeans(tm) to be specified as corresponding to particular commands for a MIME type.

When a mailcap file is parsed, the MailcapCommandMap recognizes certain parameter signatures, specifically those parameter names that begin with x-java-. The MailcapCommandMap uses this signature to find command entries for inclusion into its registries. Parameter names with the form x-java-<name> are read by the MailcapCommandMap as identifying a command with the name name. When the name is content-handler the MailcapCommandMap recognizes the class signified by this parameter as a DataContentHandler. All other commands are handled generically regardless of command name. The command implementation is specified by a fully qualified class name of a JavaBean(tm). 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


Constructor Summary
 MailcapCommandMap()
The default Constructor.
 MailcapCommandMap(java.lang.String fileName)
Constructor that allows the caller to specify the path of a mailcap file.
 MailcapCommandMap(java.io.InputStream is)
Constructor that allows the caller to specify an InputStream containing a mailcap file.
 

Method Summary
void  addMailcap(java.lang.String mail_cap)
Add entries to the registry.
DataContentHandler  createDataContentHandler(java.lang.String mimeType)
Return the DataContentHandler that refers to the MIME type.
CommandInfo[]  getAllCommands(java.lang.String mimeType)
Get all the available commands in all mailcap files known to this instance of MailcapCommandMap for this type.
CommandInfo  getCommand(java.lang.String mimeType, java.lang.String cmdName)
Get the command corresponding to cmdName for the MIME type.
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, getPreferredCommands, setDefaultCommandMap
 
Methods inherited from class java.lang.Object
 clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MailcapCommandMap

public MailcapCommandMap()
The default Constructor.

MailcapCommandMap

public MailcapCommandMap(java.lang.String fileName) throws java.io.IOException
Constructor that allows the caller to specify the path of a mailcap file.
Parameters:
fileName - The name of the mailcap file to open

MailcapCommandMap

public MailcapCommandMap(java.io.InputStream is)
Constructor that allows the caller to specify an InputStream containing a mailcap file.
Parameters:
is - InputStream of the mailcap file to open
Method Detail

getPreferredCommands

public CommandInfo[] getPreferredCommands(java.lang.String mimeType)
Get the preferred command list from a MIME Type. The MailcapCommandMap iterates through the mailcap files described by the search order described in the MailcapCommandMap class description, under Mailcap File Search Order.

The net result of the search is a proper subset of available commands in all mailcap files known to this instance of MailcapCommandMap.

Returns:
the CommandInfo objects representing the preferred commands.
Overrides:
getPreferredCommands in class CommandMap

getAllCommands

public CommandInfo[] getAllCommands(java.lang.String mimeType)
Get all the available commands in all mailcap files known to this instance of MailcapCommandMap for this type.
Returns:
the CommandInfo objects representing all the commands.
Overrides:
getAllCommands in class CommandMap

getCommand

public CommandInfo getCommand(java.lang.String mimeType,
                              java.lang.String cmdName)
Get the command corresponding to cmdName for the MIME type.
Returns:
the CommandInfo object corresponding to the command.
Overrides:
getCommand in class CommandMap

addMailcap

public void addMailcap(java.lang.String mail_cap)
Add entries to the registry. Searches programatically added entries before any other entries.

The string that is passed in should be in mailcap format.

Parameters:
mail_cap - a correctly formatted mailcap string

createDataContentHandler

public DataContentHandler createDataContentHandler(java.lang.String mimeType)
Return the DataContentHandler that refers to the MIME type.
Overrides:
createDataContentHandler in class CommandMap

Contents | Package | Class | Tree | Deprecated | Index | Help
PREV | NEXT SHOW LISTS | HIDE LISTS