: Class MailcapCommandMap

Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javax.activation
Class MailcapCommandMap

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

public class MailcapCommandMap
extends CommandMap

a comand map that represents the mailcap file. The mailcap file format is specified in RFC1524. Within the JAF it is used as an easy way to specify beans that perform certain operations on data of a particular MIME content type.

For example, the following mailcap file specifies 2 beans that perform different operations on the `text/html` MIME type and a bean that displays JPEG images:

       text/html; ; x-java-edit=gnu.inet.mime.html.HTMLBrowser
       text/&asterisk; ;  \
    	       x-java-print=gnu.inet.mime.xml.DocPrinter
       image/jpeg; jpegviewercprog %s \
                 ; x-java-view=gnu.inet.mime.JPEGViewer

This class provides a way to access the registry of information that is declared in such a mailcap file.

mailcap commands that do not begin with `x-java-` are ignored. The special command: `x-java-content-handler` causes this class to intepret the command as a `DataContentHandler`. There is a special method for obtaining the content handler for a particular MIME type. Other methods provide various ways of accessing the command registry for a particular MIME type.

#### Command line testing

Running this class from the command line and supplying a content type will cause the preferred commands for the content type to be printed on the console.

Version:
  $Revision: 1.9 $
Author:
  Andrew Selkirk: aselkirk@mailandnews.com, Nic Ferrier: nferrier@tapsellferrier.co.uk

Constructor Summary
`MailcapCommandMap()` create default MIME Types registry.
`MailcapCommandMap(java.io.InputStream stream)` create mailcap command map with entries from stream.
`MailcapCommandMap(java.lang.String fileName)` create mailcap command map with entries from file.

Method Summary
`void` | `addMailcap(java.lang.String mailCapEntry)` programmically add a mailcap entry.
`DataContentHandler` | `createDataContentHandler(java.lang.String mimeType)` create a content handler for the specified MIME type.
`CommandInfo[]` | `getAllCommands(java.lang.String mimeType)` get the list of all commands based on MIME type.
`CommandInfo` | `getCommand(java.lang.String mimeType, java.lang.String cmdName)` get command info for the specified MIME type and command name.
`CommandInfo[]` | `getPreferredCommands(java.lang.String mimeType)` get list of preferred commands based on MIME type.
`static void` | `main(java.lang.String[] argv)` With an argument of a content-type lists the preferred commands.

Methods inherited from class javax.activation.CommandMap
`getDefaultCommandMap, setDefaultCommandMap`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### MailcapCommandMap

    public MailcapCommandMap()

  create default MIME Types registry.

### MailcapCommandMap

    public MailcapCommandMap(java.lang.String fileName)
                      throws java.io.IOException

  create mailcap command map with entries from file.
  Parameters:
    `fileName` - Name of file to read
  Throws:
    `java.io.IOException` - IO exception occurred

### MailcapCommandMap

    public MailcapCommandMap(java.io.InputStream stream)

  create mailcap command map with entries from stream.
  Parameters:
    `stream` - Input stream of mailcap formatted entries

Method Detail

### addMailcap

    public void addMailcap(java.lang.String mailCapEntry)

  programmically add a mailcap entry. Mailcap entries added in this way achieve the highest preference for the search commands.
  Parameters:
    `mailCapEntry` - Mailcap formatted entry

### createDataContentHandler

    public DataContentHandler createDataContentHandler(java.lang.String mimeType)

  create a content handler for the specified MIME type. The database of registrys is searched and the most preferential content handler (commands with the name: `content-handler`) is returned.
  Overrides:
    `createDataContentHandler` in class `CommandMap`
  Parameters:
    `mimeType` - the MIME type to find a content handler for
  Returns:
    the content handler

### getAllCommands

    public CommandInfo[] getAllCommands(java.lang.String mimeType)

  get the list of all commands based on MIME type. The commands in all the registries of the mailcap database are searched.

  #### MIME type matching

  The specified mime type matches against all the registry entries where the mime type match exactly and also wildcard cases. For example `text/html` matches against:
  - text/html
  - text/&asterisk;
  Overrides:
    `getAllCommands` in class `CommandMap`
  Parameters:
    `mimeType` - MIME type to search for
  Returns:
    command information associated with the mime type

### getCommand

    public CommandInfo getCommand(java.lang.String mimeType,
                                  java.lang.String cmdName)

  get command info for the specified MIME type and command name. The search for the command is done by order of preference.
  Overrides:
    `getCommand` in class `CommandMap`
  Parameters:
    `mimeType` - MIME type to search for
    `cmdName` - Command name to check
  Returns:
    Command information, or null

### getPreferredCommands

    public CommandInfo[] getPreferredCommands(java.lang.String mimeType)

  get list of preferred commands based on MIME type. The registry is searched for a mailcap entry assigned to the specified MIME type. ALL the commands that match the particular MIME type are returned but each command type is only returned once. Thus, if two mailcap files specify the same command for a bean then only the command from the registry with the greater preference will appear in the resulting list. But if two mailcap files specify different commands for a particular MIME type then both commands will be returned from this method.
  Overrides:
    `getPreferredCommands` in class `CommandMap`
  Parameters:
    `mimeType` - MIME type to search for
  Returns:
    listing of preferred command information

### main

    public static void main(java.lang.String[] argv)

  With an argument of a content-type lists the preferred commands.
  Parameters:
    `argv` - Command-lline arguments

Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

© Copyright 2002 the Free Software Foundation, all rights reserved.