1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
package net.sourceforge.jnlp.util.logging;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Observable;
import java.util.Random;
import java.util.regex.Pattern;
import net.sourceforge.jnlp.util.logging.OutputController.Level;
import net.sourceforge.jnlp.util.logging.headers.Header;
import net.sourceforge.jnlp.util.logging.headers.JavaMessage;
import net.sourceforge.jnlp.util.logging.headers.MessageWithHeader;
import net.sourceforge.jnlp.util.logging.headers.ObservableMessagesProvider;
import net.sourceforge.jnlp.util.logging.headers.PluginHeader;
import net.sourceforge.jnlp.util.logging.headers.PluginMessage;
public class ConsoleOutputPaneModel {
ConsoleOutputPaneModel(ObservableMessagesProvider dataProvider) {
this.dataProvider = dataProvider;
}
boolean shouldUpdate() {
for (int i = lastUpdateIndex; i < dataProvider.getData().size(); i++) {
if (!filtered(dataProvider.getData().get(i))) {
return true;
}
}
return false;
}
private abstract class CatchedMessageWithHeaderComparator implements Comparator<MessageWithHeader> {
@Override
public int compare(MessageWithHeader o1, MessageWithHeader o2) {
try {
final int order = revertSort ? 1 : -1;
return order * body(o1, o2);
} catch (NullPointerException npe) {
//caused by corrupted c messages
return 0;
}
}
abstract int body(MessageWithHeader o1, MessageWithHeader o2);
}
//testign data provider
static class TestMessagesProvider extends Observable implements ObservableMessagesProvider {
List<MessageWithHeader> data = new ArrayList<MessageWithHeader>();
List<MessageWithHeader> origData = new ArrayList<MessageWithHeader>();
public List<MessageWithHeader> getData() {
return data;
}
@Override
public Observable getObservable() {
return this;
}
public TestMessagesProvider() {
createData();
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(new Random().nextInt(2000));
data.add(origData.get(new Random().nextInt(origData.size())));
TestMessagesProvider.this.setChanged();
TestMessagesProvider.this.notifyObservers();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}).start();
}
void createData() {
String[] plugin = {
"plugindebug 1384850630162925 [jvanek][ITW-C-PLUGIN][MESSAGE_DEBUG][Tue Nov 19 09:43:50 CET 2013][/home/jvanek/Desktop/icedtea-web/plugin/icedteanp/IcedTeaNPPlugin.cc:1204] ITNPP Thread# 140513434003264, gthread 0x7fcbd531f8c0: PIPE: plugin read: plugin PluginProxyInfo reference 1 http://www.walter-fendt.de:80",
"preinit_plugindebug 1384850630162920 [jvanek][ITW-C-PLUGIN][MESSAGE_DEBUG][Tue Nov 19 09:43:50 CET 2013][/home/jvanek/Desktop/icedtea-web/plugin/icedteanp/IcedTeaNPPlugin.cc:1204] ITNPP Thread# 140513434003264, gthread 0x7fcbd531f8c0: PIPE: plugin read: plugin PluginProxyInfo reference 1 http://www.walter-fendt.de:80",
"plugindebugX 1384850630162954 [jvanek][ITW-Cplugindebug 1384850630163008 [jvanek][ITW-C-PLUGIN][MESSAGE_DEBUG][Tue Nov 19 09:43:50 CET 2013][/home/jvanek/Desktop/icedtea-web/plugin/icedteanp/IcedTeaNPPlugin.cc:1124] ITNPP Thread# 140513434003264, gthread 0x7fcbd531f8c0: parts[0]=plugin, parts[1]=PluginProxyInfo, reference, parts[3]=1, parts[4]=http://www.walter-fendt.de:80 -- decoded_url=http://www.walter-fendt.de:80",
"preinit_pluginerror 1384850630163294 [jvanek][ITW-C-PLUGIN][MESSAGE_ERROR][Tue Nov 19 09:43:50 CET 2013][/home/jvanek/Desktop/icedtea-web/plugin/icedteanp/IcedTeaNPPlugin.cc:1134] ITNPP Thread# 140513434003264, gthread 0x7fcbd531f8c0: Proxy info: plugin PluginProxyInfo reference 1 DIRECT",
"pluginerror 1384850630163291 [jvanek][ITW-C-PLUGIN][MESSAGE_ERROR][Tue Nov 19 09:43:50 CET 2013][/home/jvanek/Desktop/icedtea-web/plugin/icedteanp/IcedTeaNPPlugin.cc:1134] ITNPP Thread# 140513434003264, gthread 0x7fcbd531f8c0: Proxy info: plugin PluginProxyInfo reference 1 DIRECT"
};
for (String string : plugin) {
origData.add(new PluginMessage(string));
}
origData.add(new JavaMessage(new Header(Level.ERROR_ALL, Thread.currentThread().getStackTrace(), Thread.currentThread(), false), "message 1"));
origData.add(new JavaMessage(new Header(Level.ERROR_DEBUG, Thread.currentThread().getStackTrace(), Thread.currentThread(), false), "message 3"));
origData.add(new JavaMessage(new Header(Level.WARNING_ALL, Thread.currentThread().getStackTrace(), Thread.currentThread(), false), "message 2"));
origData.add(new JavaMessage(new Header(Level.WARNING_DEBUG, Thread.currentThread().getStackTrace(), Thread.currentThread(), false), "message 4"));
origData.add(new JavaMessage(new Header(Level.MESSAGE_DEBUG, Thread.currentThread().getStackTrace(), Thread.currentThread(), false), "message 9"));
origData.add(new JavaMessage(new Header(Level.MESSAGE_ALL, Thread.currentThread().getStackTrace(), Thread.currentThread(), false), "message 0 - multilined \n"
+ "since beggining\n"
+ " later\n"
+ "again from beggingin\n"
+ " even later"));
data.addAll(origData);
}
}
static final Pattern defaultPattern = Pattern.compile("(m?)(.*\n*)*");
ObservableMessagesProvider dataProvider;
Pattern lastValidPattern = defaultPattern;
Pattern usedPattern = lastValidPattern;
int lastUpdateIndex; //to add just what was added newly
int statisticsShown;
private static final String HTMLCOLOR_DIMRED = "FF6666";
private static final String HTMLCOLOR_MIDGRAY = "666666";
private static final String HTMLCOLOR_SPARKRED = "FF0000";
private static final String HTMLCOLOR_LIGHTGRAY = "AAAAAA";
private static final String HTMLCOLOR_GREENYELLOW = "AAAA00";
private static final String HTMLCOLOR_PINKYREAD = "FF0055";
private static final String HTMLCOLOR_BLACK = "000000";
String importList() {
return importList(lastUpdateIndex);
}
String importList(int start) {
return importList(highLight, start);
}
String importList(boolean mark, int start) {
int added = start;
StringBuilder sb = new StringBuilder();
if (mark) {
sb.append("<div style='");
if (!wordWrap) {
sb.append("white-space:nowrap;");
}
sb.append("font-family:\"Monospaced\"'>");
}
List<MessageWithHeader> sortedList;
if (start == 0) {
sortedList = preSort(dataProvider.getData());
} else {
sortedList = preSort(Collections.synchronizedList(dataProvider.getData().subList(start, dataProvider.getData().size())));
}
lastUpdateIndex = dataProvider.getData().size();
for (MessageWithHeader messageWithHeader : sortedList) {
if (filtered(messageWithHeader)) {
continue;
}
if (mark) {
sb.append("<div style='color:#");
if (messageWithHeader.getHeader().isC && messageWithHeader.getHeader() instanceof PluginHeader) {
if (!((PluginHeader) (messageWithHeader.getHeader())).preinit) {
if (messageWithHeader.getHeader().level.isError()) {
sb.append(HTMLCOLOR_DIMRED);
} else {
sb.append(HTMLCOLOR_MIDGRAY);
}
} else {
if (messageWithHeader.getHeader().level.isError()) {
sb.append(HTMLCOLOR_SPARKRED);
} else {
sb.append(HTMLCOLOR_LIGHTGRAY);
}
}
} else {
if (messageWithHeader.getHeader().level.isWarning()) {
sb.append(HTMLCOLOR_GREENYELLOW);
} else if (messageWithHeader.getHeader().level.isError()) {
sb.append(HTMLCOLOR_PINKYREAD);
} else {
sb.append(HTMLCOLOR_BLACK);
}
}
sb.append("'>");
//sb.append("<![CDATA[");
}
if (messageWithHeader instanceof PluginMessage && ((PluginMessage) (messageWithHeader)).wasError) {
sb.append("{corrupted}");
}
String line = (createLine(messageWithHeader));
if (mark) {
line = line.replaceAll("\n", "<br>\n");
line = line.replaceAll(" ", " ");//small trick, html is reducting row of sapces to single space. This handles it and stimm allow line wrap
line = line.replaceAll("\t", " ");
}
sb.append(line);
if (mark) {
//sb.append("]]>");
sb.append("</div>");
}
//always wrap, looks better, works smoother
sb.append("\n");
added++;
}
if (mark) {
sb.append("</div>");
}
statisticsShown = added;
return sb.toString();
}
String createLine(MessageWithHeader m) {
StringBuilder sb = new StringBuilder();
if (showHeaders) {
sb.append(m.getHeader().toString(showUser,
showOrigin,
showLevel,
showDate,
showCode,
showThread1,
showThread2));
}
if (showMessage && showHeaders) {
sb.append(": ");
}
if (showMessage) {
sb.append(m.getMessage().toString());
}
return sb.toString();
}
List<MessageWithHeader> preSort(List<MessageWithHeader> data) {
List<MessageWithHeader> sortedData;
if (sortBy == 0) {
if (revertSort) {
sortedData = Collections.synchronizedList(new ArrayList<MessageWithHeader>(data));
Collections.reverse(sortedData);
} else {
sortedData = data;
}
} else {
sortedData = Collections.synchronizedList(new ArrayList<MessageWithHeader>(data));
switch (sortBy) {
case 1:
Collections.sort(sortedData, new CatchedMessageWithHeaderComparator() {
@Override
public int body(MessageWithHeader o1, MessageWithHeader o2) {
return o1.getHeader().user.compareTo(o2.getHeader().user);
}
});
break;
case 2:
Collections.sort(sortedData, new CatchedMessageWithHeaderComparator() {
@Override
public int body(MessageWithHeader o1, MessageWithHeader o2) {
return o1.getHeader().getOrigin().compareTo(o2.getHeader().getOrigin());
}
});
break;
case 3:
Collections.sort(sortedData, new CatchedMessageWithHeaderComparator() {
@Override
public int body(MessageWithHeader o1, MessageWithHeader o2) {
return o1.getHeader().level.toString().compareTo(o2.getHeader().level.toString());
}
});
break;
case 4:
Collections.sort(sortedData, new CatchedMessageWithHeaderComparator() {
@Override
public int body(MessageWithHeader o1, MessageWithHeader o2) {
return o1.getHeader().date.compareTo(o2.getHeader().date);
}
});
break;
case 5:
Collections.sort(sortedData, new CatchedMessageWithHeaderComparator() {
@Override
public int body(MessageWithHeader o1, MessageWithHeader o2) {
return o1.getHeader().caller.compareTo(o2.getHeader().caller);
}
});
break;
case 6:
Collections.sort(sortedData, new CatchedMessageWithHeaderComparator() {
@Override
public int body(MessageWithHeader o1, MessageWithHeader o2) {
return o1.getHeader().thread1.compareTo(o2.getHeader().thread1);
}
});
break;
case 7:
Collections.sort(sortedData, new CatchedMessageWithHeaderComparator() {
@Override
public int body(MessageWithHeader o1, MessageWithHeader o2) {
return o1.getMessage().compareTo(o2.getMessage());
}
});
break;
case 8:
Collections.sort(sortedData, new CatchedMessageWithHeaderComparator() {
@Override
public int body(MessageWithHeader o1, MessageWithHeader o2) {
return o1.getHeader().thread2.compareTo(o2.getHeader().thread2);
}
});
break;
}
}
return sortedData;
}
boolean filtered(MessageWithHeader m) {
if (!showOut && m.getHeader().level.isOutput() && !m.getHeader().level.isWarning()) {
return true;
}
if (!showErr && m.getHeader().level.isError() && !m.getHeader().level.isWarning()) {
return true;
}
if (!showDebug && m.getHeader().level.isDebug()) {
return true;
}
if (!showInfo && m.getHeader().level.isInfo()) {
return true;
}
if (!showJava && !m.getHeader().isC) {
return true;
}
if (!showPlugin && m.getHeader().isC) {
return true;
}
if (m.getHeader() instanceof PluginHeader) {
PluginHeader mm = (PluginHeader) m.getHeader();
if (!showPreInit && mm.preinit) {
return true;
}
if (!showPostInit && !mm.preinit) {
return true;
}
if (!showIncomplete && m instanceof PluginMessage && ((PluginMessage) (m)).wasError) {
return true;
}
if (!showComplete && m instanceof PluginMessage && !((PluginMessage) (m)).wasError) {
return true;
}
}
if (regExLabel) {
String s = createLine(m);
if (matchPattern && !usedPattern.matcher(s).matches()) {
return true;
}
if (!matchPattern && usedPattern.matcher(s).matches()) {
return true;
}
}
return false;
}
String createStatisticHint() {
return statisticsShown + "/" + dataProvider.getData().size();
}
boolean highLight;
boolean matchPattern;
boolean regExLabel;
boolean revertSort;
boolean showCode;
boolean showComplete;
boolean showDate;
boolean showDebug;
boolean showErr;
boolean showHeaders;
boolean showIncomplete;
boolean showInfo;
boolean showJava;
boolean showLevel;
boolean showMessage;
boolean showOrigin;
boolean showOut;
boolean showPlugin;
boolean showPostInit;
boolean showPreInit;
boolean showThread1;
boolean showThread2;
boolean showUser;
int sortBy;
boolean wordWrap;
}
|