1 10 11 import java.io.*; 12 import javax.activation.*; 13 import java.awt.datatransfer.*; 14 15 public class DCHTest2 { 16 private FileDataSource fds = null; 17 private MailcapCommandMap cmdMap = null; 18 private DataHandler dh = null; 19 private DataContentHandlerFactory dchf = null; 20 23 public static void main(String args[]) { 24 DCHTest2 test = new DCHTest2(); 25 26 if(args.length < 2) { 27 System.out.println("usage: DCHTest2 file.txt mailcap"); 28 System.exit(1); 29 } 30 31 33 test.setFile(args[0]); 34 35 test.setMailcap(args[1]); 36 test.doit(); 37 } 38 39 private void doit() { 40 DataFlavor xfer_flavors[]; 41 Object content = null; 42 43 dh = new DataHandler(fds); 45 dh.setCommandMap(cmdMap); 46 System.out.println("DCHTest2: DataHandler created"); 47 48 xfer_flavors = dh.getTransferDataFlavors(); 50 System.out.println("DCHTest2: dh.getTransferDF returned " + 51 xfer_flavors.length + " data flavors."); 52 53 try { 55 content = dh.getContent(); 56 } catch (Exception e) { e.printStackTrace(); } 57 if(content == null) 58 System.out.println("DCHTest2: no content to be had!!!"); 59 else 60 System.out.println("DCHTest2: got content of the following type: " + 61 content.getClass().getName()); 62 63 } 64 65 68 public void setFile(String filename) { 69 fds = new FileDataSource(filename); 70 System.out.println("DCHTest2: FileDataSource created"); 71 if(!fds.getContentType().equals("text/plain")) { 72 System.out.println("Type must be text/plain"); 73 System.exit(1); 74 } 75 } 76 77 80 public void setMailcap(String mailcap) { 81 82 try { 83 cmdMap = new MailcapCommandMap(mailcap); 84 } catch(Exception e){ 85 e.printStackTrace(); 86 System.exit(1); 87 } 88 } 89 90 91 } 92 93 94 | Popular Tags |