- java.lang.Object
-
- javax.activation.CommandMap
-
- javax.activation.MailcapCommandMap
-
public class MailcapCommandMap extends CommandMap
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:
- Programatically added entries to the MailcapCommandMap instance.
- The file
.mailcap
in the user's home directory. - The file <java.home>
/lib/mailcap
. - The file or resources named
META-INF/mailcap
. - The file or resource named
META-INF/mailcap.default
(usually found only in theactivation.jar
file).
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 formx-java-<name>
are read by the MailcapCommandMap as identifying a command with the name name. When the name iscontent-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 betrue
orfalse
. An entry for a MIME type that includes a parameter ofx-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 formtext/*; ; 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
- Since:
- 1.6
-
-
Constructor Summary
Constructors Constructor and Description MailcapCommandMap()
The default Constructor.MailcapCommandMap(InputStream is)
Constructor that allows the caller to specify an InputStream containing a mailcap file.MailcapCommandMap(String fileName)
Constructor that allows the caller to specify the path of a mailcap file.
-
Method Summary
Methods Modifier and Type Method and Description void
addMailcap(String mail_cap)
Add entries to the registry.DataContentHandler
createDataContentHandler(String mimeType)
Return the DataContentHandler for the specified MIME type.CommandInfo[]
getAllCommands(String mimeType)
Get all the available commands in all mailcap files known to this instance of MailcapCommandMap for this MIME type.CommandInfo
getCommand(String mimeType, String cmdName)
Get the command corresponding tocmdName
for the MIME type.String[]
getMimeTypes()
Get all the MIME types known to this command map.String[]
getNativeCommands(String mimeType)
Get the native commands for the given MIME type.CommandInfo[]
getPreferredCommands(String mimeType)
Get the preferred command list for a MIME Type.-
Methods inherited from class javax.activation.CommandMap
createDataContentHandler, getAllCommands, getCommand, getDefaultCommandMap, getPreferredCommands, setDefaultCommandMap
-
-
-
-
Constructor Detail
-
MailcapCommandMap
public MailcapCommandMap()
The default Constructor.
-
MailcapCommandMap
public MailcapCommandMap(String fileName) throws IOException
Constructor that allows the caller to specify the path of a mailcap file.- Parameters:
fileName
- The name of the mailcap file to open- Throws:
IOException
- if the file can't be accessed
-
MailcapCommandMap
public MailcapCommandMap(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(String mimeType)
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.
- Specified by:
getPreferredCommands
in classCommandMap
- Parameters:
mimeType
- the MIME type- Returns:
- the CommandInfo objects representing the preferred commands.
-
getAllCommands
public CommandInfo[] getAllCommands(String mimeType)
Get all the available commands in all mailcap files known to this instance of MailcapCommandMap for this MIME type.- Specified by:
getAllCommands
in classCommandMap
- Parameters:
mimeType
- the MIME type- Returns:
- the CommandInfo objects representing all the commands.
-
getCommand
public CommandInfo getCommand(String mimeType, String cmdName)
Get the command corresponding tocmdName
for the MIME type.- Specified by:
getCommand
in classCommandMap
- Parameters:
mimeType
- the MIME typecmdName
- the command name- Returns:
- the CommandInfo object corresponding to the command.
-
addMailcap
public 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
- a correctly formatted mailcap string
-
createDataContentHandler
public DataContentHandler createDataContentHandler(String mimeType)
Return the DataContentHandler for the specified MIME type.- Specified by:
createDataContentHandler
in classCommandMap
- Parameters:
mimeType
- the MIME type- Returns:
- the DataContentHandler
-
getMimeTypes
public String[] getMimeTypes()
Get all the MIME types known to this command map.- Overrides:
getMimeTypes
in classCommandMap
- Returns:
- array of MIME types as strings
- Since:
- JAF 1.1
-
getNativeCommands
public 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.- Returns:
- array of native command entries
- Since:
- JAF 1.1
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
21/11/2024 22:10:49 Cette version de la page est en cache (à la date du 21/11/2024 22:10:49) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 11/06/2005, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/activation/MailcapCommandMap.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.