- java.lang.Object
- 
- jakarta.activation.CommandMap
- 
- jakarta.activation.MailcapCommandMap
 
 
- 
 public class MailcapCommandMap extends CommandMap MailcapCommandMap extends the CommandMap abstract class. It implements a CommandMap whose configuration is based on jakarta.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 jakarta.mailcap file entries. When requests are made to search for commands in the MailcapCommandMap, it searches jakarta.mailcap files in the following order: - Programatically added entries to the MailcapCommandMap instance.
-  The file .jakarta.mailcapin the user's home directory.
-  The file jakarta.mailcapin the Java runtime.
-  The file or resources named META-INF/jakarta.mailcap.
-  The file or resource named META-INF/jakarta.mailcap.default(usually found only in theactivation.jarfile).
 (The current implementation looks for the jakarta.mailcapfile in the Java runtime in the directoryjava.home/confif it exists, and otherwise in the directoryjava.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 jakarta.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 jakarta.mailcap files that allows JavaBeans(tm) components to be specified as corresponding to particular commands for a MIME type. When a jakarta.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 formx-java-<name>are read by the MailcapCommandMap as identifying a command with the name name. When the name iscontent-handlerthe 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 betrueorfalse. An entry for a MIME type that includes a parameter ofx-java-fallback-entry=truedefines 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 formtext/*; ; x-java-fallback-entry=true; x-java-view=com.sun.TextViewerspecifies 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 jakarta.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 jakarta.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 SummaryConstructors Constructor Description MailcapCommandMap()The default Constructor.MailcapCommandMap(java.io.InputStream is)Constructor that allows the caller to specify an InputStream containing a jakarta.mailcap file.MailcapCommandMap(java.lang.String fileName)Constructor that allows the caller to specify the path of a jakarta.mailcap file.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMailcap(java.lang.String mail_cap)Add entries to the registry.DataContentHandlercreateDataContentHandler(java.lang.String mimeType)Return the DataContentHandler for the specified MIME type.CommandInfo[]getAllCommands(java.lang.String mimeType)Get all the available commands in all jakarta.mailcap files known to this instance of MailcapCommandMap for this MIME type.CommandInfogetCommand(java.lang.String mimeType, java.lang.String cmdName)Get the command corresponding tocmdNamefor the MIME type.java.lang.String[]getMimeTypes()Get all the MIME types known to this command map.java.lang.String[]getNativeCommands(java.lang.String mimeType)Get the native commands for the given MIME type.CommandInfo[]getPreferredCommands(java.lang.String mimeType)Get the preferred command list for a MIME Type.- 
Methods inherited from class jakarta.activation.CommandMapcreateDataContentHandler, getAllCommands, getCommand, getDefaultCommandMap, getPreferredCommands, setDefaultCommandMap
 
- 
 
- 
- 
- 
Constructor Detail- 
MailcapCommandMappublic MailcapCommandMap() The default Constructor.
 - 
MailcapCommandMappublic MailcapCommandMap(java.lang.String fileName) throws java.io.IOExceptionConstructor that allows the caller to specify the path of a jakarta.mailcap file.- Parameters:
- fileName- The name of the jakarta.mailcap file to open
- Throws:
- java.io.IOException- if the file can't be accessed
 
 - 
MailcapCommandMappublic MailcapCommandMap(java.io.InputStream is) Constructor that allows the caller to specify an InputStream containing a jakarta.mailcap file.- Parameters:
- is- InputStream of the jakarta.mailcap file to open
 
 
- 
 - 
Method Detail- 
getPreferredCommandspublic CommandInfo[] getPreferredCommands(java.lang.String mimeType) Get the preferred command list for a MIME Type. The MailcapCommandMap searches the jakarta.mailcap files as described above under Mailcap file search order.The result of the search is a proper subset of available commands in all jakarta.mailcap files known to this instance of MailcapCommandMap. The first entry for a particular command is considered the preferred command. - Specified by:
- getPreferredCommandsin class- CommandMap
- Parameters:
- mimeType- the MIME type
- Returns:
- the CommandInfo objects representing the preferred commands.
 
 - 
getAllCommandspublic CommandInfo[] getAllCommands(java.lang.String mimeType) Get all the available commands in all jakarta.mailcap files known to this instance of MailcapCommandMap for this MIME type.- Specified by:
- getAllCommandsin class- CommandMap
- Parameters:
- mimeType- the MIME type
- Returns:
- the CommandInfo objects representing all the commands.
 
 - 
getCommandpublic CommandInfo getCommand(java.lang.String mimeType, java.lang.String cmdName) Get the command corresponding tocmdNamefor the MIME type.- Specified by:
- getCommandin class- CommandMap
- Parameters:
- mimeType- the MIME type
- cmdName- the command name
- Returns:
- the CommandInfo object corresponding to the command.
 
 - 
addMailcappublic void addMailcap(java.lang.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 jakarta.mailcap format. - Parameters:
- mail_cap- a correctly formatted jakarta.mailcap string
 
 - 
createDataContentHandlerpublic DataContentHandler createDataContentHandler(java.lang.String mimeType) Return the DataContentHandler for the specified MIME type.- Specified by:
- createDataContentHandlerin class- CommandMap
- Parameters:
- mimeType- the MIME type
- Returns:
- the DataContentHandler
 
 - 
getMimeTypespublic java.lang.String[] getMimeTypes() Get all the MIME types known to this command map.- Overrides:
- getMimeTypesin class- CommandMap
- Returns:
- array of MIME types as strings
- Since:
- JAF 1.1
 
 - 
getNativeCommandspublic java.lang.String[] getNativeCommands(java.lang.String mimeType) Get the native commands for the given MIME type. Returns an array of strings where each string is an entire jakarta.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 jakarta.mailcap entry syntax. Only jakarta.mailcap entries that specify a view command for the specified MIME type are returned.- Parameters:
- mimeType- the MIME type
- Returns:
- array of native command entries
- Since:
- JAF 1.1
 
 
- 
 
-