1 36 37 import javax.jnlp.BasicService; 38 import javax.jnlp.ServiceManager; 39 import javax.jnlp.UnavailableServiceException; 40 import java.io.*; 41 import java.net.*; 42 43 public class WebHandler { 44 45 46 static private BasicService _bs = null; 47 48 static public boolean isEnabled() { 49 return true; 50 } 51 52 static public void publish(String txt) { 53 URL url = getPublishURL(); 56 57 try { 58 URLConnection urlConn = url.openConnection(); 59 urlConn.setDoInput (true); 61 urlConn.setDoOutput (true); 63 urlConn.setUseCaches (false); 65 urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 67 68 DataOutputStream printout = new DataOutputStream (urlConn.getOutputStream()); 70 String content = "contents=" + URLEncoder.encode(txt); 71 printout.writeBytes(content); 72 printout.flush (); 73 printout.close (); 74 75 DataInputStream input = new DataInputStream (urlConn.getInputStream ()); 77 String str; 78 while (null != ((str = input.readLine()))) { 79 System.out.println (str); 80 } 81 input.close (); 82 } catch(IOException ioe) { 83 ioe.printStackTrace(System.out); 84 } 85 }; 86 87 static public void show() { 88 initialize(); 89 _bs.showDocument(getPublishURL()); 90 }; 91 92 static private URL getPublishURL() { 93 String location = System.getProperty("jnlp.publish-url"); 94 System.out.println(location); 95 try { 96 return new URL(location); 97 } catch(MalformedURLException mue) { 98 mue.printStackTrace(System.out); 99 return null; 100 } 101 } 102 103 static private synchronized void initialize() { 104 if (_bs != null) return; 105 try { 106 _bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService"); 107 } catch(UnavailableServiceException e) { 108 _bs = null; 109 } 110 } 111 } 112 | Popular Tags |