Top Description Fields Constructors Methods
javax.activation

public Class MailcapCommandMap

extends CommandMap
Class Inheritance
Imports
java.util.*, java.io.*, java.net.*, java.security.AccessController, .PrivilegedAction, com.sun.activation.registries.MailcapFile, .LogSupport

MailcapCommandMap extends the CommandMap abstract class. It implements a CommandMap whose 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 file .mailcap in the user's home directory.
  3. The file mailcap in the Java runtime.
  4. The file or resources named META-INF/mailcap.
  5. The file or resource named META-INF/mailcap.default (usually found only in the activation.jar file).

(The current implementation looks for the mailcap file in the Java runtime in the directory java.home/conf if it exists, and otherwise in the directory java.home/lib, where java.home is the value of the "java.home" System property. Note that the "conf" directory was introduced in JDK 9.)

Mailcap file format:

Mailcap files must conform to the mailcap file specification (RFC 1524, A User Agent Configuration Mechanism For Multimedia Mail Format Information). The 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) components 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) component. For example; a command for viewing some data can be specified as: x-java-view=com.foo.ViewBean.

When the command name is fallback-entry, the value of the command may be true or false. An entry for a MIME type that includes a parameter of x-java-fallback-entry=true defines fallback commands for that MIME type that will only be used if no non-fallback entry can be found. For example, an entry of the form text/*; ; x-java-fallback-entry=true; x-java-view=com.sun.TextViewer specifies a view command to be used for any text MIME type. This view command would only be used if a non-fallback view command for the MIME type could not be found.

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

Authors
Bart Calder, Bill Shannon

Field Summary

Modifier and TypeField and Description
private static final String
private MailcapFile[]
private static final int

Constructor Summary

AccessConstructor and Description
public
MailcapCommandMap()

The default Constructor.

public
MailcapCommandMap(String
The name of the mailcap file to open
fileName
)

Constructor that allows the caller to specify the path of a mailcap file.

public
MailcapCommandMap(InputStream
InputStream of the mailcap file to open
is
)

Constructor that allows the caller to specify an InputStream containing a mailcap file.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addMailcap(String
a correctly formatted mailcap string
mail_cap
)

Add entries to the registry.

private void
appendCmdsToList(Map<K, V> typeHash, List<E> cmdList)

Put the commands that are in the hash table, into the list.

private void
appendPrefCmdsToList(Map<K, V> cmdHash, List<E> cmdList)

Put the commands that are in the hash table, into the list.

private boolean
checkForVerb(List<E> cmdList, String verb)

Check the cmdList to see if this command exists, return true if the verb is there.

public synchronized DataContentHandler

Returns:

the DataContentHandler
createDataContentHandler
(String
the MIME type
mimeType
)

Implements abstract javax.activation.CommandMap.createDataContentHandler.

Return the DataContentHandler for the specified MIME type.
public synchronized CommandInfo[]

Returns:

the CommandInfo objects representing all the commands.
getAllCommands
(String
the MIME type
mimeType
)

Implements abstract javax.activation.CommandMap.getAllCommands.

Get all the available commands in all mailcap files known to this instance of MailcapCommandMap for this MIME type.
public synchronized CommandInfo

Returns:

the CommandInfo object corresponding to the command.
getCommand
(String
the MIME type
mimeType
,
String
the command name
cmdName
)

Implements abstract javax.activation.CommandMap.getCommand.

Get the command corresponding to cmdName for the MIME type.
private DataContentHandler
public synchronized String[]

Returns:

array of MIME types as strings
getMimeTypes
()

Overrides javax.activation.CommandMap.getMimeTypes.

Get all the MIME types known to this command map.
public synchronized String[]

Returns:

array of native command entries
getNativeCommands
(String
the MIME type
mimeType
)

Get the native commands for the given MIME type.

public synchronized CommandInfo[]

Returns:

the CommandInfo objects representing the preferred commands.
getPreferredCommands
(String
the MIME type
mimeType
)

Implements abstract javax.activation.CommandMap.getPreferredCommands.

Get the preferred command list for a MIME Type.
private void
loadAllResources(List<E> v, String name)

Load all of the named resource.

private MailcapFile
loadFile(String name)

Load from the named file.

private MailcapFile
loadResource(String name)

Load from the named resource.

Inherited from javax.activation.CommandMap:
createDataContentHandlergetAllCommandsgetCommandgetDefaultCommandMapgetPreferredCommandssetDefaultCommandMap

Field Detail

confDirback to summary
private static final String confDir
DBback to summary
private MailcapFile[] DB
PROGback to summary
private static final int PROG

Constructor Detail

MailcapCommandMapback to summary
public MailcapCommandMap()

The default Constructor.

MailcapCommandMapback to summary
public MailcapCommandMap(String fileName) throws IOException

Constructor that allows the caller to specify the path of a mailcap file.

Parameters
fileName:String

The name of the mailcap file to open

Exceptions
IOException:
if the file can't be accessed
MailcapCommandMapback to summary
public MailcapCommandMap(InputStream is)

Constructor that allows the caller to specify an InputStream containing a mailcap file.

Parameters
is:InputStream

InputStream of the mailcap file to open

Method Detail

addMailcapback to summary
public synchronized void addMailcap(String mail_cap)

Add entries to the registry. Programmatically added entries are searched before other entries.

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

Parameters
mail_cap:String

a correctly formatted mailcap string

appendCmdsToListback to summary
private void appendCmdsToList(Map<K, V> typeHash, List<E> cmdList)

Put the commands that are in the hash table, into the list.

appendPrefCmdsToListback to summary
private void appendPrefCmdsToList(Map<K, V> cmdHash, List<E> cmdList)

Put the commands that are in the hash table, into the list.

checkForVerbback to summary
private boolean checkForVerb(List<E> cmdList, String verb)

Check the cmdList to see if this command exists, return true if the verb is there.

createDataContentHandlerback to summary
public synchronized DataContentHandler createDataContentHandler(String mimeType)

Implements abstract javax.activation.CommandMap.createDataContentHandler.

Return the DataContentHandler for the specified MIME type.

Parameters
mimeType:String

the MIME type

Returns:DataContentHandler

the DataContentHandler

getAllCommandsback to summary
public synchronized CommandInfo[] getAllCommands(String mimeType)

Implements abstract javax.activation.CommandMap.getAllCommands.

Get all the available commands in all mailcap files known to this instance of MailcapCommandMap for this MIME type.

Parameters
mimeType:String

the MIME type

Returns:CommandInfo[]

the CommandInfo objects representing all the commands.

getCommandback to summary
public synchronized CommandInfo getCommand(String mimeType, String cmdName)

Implements abstract javax.activation.CommandMap.getCommand.

Get the command corresponding to cmdName for the MIME type.

Parameters
mimeType:String

the MIME type

cmdName:String

the command name

Returns:CommandInfo

the CommandInfo object corresponding to the command.

getDataContentHandlerback to summary
private DataContentHandler getDataContentHandler(String name)
getMimeTypesback to summary
public synchronized String[] getMimeTypes()

Overrides javax.activation.CommandMap.getMimeTypes.

Get all the MIME types known to this command map.

Returns:String[]

array of MIME types as strings

Since
JAF 1.1
getNativeCommandsback to summary
public synchronized String[] getNativeCommands(String mimeType)

Get the native commands for the given MIME type. Returns an array of strings where each string is an entire mailcap file entry. The application will need to parse the entry to extract the actual command as well as any attributes it needs. See RFC 1524 for details of the mailcap entry syntax. Only mailcap entries that specify a view command for the specified MIME type are returned.

Parameters
mimeType:String

the MIME type

Returns:String[]

array of native command entries

Since
JAF 1.1
getPreferredCommandsback to summary
public synchronized CommandInfo[] getPreferredCommands(String mimeType)

Implements abstract javax.activation.CommandMap.getPreferredCommands.

Get the preferred command list for a MIME Type. The MailcapCommandMap searches the mailcap files as described above under Mailcap file search order.

The result of the search is a proper subset of available commands in all mailcap files known to this instance of MailcapCommandMap. The first entry for a particular command is considered the preferred command.

Parameters
mimeType:String

the MIME type

Returns:CommandInfo[]

the CommandInfo objects representing the preferred commands.

loadAllResourcesback to summary
private void loadAllResources(List<E> v, String name)

Load all of the named resource.

loadFileback to summary
private MailcapFile loadFile(String name)

Load from the named file.

loadResourceback to summary
private MailcapFile loadResource(String name)

Load from the named resource.