Java/JDK 6/Activation Framework
Версия от 18:01, 31 мая 2010; (обсуждение)
MailcapCommandMap Demo
import javax.activation.rumandInfo;
import javax.activation.MailcapCommandMap;
public class MailcapCommandMapDemo2 {
public static void main(String[] args) {
MailcapCommandMap mailcapCommandMap = new MailcapCommandMap();
String mailcap = "text/plain;; " + "x-java-content-handler=beans.TextHandler;"
+ "x-java-view=beans.TextViewer;" + "x-java-edit=beans.TextEditor";
mailcapCommandMap.addMailcap(mailcap);
// Get all MIME types
String[] mimeTypes = mailcapCommandMap.getMimeTypes();
for (String mimeType : mimeTypes) {
System.out.println(mimeType);
CommandInfo[] commandInfos = mailcapCommandMap.getAllCommands(mimeType);
for (CommandInfo info : commandInfos) {
System.out.println(" " + info.getCommandName() + " : "
+ info.getCommandClass());
}
}
}
}
/*text/plain
content-handler : beans.TextHandler
view : beans.TextViewer
edit : beans.TextEditor
view : com.sun.activation.viewers.TextViewer
edit : com.sun.activation.viewers.TextEditor
image/jpeg
view : com.sun.activation.viewers.ImageViewer
image/gif
view : com.sun.activation.viewers.ImageViewer
text/*
view : com.sun.activation.viewers.TextViewer
edit : com.sun.activation.viewers.TextEditor
*/
Using activation framework
import javax.activation.rumandInfo;
import javax.activation.MailcapCommandMap;
public class MailcapCommandMapDemo1 {
public static void main(String[] args) {
MailcapCommandMap mailcapCommandMap = new MailcapCommandMap();
String[] mimeTypes = mailcapCommandMap.getMimeTypes();
for (String mimeType : mimeTypes) {
System.out.println(mimeType);
CommandInfo[] commandInfos = mailcapCommandMap.getAllCommands(mimeType);
for (CommandInfo info : commandInfos) {
System.out.println(" " + info.getCommandName() + " : "
+ info.getCommandClass());
}
}
}
}
/*image/jpeg
view : com.sun.activation.viewers.ImageViewer
image/gif
view : com.sun.activation.viewers.ImageViewer
text/*
view : com.sun.activation.viewers.TextViewer
edit : com.sun.activation.viewers.TextEditor
*/