1 package org.catacomb.druid.guimodel; 2 3 import org.catacomb.interlish.structure.InfoMessage; 4 import org.catacomb.interlish.util.JUtil; 5 import org.catacomb.util.Timestamp; 6 7 8 9 public class LogEntry implements InfoMessage { 10 11 String timestamp; 12 int severity; 13 String context; 14 String text; 15 16 String logEntryTemplate; 17 String htmlText; 18 19 20 21 public LogEntry(String s) { 22 this(INFO, "default", s); 23 } 24 25 26 public LogEntry(int level, String msg) { 27 this(level, "default", msg); 28 } 29 30 31 public LogEntry(int level, String ctx, String msg) { 32 severity = level; 33 context = ctx; 34 text = msg; 35 36 timestamp = Timestamp.withinSessionTimestamp(); 37 38 } 39 40 41 42 public String getPlainText() { 43 return (timestamp + " " + textLevels[severity] + " " + context + " " + text); 44 } 45 46 47 48 public String getHTML() { 49 if (htmlText == null) { 50 if (logEntryTemplate == null) { 51 logEntryTemplate = JUtil.getRelativeResource(this, "LogEntryTemplate.txt"); 52 } 53 String s = logEntryTemplate.replaceAll("LEVEL", "" + textLevels[severity]); 54 s = s.replaceAll("TIMESTAMP", timestamp); 55 s = s.replaceAll("CONTEXT", context); 56 s = s.replaceAll("TEXT", text); 57 58 htmlText = s; 59 } 60 return htmlText; 61 } 62 63 64 public int getLevel() { 65 return severity; 66 } 67 68 69 public String getContext() { 70 return context; 71 } 72 73 74 public boolean sameAs(InfoMessage im) { 75 boolean ret = false; 76 77 if (im instanceof LogEntry) { 78 LogEntry le = (LogEntry)im; 79 if (le.getPlainText().equals(getPlainText())) { 80 ret = true; 81 } 82 } 83 return ret; 84 } 85 86 }