1 package de.webman.generator.eventhandler; 2 3 import java.io.*; 4 import com.teamkonzept.international.LanguageManager; 5 6 14 public class GRHTMLWrapper extends PrintWriter 15 { 16 18 21 public static final String LINE_SEPARATOR = System.getProperty("line.separator"); 22 23 public static String HEADER_START = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\"><HTML><HEAD>"; 24 25 public static String HEADER_META = "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\"><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">"; 26 27 public static String HEADER_SCRIPT = "<SCRIPT LANGUAGE=\"JavaScript\">"+ LINE_SEPARATOR + "<!--" +LINE_SEPARATOR +"function omChangeImage(lala,FileName )" + LINE_SEPARATOR + "{ " + LINE_SEPARATOR + "document[lala].src = FileName;}" + LINE_SEPARATOR + "//--></SCRIPT>"; 28 29 public static String HEADER_STYLE = "<LINK HREF=\"<TK_APP_CONTEXT>/templates/style.css\" REL=\"stylesheet\" TYPE=\"text/css\"><STYLE TYPE=\"text/css\"><!--BODY {background-color :#336699;}--></STYLE>"; 30 31 public static String HEADER_TITLE_START = "<TITLE>"; 32 33 public static String HEADER_TITLE_END = "</TITLE>"; 34 35 public static String HEADER_END = "</HEAD>"; 36 37 public static String BODY_START = "<BODY onLoad=\"self.focus();\" TOPMARGIN=\"0\" LEFTMARGIN=\"0\" MARGINWIDTH=\"0\" MARGINHEIGHT=\"0\">"; 38 39 public static String DOCUMENT_PARTICLE_0 = 40 "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" + 41 "<tr>" + 42 "<td width=\"220\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" + 43 "<tr>" + 44 "<td class=\"mblau\" width=\"22\"><A HREF=\"<TK_APP_CONTEXT>/servlet/WebManServlet\" target=\"_top\"" + 45 " onmouseover=\"omChangeImage('start', '<TK_APP_CONTEXT>/templates/images/go_start_on.gif')\"" + 46 " onmouseout=\"omChangeImage('start', '<TK_APP_CONTEXT>/templates/images/go_start_off.gif')\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/go_start_off.gif\" width=\"22\" height=\"42\" border=\"0\" alt=\"\" name=\"start\"></a></td>" + 47 "<td width=\"1\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"1\" height=\"42\" border=\"0\" alt=\"\"></td>" + 48 "<td class=\"btitel\" width=\"196\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/i_generator.gif\" width=\"38\" height=\"34\" border=\"0\" alt=\"\">"; 49 50 public static String DOCUMENT_PARTICLE_1 = 51 "<br>" + 52 "<img SRC=\"<TK_APP_CONTEXT>/templates/images/mblau.gif\" width=\"195\" height=\"1\" border=\"0\" alt=\"\"></td>" + 53 "<td width=\"1\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"1\" height=\"42\" border=\"0\" alt=\"\"></td>" + 54 "</tr>" + 55 "</table></td>" + 56 "<td class=\"weiss\" valign=\"top\" width=\"275\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" + 57 "<tr>" + 58 "<td class=\"dgrau\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/dgrau.gif\" width=\"19\" height=\"18\" border=\"0\" alt=\"\"></td>" + 59 "<td class=\"dgrau\">angemeldet als:</td>" + 60 "<td class=\"weiss\"> </td>" + 61 "</tr>" + 62 "<tr>" + 63 "<td class=\"l\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"19\" height=\"1\" border=\"0\" alt=\"\"></td>" + 64 "<td class=\"l\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"210\" height=\"1\" border=\"0\" alt=\"\"></td>" + 65 "<td class=\"l\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"46\" height=\"1\" border=\"0\" alt=\"\"></td>" + 66 "</tr>" + 67 "<tr>" + 68 "<td class=\"hgrau\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/hgrau.gif\" width=\"19\" height=\"23\" border=\"0\" alt=\"\"></td>" + 69 "<td class=\"hgrau\">"; 70 71 public static String DOCUMENT_PARTICLE_2 = 72 "</td>" + 73 "<td class=\"weiss\"> </td>" + 74 "</tr>" + 75 "</table></td>" + 76 "<td class=\"weiss\" align=\"right\" valign=\"top\" width=\"100%\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" + 77 "<tr><td width=\"100%\"> </td>" + 78 "<td><a HREF=\"http://www.webman.de\" target=\"_blank\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/logo.gif\" width=\"165\" height=\"42\"" + 79 "border=\"0\" alt=\" At your side. For your site. \"></a></td>" + 80 "<td valign=\"bottom\" class=\"version\">" + 81 getVersion() + 82 "<br><img SRC=\"<TK_APP_CONTEXT>/templates/images/weiss.gif\" width=\"10\" height=\"3\" border=\"0\" alt=\"\"></td>" + 83 "<td><img SRC=\"<TK_APP_CONTEXT>/templates/images/weiss.gif\" width=\"23\" height=\"1\" border=\"0\" alt=\"\"></td>" + 84 "</tr></table></td>" + 85 "</tr>" + 86 "</table>" + LINE_SEPARATOR + 87 "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" + 88 "<tr>" + 89 "<td class=\"l\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"22\" height=\"1\" border=\"0\" alt=\"\"></td>" + 90 "<td class=\"l\" width=\"1\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>" + 91 "<td class=\"l\" width=\"100%\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>" + 92 "</tr>" + 93 "<tr>" + 94 "<td class=\"dblau\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/dblau.gif\" width=\"22\" height=\"6\" border=\"0\" alt=\"\"></td>" + 95 "<td class=\"mblau\" width=\"1\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"1\" height=\"6\" border=\"0\" alt=\"\"></td>" + 96 "<td class=\"mblau\" width=\"100%\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/mblau.gif\" width=\"400\" height=\"6\" border=\"0\" alt=\"\"></td>" + 97 "</tr>" + 98 "<tr>" + 99 "<td class=\"l\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>" + 100 "<td class=\"l\" width=\"1\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>" + 101 "<td class=\"l\" width=\"100%\"\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"400\" height=\"1\" border=\"0\" alt=\"\"></td>" + 102 "</tr>" + 103 "</table>"; 104 105 public static String TABLE_START = 106 "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" + 107 "<tr>" + 108 "<td class=\"mblau\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/mblau.gif\" width=\"22\" height=\"1\" border=\"0\" alt=\"\"></td>" + 109 "<td class=\"l\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>" + 110 "<td class=\"mblau\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/mblau.gif\" width=\"78\" height=\"6\" border=\"0\" alt=\"\"></td>"; 111 112 public static String TABLE_END = "</tr></table>"; 113 114 public static String BODY_END = "</BODY></HTML>"; 115 116 public static String LINE_STANDARD = "<td class=\"start\">"; 117 118 public static String LINE_SUCCESS = "<td class=\"number\">"; 119 120 public static String LINE_FAILURE = "<td class=\"warning\">"; 121 122 public static String PARAGRAPH_EMPTY = 123 "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" + 124 "<tr>" + 125 "<td class=\"mblau\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/mblau.gif\" width=\"22\" height=\"1\" border=\"0\" alt=\"\"></td>" + 126 "<td class=\"l\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>" + 127 "<td class=\"mblau\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/mblau.gif\" width=\"78\" height=\"6\" border=\"0\" alt=\"\"></td>" + 128 "<td class=\"mblau\">" + 129 "<p> </p>" + 130 "</tr>" + 131 "</table>"; 132 133 public static String PARAGRAPH_LINE = 134 "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" + 135 "<tr>" + 136 "<td class=\"l\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"22\" height=\"1\" border=\"0\" alt=\"\"></td>" + 137 "<td class=\"l\" width=\"1\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>" + 138 "<td class=\"l\" width=\"100%\"><img SRC=\"<TK_APP_CONTEXT>/templates/images/line.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"\"></td>" + 139 "</tr>" + 140 "</table>"; 141 142 private static String TK_APP_CONTEXT = "<TK_APP_CONTEXT>"; 143 144 145 147 150 private boolean open = false; 151 152 155 private PrintWriter writer = null; 156 157 160 private String context = null; 161 162 163 165 172 public GRHTMLWrapper (PrintWriter writer, String context) 173 { 174 super(writer); 175 176 this.writer = writer; 177 this.context = context; 178 } 179 180 private static String getVersion() 181 { 182 try 183 { 184 return LanguageManager.getText("gui", "WEBMAN_VER"); 185 } 186 catch (Exception e) 187 { 188 return "unknown"; 189 } 190 } 191 192 194 197 public synchronized void close () 198 { 199 writer.println(substitute(BODY_END)); 200 writer.close(); 201 } 202 203 206 public synchronized void write (int c) 207 { 208 linePrefix(); 209 writer.write(c); 210 } 211 212 215 public synchronized void write (char[] buf, int off, int len) 216 { 217 linePrefix(); 218 writer.write(buf, off, len); 219 } 220 221 224 public synchronized void write (char[] buf) 225 { 226 linePrefix(); 227 writer.write(buf); 228 } 229 230 233 public synchronized void write (String s, int off, int len) 234 { 235 linePrefix(); 236 writer.write(s, off, len); 237 } 238 239 242 public synchronized void write (String s) 243 { 244 linePrefix(); 245 writer.write(s); 246 } 247 248 249 251 257 public synchronized void start (String name, String login) 258 { 259 writer.println(substitute(HEADER_START)); 260 writer.println(substitute(HEADER_META)); 261 writer.println(substitute(HEADER_SCRIPT)); 262 writer.println(substitute(HEADER_STYLE)); 263 writer.print(substitute(HEADER_TITLE_START)); 264 writer.print(name); 265 writer.println(substitute(HEADER_TITLE_END)); 266 writer.println(substitute(HEADER_END)); 267 268 writer.println(substitute(BODY_START)); 269 writer.print(substitute(DOCUMENT_PARTICLE_0)); 270 writer.print(name); 271 writer.print(substitute(DOCUMENT_PARTICLE_1)); 272 writer.print(login); 273 writer.println(substitute(DOCUMENT_PARTICLE_2)); 274 275 writer.println(substitute(PARAGRAPH_EMPTY)); 276 } 277 278 284 public synchronized void end (boolean success) 285 { 286 lineSuffix(); 287 288 writer.println(substitute(PARAGRAPH_EMPTY)); 289 writer.println(substitute(PARAGRAPH_LINE)); 290 writer.println(substitute(PARAGRAPH_EMPTY)); 291 292 if (! open) 293 { 294 writer.print(substitute(TABLE_START)); 295 open = true; 296 } 297 298 writer.print(substitute(success ? LINE_SUCCESS : LINE_FAILURE)); 299 writer.print(success ? "Successfully finished" : "Finished with errors"); 300 301 lineSuffix(); 302 303 writer.println(substitute(PARAGRAPH_EMPTY)); 304 writer.println(substitute(PARAGRAPH_LINE)); 305 writer.println(substitute(PARAGRAPH_EMPTY)); 306 } 307 308 public void println(String line) 309 { 310 linePrefix(); 311 writer.print("<font color=" + getColor(line) + ">"); 312 writer.println(line); 313 writer.print("</font>"); 314 lineSuffix(); 315 316 } 317 318 321 public synchronized void println () 322 { 323 linePrefix(); 324 lineSuffix(); 325 } 326 327 330 public void print(String line) 331 { 332 linePrefix(); 333 writer.print("<font color=" + getColor(line) + ">"); 334 writer.println(line); 335 writer.print("</font>"); 336 } 337 338 342 private String getColor(String in) 343 { 344 if (in.indexOf("INFO")!= -1) 345 return "white"; 346 if (in.indexOf("WARN") != -1) 347 return "yellow"; 348 if (in.indexOf("ERROR") != -1 || in.indexOf("FATAL") != -1) 349 return "#ff5555"; if (in.toLowerCase().indexOf(" done") != -1 351 || in.toLowerCase().indexOf(" success") != -1 352 || in.toLowerCase().indexOf(" succeeded") != -1) 353 return "#00cc00"; return "black"; 355 } 356 357 359 private void linePrefix () 360 { 361 if (! open) 362 { 363 writer.print(substitute(TABLE_START)); 364 writer.print(substitute(LINE_STANDARD)); 365 open = true; 366 } 367 } 368 369 private void lineSuffix () 370 { 371 if (open) 372 { 373 writer.println(substitute(TABLE_END)); 374 open = false; 375 } 376 } 377 378 379 381 private String substitute (String string) 382 { 383 int index = string.indexOf(TK_APP_CONTEXT); 384 385 if (index == -1) 386 { 387 return string; 388 } 389 390 int count = 0; 391 int diff = this.context.length() - TK_APP_CONTEXT.length(); 392 StringBuffer buffer = new StringBuffer (string); 393 394 while (index != -1) 395 { 396 buffer.replace(index + (count * diff), index + (count * diff) + TK_APP_CONTEXT.length(), this.context); 397 index = string.indexOf(TK_APP_CONTEXT, index + 1); 398 count++; 399 } 400 401 return buffer.toString(); 402 } 403 404 } 405 | Popular Tags |