View Javadoc

1   package org.catacomb.druid.guimodel;
2   
3   import org.catacomb.interlish.report.UserLog;
4   import org.catacomb.interlish.structure.InfoLog;
5   import org.catacomb.interlish.structure.InfoMessage;
6   import org.catacomb.interlish.structure.LogNotificand;
7   import org.catacomb.report.E;
8   
9   
10  import java.util.ArrayList;
11  
12  
13  // producer of logs (this)
14  // receiver of log messages
15  public class Log implements InfoLog {
16  
17      String name;
18  
19      ArrayList<InfoMessage> messages;
20      StringBuffer textBuffer;
21      StringBuffer htmlBuffer;
22  
23      LogNotificand notificand;
24  
25      static Log systemLog;
26  
27  
28      public Log(String s) {
29          name = s;
30          messages = new ArrayList<InfoMessage>();
31          clear();
32      }
33  
34  
35  
36      public void addInfoMessage(InfoMessage im) {
37          messages.add(im);
38          textBuffer.append(im.getPlainText());
39          textBuffer.append("-br-");
40          textBuffer.append("\n");
41  
42          htmlBuffer.append(im.getHTML());
43  
44          if (notificand != null) {
45              notificand.itemLogged(this);
46          }
47      }
48  
49  
50      public void addInfoMessage(int lev, String ctx, String msg) {
51          addInfoMessage(new LogEntry(lev, ctx, msg));
52      }
53  
54  
55      public void setLogNotificand(LogNotificand ln) {
56          if (notificand != null) {
57              E.warning("squashing existing log notificand");
58          }
59          notificand = ln;
60      }
61  
62      public void removeLogNotificand(LogNotificand ln) {
63          notificand = null;
64      }
65  
66  
67      public String getPlainText() {
68          return textBuffer.toString();
69      }
70  
71  
72      public String getHTML() {
73          return htmlBuffer.toString();
74      }
75  
76  
77      public void clear() {
78          messages.clear();
79          textBuffer = new StringBuffer();
80          htmlBuffer = new StringBuffer();
81      }
82  
83  
84  
85      // REFAC - these should go elsewhere...;
86      public static void setSystemLog(Log log) {
87          systemLog = log;
88          UserLog.setLog(log);
89          E.setReporter(log);
90      }
91  
92  
93      public void report(String s) {
94          infoMsg("", s);
95      }
96  
97  
98      public void reportInfo(String s) {
99          infoMsg("", s);
100     }
101 
102     public void reportWarning(String s) {
103         warningMsg("", s);
104     }
105 
106     public void reportError(String s) {
107         errorMsg("", s);
108     }
109 
110 
111     public static void infoMsg(String ctx, String txt) {
112         systemLog.addInfoMessage(LogEntry.INFO, ctx, txt);
113     }
114 
115     public static void warningMsg(String ctx, String txt) {
116         systemLog.addInfoMessage(LogEntry.WARNING, ctx, txt);
117     }
118 
119     public static void errorMsg(String ctx, String txt) {
120         systemLog.addInfoMessage(LogEntry.ERROR, ctx, txt);
121     }
122 }