1 10 11 import java.io.*; 12 import javax.activation.*; 13 import java.awt.datatransfer.*; 14 15 public class ODCHTest { 16 private FileDataSource fds = null; 17 private DataHandler dh = null; 18 private DataContentHandlerFactory dchf = null; 19 private String str; 20 23 public static void main(String args[]) { 24 ODCHTest test = new ODCHTest(); 25 26 if(args.length != 0) { 27 System.out.println("usage: ODCHTest"); 28 System.exit(1); 29 } 30 31 33 34 test.doit(); 35 } 36 37 private void doit() { 38 DataFlavor xfer_flavors[]; 39 Object content = null; 40 41 str = new String ("This is a test"); 42 43 dh = new DataHandler(str, "text/plain"); 45 System.out.println("ODCHTest: DataHandler created with str & text/plain"); 46 47 dchf = new SimpleDCF("text/plain:PlainDCH\n"); 49 System.out.println("ODCHTest: Simple dchf created"); 50 51 dh.setDataContentHandlerFactory(dchf); 53 System.out.println("ODCHTest: DataContentHandlerFactory set in DataHandler"); 54 55 xfer_flavors = dh.getTransferDataFlavors(); 57 System.out.println("ODCHTest: dh.getTransferDF returned " + 58 xfer_flavors.length + " data flavors."); 59 60 try { 62 content = dh.getContent(); 63 } catch (Exception e) { e.printStackTrace(); } 64 65 if(content == null) 66 System.out.println("ODCHTest: no content to be had!!!"); 67 else { 68 System.out.println("ODCHTest: got content of the following type: " + 69 content.getClass().getName()); 70 if(content == str) 71 System.out.println("get content works"); 72 73 } 74 } 75 76 } 77 | Popular Tags |