1 16 23 24 package com.psibt.framework.net; 25 32 public class UserDialogRequestHandler extends RootRequestHandler { 33 34 private Component parentComponent; 35 36 39 public UserDialogRequestHandler() { 40 this(null); 41 } 42 43 46 public UserDialogRequestHandler(Component parentComponent) { 47 this.setTitle("user dialog"); 48 this.setDescription("show user dialog"); 49 this.setHandledPath("/userdialog/"); 50 this.parentComponent = parentComponent; 51 } 52 53 60 public boolean handleRequest(String request, Writer out) { 61 String path = ""; 62 String query = null; 63 try { 64 URL url = new URL("http://localhost"+request); 65 path = url.getPath(); 66 query = url.getQuery(); 67 if (path.startsWith(this.getHandledPath()) == false) { 68 return false; 69 } 70 71 out.write("HTTP/1.0 200 OK\r\n"); 72 out.write("Content-type: text/html\r\n\r\n"); 73 out.write("<HTML><HEAD><TITLE>" + this.getTitle() + "</TITLE></HEAD>\r\n"); 74 out.write("<BODY><H1>" + this.getDescription() + "</H1>\r\n"); 75 if ((query != null) && (query.length() >= 0)) { 76 int idx = query.indexOf("="); 77 String message = query.substring(idx+1, query.length()); 78 message = message.replace('+', ' '); 80 idx = message.indexOf("%"); 82 while (idx >= 0) { 83 String sl = message.substring(0, idx); 84 String sm = message.substring(idx+1, idx+3); 85 String sr = message.substring(idx+3, message.length()); 86 try { 87 int i = Integer.parseInt(sm, 16); 88 sm = String.valueOf((char)i); 89 } 90 catch (Exception ex) { 91 sm = ""; 92 } 93 message = sl + sm + sr; 94 idx = message.indexOf("%"); 95 } 96 if ((message != null) && (message.length() > 0)) { 98 Thread t = new Thread (new DialogThread(parentComponent, message)); 99 t.start(); 100 } 101 } 102 out.write("<form name=\"Formular\" ACTION=\""+this.getHandledPath()+"+\" METHOD=\"PUT\">"); 103 out.write("<table>\r\n"); 104 out.write(" <tr><td>Send message to user</td></tr>\r\n"); 105 out.write(" <tr><td><textarea name=\"message\" rows=10 cols=50></textarea></td></tr>\r\n"); 106 out.write("</table>\r\n"); 107 out.write("<input type=submit value=\"Submit\">"); 108 out.write("</form>"); 109 out.write("</BODY></HTML>\r\n"); 110 out.flush(); 111 return true; 112 } catch (Exception ex) { 113 return false; 114 } 115 } 116 117 121 class DialogThread implements Runnable { 122 private Component parentComponent; 123 private String message; 124 125 public DialogThread(Component parentComponent, String message) { 126 this.parentComponent = parentComponent; 127 this.message = message; 128 } 129 130 public void run() { 131 JOptionPane.showMessageDialog(parentComponent, message); 132 } 133 } 134 } | Popular Tags |