Get action map from Activation command map in Java

Description

The following code shows how to get action map from Activation command map.

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.

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. When you click a command, Windows Explorer invokes the appropriate application and pass the reference to the right-clicked file.

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

Example


import javax.activation.CommandInfo;
import javax.activation.MailcapCommandMap;
/*from   w  ww  . j a  v a  2  s . co m*/
public class Main {
  public static void main(String[] args) {
    MailcapCommandMap mailcapCommandMap = new MailcapCommandMap();

    String[] mimeTypes = mailcapCommandMap.getMimeTypes();
    System.out.println(mimeTypes.length);
    for (String mimeType : mimeTypes) {
      System.out.println(mimeType);
      CommandInfo[] commandInfos = mailcapCommandMap
          .getAllCommands(mimeType);
      for (CommandInfo info : commandInfos) {
        System.out.println(" " + info.getCommandName() + " : "
            + info.getCommandClass());
      }
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization