KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > MCTest


1 /*
2  * @(#)MCTest.java 1.6 99/12/06
3  *
4  * Copyright 1997-1999 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * This software is the proprietary information of Sun Microsystems, Inc.
7  * Use is subject to license terms.
8  *
9  */

10 import java.io.*;
11 import java.beans.*;
12 import com.sun.activation.registries.*;
13 import javax.activation.*;
14
15 public class MCTest {
16     MailcapCommandMap mcf = null;
17     String JavaDoc file_name = null;
18
19     public static void main(String JavaDoc args[]){
20     MCTest test = new MCTest();
21     
22     if(args.length == 0) {
23             System.out.println("usage: MCTest mailcap");
24             System.exit(1);
25         }
26
27     test.setFile(args[0]);
28
29     test.doit();
30
31     }
32
33     private void setFile(String JavaDoc fname) {
34        file_name = fname;
35     }
36
37     private void doit() {
38
39     try {
40         mcf = new MailcapCommandMap(file_name);
41     } catch (Exception JavaDoc e){
42         e.printStackTrace();
43         System.exit(1);
44     }
45
46     CommandInfo cmdinfo[] = mcf.getAllCommands("text/plain");
47         System.out.print("Are there any commands for text/plain?");
48     
49     if(cmdinfo != null) {
50         System.out.println("number of cmds = " + cmdinfo.length);
51         System.out.println("now try an individual cmd");
52         CommandInfo info = mcf.getCommand("text/plain", "view");
53         if(info != null) {
54         System.out.println("Got command...");
55         }
56         else
57         System.out.println("no cmds");
58         // System.out.print("Add another command");
59

60         mcf.addMailcap("text/plain;; x-java-flobotz=com.sun.activation.flobotz\n");
61         // System.out.println("...dome");
62
if(cmdinfo != null) {
63         cmdinfo = mcf.getAllCommands("text/plain");
64         System.out.println("now we have cmds = " + cmdinfo.length);
65         
66         }
67
68         } else {
69         System.out.println("NO CMDS AT ALL!");
70     }
71     
72     }
73     
74 }
75
Popular Tags