KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > html > ReportWriter


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.html;
21
22 import javax.swing.text.*;
23 import javax.swing.event.*;
24 import java.awt.*;
25 import java.awt.event.*;
26 import javax.swing.*;
27 import java.io.*;
28 import java.util.List JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import org.openide.ErrorManager;
31 import org.openide.explorer.view.*;
32
33
34 import org.openide.loaders.DataObject;
35 import org.openide.text.Line;
36
37 import org.netbeans.modules.html.*;
38
39 import org.w3c.tidy.*;
40
41 import org.netbeans.modules.tasklist.core.TLUtils;
42
43
44 /** Special PrintWriter which has intimate knowledge of
45     the "Report" class in org.w3c.tidy.Report. It uses
46     this knowledge to decompose output written to the
47     tidy print writer into separate error warnings that
48     are then forwarded to the ErrorReporter. */

49 class ReportWriter extends PrintWriter {
50     // XXX ErrorReporter - Shouldn't that be "ErrorPresenter" instead?
51
private ErrorReporter reporter = null;
52         private int line = -1;
53         private int column = -1;
54         private boolean warning = false;
55         private StringBuffer JavaDoc sb = new StringBuffer JavaDoc(200);
56
57         ReportWriter(ErrorReporter reporter) {
58             super(new StringWriter()); // dummy string writer, don't need it
59
this.reporter = reporter;
60         }
61
62         public void print(String JavaDoc msg) {
63             if (msg.startsWith("Error: ")) { // from TidyMessages.properties
64
warning = false;
65                 /* Leave Error prefix around: gives more weight to these
66                 if (msg.length() == 7) {
67                     return;
68                 }
69                 msg = msg.substring(7); // Chop off Warning prefix
70                 */

71             } else if (msg.startsWith("Warning: ")) { // from TidyMessages.properties
72
warning = true;
73                 if (msg.length() == 8) {
74                     return;
75                 }
76                 msg = msg.substring(8); // Chop off Warning prefix
77
}
78             // Special knowledge: when we get a print() and there has
79
// been no output yet, it's probably a line/column
80
// marker
81
if ((sb.length() == 0) &&
82                 (msg.startsWith("line "))) { // should this be bundle chkd?
83
// for now, no other bundles
84
// in distribution
85
int i = 5;
86                 int digit;
87                 line = 0;
88                 while (true) {
89                     char c = msg.charAt(i++);
90                     digit = Character.digit(c, 10);
91                     if (digit == -1) {
92                         break;
93                     }
94                     line *= 10;
95                     line += digit;
96                 }
97                 // We don't care about the column yet so no point
98
// processing it
99
} else {
100                 sb.append(msg);
101             }
102         }
103
104         public void println(String JavaDoc msg) {
105             if (msg.startsWith("Error: ")) { // from TidyMessages.properties
106
warning = false;
107                 /* Leave Error prefix around: gives more weight to these
108                 if (msg.length() == 7) {
109                     return;
110                 }
111                 msg = msg.substring(7); // Chop off Warning prefix
112                 */

113             } else if (msg.startsWith("Warning: ")) { // from TidyMessages.properties
114
warning = true;
115                 if (msg.length() == 8) {
116                     return;
117                 }
118                 msg = msg.substring(8); // Chop off Warning prefix
119
}
120             String JavaDoc content;
121             if (sb.length() > 0) {
122                 sb.append(msg);
123                 content = sb.toString();
124             } else {
125                 content = msg;
126             }
127             report(content);
128         }
129
130         public void println() {
131             if (sb.length() > 0) {
132                 report(sb.toString());
133             }
134         }
135
136         private void report(String JavaDoc msg) {
137             reporter.reportError(line, column, !warning, msg);
138             line = -1;
139             column = -1;
140             sb.setLength(0);
141             warning = false;
142         }
143     }
144
Popular Tags