Java Tutorial/Development/Activation Framework — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 15:30, 31 мая 2010

import javax.activation.CommandInfo;

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


Java activation framework

Probably the easiest way to understand the JAF is by looking at Windows Explorer.

Windows Explorer allows you to right-click on a file and select a command from the list associated with the file type.

The lists will differ from one computer to another.

When you click a command, Windows Explorer invokes the appropriate application and pass the reference to the right-clicked file.

You can use the JAF in a Java editor so that upon clicking a text file, the user will be presented with a command list and be able to select a command that will launch the application to handle the object.

You need to decide the supported types of objects and invoke appropriate JavaBeans that can handle each type of object.


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