MailcapCommandMap (Java EE 5)

Java EE API


javax.activation Class MailcapCommandMap

java.lang.Object
  extended by javax.activation.CommandMap
      extended by javax.activation.MailcapCommandMap

public class MailcapCommandMap
extends CommandMap

Extends: CommandMap

MailcapCommandMap 扩展 CommandMap 抽象类。它实现配置基于 mailcap 文件 (RFC 1524) 的 CommandMap。可以以编程方式和通过配置文件的方式来配置 MailcapCommandMap。

mailcap 文件搜索顺序:

MailcapCommandMap 在用户系统的各个位置查找 mailcap 文件条目。当发出请求以搜索 MailcapCommandMap 中的命令时,它以下面的顺序搜索 mailcap 文件:

  1. 以编程方式添加到 MailcapCommandMap 实例的条目。
  2. 用户主目录中的 .mailcap 文件。
  3. <java.home>/lib/mailcap 文件。
  4. 名为 META-INF/mailcap 的文件或资源。
  5. 名为 META-INF/mailcap.default 的文件或资源(通常只存在于 activation.jar 文件中)。

mailcap 文件格式:

mailcap 文件必须符合 mailcap 文件规范 (RFC 1524, A User Agent Configuration Mechanism For Multimedia Mail Format Information)。文件格式由与特定 MIME 类型对应的条目组成。一般情况下,当客户机本身不能对指定的 MIME 类型进行操作时,该规范为其指定使用的应用程序。MailcapCommandMap 扩展了此规范,它在 mailcap 文件中使用一个参数机制,该机制允许指定 JavaBeans(tm) 组件对应于 MIME 类型的特定命令。

解析一个 mailcap 文件时,MailcapCommandMap 识别出某些参数签名,特别是以 x-java- 开头的参数名称。MailcapCommandMap 使用此签名查找命令条目,以将其包含到注册表。用名称 name 标识一个命令时,MailcapCommandMap 读取 x-java-<name> 形式的参数名称。当 namecontent-handler 时,MailcapCommandMap 将此参数所表示的类视为 DataContentHandler。所有其他命令的处理通常忽略其命令名。命令实现由 JavaBean(tm) 组件的一个完全限定类名指定。例如,查看某些数据的命令可以被指定为:x-java-view=com.foo.ViewBean

当命令名是 fallback-entry 时,命令的值可以为 truefalse。包含 x-java-fallback-entry=true 参数的 MIME 类型的条目定义了该 MIME 类型的回退 (fallback) 命令,只在找不到非回退条目的情况下才使用该命令。例如,形式为 text/*; ; x-java-fallback-entry=true; x-java-view=com.sun.TextViewer 的条目指定了用于任何文本 MIME 类型的查看命令。此查看命令只在找不到 MIME 类型的非回退查看命令的情况下使用。

支持 MailcapCommandMap 的 mailcap 文件的一般形式如下:

# 注释以 '#' 开头并延续到行的末尾。
<mime type>; ; <parameter list>
# 其中参数列表由一个或多个参数组成,
# 其中参数类似于:x-java-view=com.sun.TextViewer
# 参数列表类似于:
纯文本; ; x-java-view=com.sun.TextViewer; x-java-edit=com.sun.TextEdit
# 注意,不包含 'x-java' 参数的 mailcap 条目
# 和遵守 RFC 1524 的条目将被忽略:
image/gif; /usr/dt/bin/sdtimage %s

英文文档:

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 <java.home>/lib/mailcap.
  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).

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

Author:
Bart Calder, Bill Shannon

Constructor Summary
 
Method Summary
 void
 DataContentHandler
 CommandInfo[]
 CommandInfo
 String[]
 String[]
 CommandInfo[]
 
Methods inherited from class javax.activation.CommandMap
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public MailcapCommandMap()
默认的构造方法。
英文文档:

MailcapCommandMap

public MailcapCommandMap()
The default Constructor.


public MailcapCommandMap(String fileName) throws java.io.IOException
允许调用者指定 mailcap 文件路径的构造方法。
fileName 要打开的 mailcap 文件的名称
Throwsjava.io.IOException: 如果不能访问该文件
英文文档:

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


public MailcapCommandMap(java.io.InputStream is)
允许调用者指定一个包含 mailcap 文件的 InputStream 的构造方法。
is 要打开的 mailcap 文件的 InputStream
英文文档:

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

public CommandInfo[] getPreferredCommands(String mimeType)
获取 MIME 类型的首选命令列表。MailcapCommandMap 以如上所述的 mailcap 文件搜索顺序 来搜索 mailcap 文件。

搜索的结果是此 MailcapCommandMap 实例已知的所有 mailmap 文件中可用命令的适当子集。特定命令的第一个条目被视为首选命令。

mimeType MIME 类型
return 表示首选命令的 CommandInfo 对象。

英文文档:

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 class CommandMap
Parameters:
mimeType - the MIME type
Returns:
the CommandInfo objects representing the preferred commands.

public CommandInfo[] getAllCommands(String mimeType)
针对此 MIME 类型获取此 MailcapCommandMap 实例已知的所有 mailcap 文件中的所有可用命令。
mimeType MIME 类型
return 表示所有命令的 CommandInfo 对象
英文文档:

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 class CommandMap
Parameters:
mimeType - the MIME type
Returns:
the CommandInfo objects representing all the commands.

public CommandInfo getCommand(String mimeType, String cmdName)
针对 MIME 类型获取与 cmdName 对应的命令。
mimeType MIME 类型
cmdName 命令名
return 与命令对应的 CommandInfo 对象。
英文文档:

getCommand

public CommandInfo getCommand(String mimeType,
                              String cmdName)
Get the command corresponding to cmdName for the MIME type.

Specified by:
getCommand in class CommandMap
Parameters:
mimeType - the MIME type
cmdName - the command name
Returns:
the CommandInfo object corresponding to the command.

public void addMailcap(String mail_cap)
将条目添加到注册表。搜索其他条目之前,先搜索以编程方式添加的条目。

传入的字符串应该是 mailcap 格式。

mail_cap 已正确格式化的 mailcap 字符串

英文文档:

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

public DataContentHandler createDataContentHandler(String mimeType)
返回指定 MIME 类型的 DataContentHandler。
mimeType MIME 类型
return DataContentHandler
英文文档:

createDataContentHandler

public DataContentHandler createDataContentHandler(String mimeType)
Return the DataContentHandler for the specified MIME type.

Specified by:
createDataContentHandler in class CommandMap
Parameters:
mimeType - the MIME type
Returns:
the DataContentHandler

public String[] getMimeTypes()
获取此命令映射已知的所有 MIME 类型。
return 字符串形式的 MIME 类型数组
sinceJAF 1.1
英文文档:

getMimeTypes

public String[] getMimeTypes()
Get all the MIME types known to this command map.

Overrides:
getMimeTypes in class CommandMap
Returns:
array of MIME types as strings
Since:
JAF 1.1

public String[] getNativeCommands(String mimeType)
获取给定 MIME 类型的本地命令。返回一个字符串数组,其中每个字符串都是一个完整的 mailcap 文件条目。应用程序需要解析条目以提取实际命令以及它需要的所有属性。关于 mailcap 条目语法的详细信息,请参阅 RFC 1524。只返回为指定的 MIME 类型指定查看命令的 mailcap 条目。
return 本地命令条目数组
sinceJAF 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


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!