01: /*
02: * CheckPathFormatter.java
03: *
04: * Copyright (C) 2002 Peter Graves
05: * $Id: CheckPathFormatter.java,v 1.1.1.1 2002/09/24 16:08:14 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j;
23:
24: public final class CheckPathFormatter extends Formatter {
25: private static final byte FORMAT_TEXT = 0;
26: private static final byte FORMAT_COMMENT = 1;
27: private static final byte FORMAT_HEADER_NAME = 2;
28: private static final byte FORMAT_HEADER_VALUE = 4;
29: private static final byte FORMAT_NOT_FOUND = 5;
30: private static final byte FORMAT_STATUS = 6;
31:
32: public CheckPathFormatter(Buffer buffer) {
33: this .buffer = buffer;
34: }
35:
36: public LineSegmentList formatLine(Line line) {
37: clearSegmentList();
38: if (line == null) {
39: addSegment("", FORMAT_TEXT);
40: return segmentList;
41: }
42: parseLine(line);
43: return segmentList;
44:
45: }
46:
47: private void parseLine(Line line) {
48: final String text = getDetabbedText(line);
49: if (text.endsWith(" -->")) {
50: addSegment(text, FORMAT_COMMENT);
51: return;
52: }
53: String trim = text.trim();
54: char c;
55: if (trim.length() > 0
56: && ((c = trim.charAt(0)) == '"' || c == '<')) {
57: if (text.endsWith(" NOT FOUND")) {
58: int index = text.length() - 11;
59: addSegment(text, 0, index, FORMAT_TEXT);
60: addSegment(text, index, FORMAT_NOT_FOUND);
61: } else if (text.endsWith(" (Already listed)")) {
62: int index = text.length() - 16;
63: addSegment(text, 0, index, FORMAT_TEXT);
64: addSegment(text, index, FORMAT_STATUS);
65: } else
66: addSegment(text, FORMAT_TEXT);
67: return;
68: }
69: int index = text.indexOf(':');
70: if (index > 0) {
71: addSegment(text, 0, index + 1, FORMAT_HEADER_NAME);
72: addSegment(text, index + 1, FORMAT_HEADER_VALUE);
73: return;
74: }
75: // Default.
76: addSegment(text, FORMAT_TEXT);
77: }
78:
79: public FormatTable getFormatTable() {
80: if (formatTable == null) {
81: // Currently there's no CheckPathMode...
82: formatTable = new FormatTable("ListOccurrencesMode");
83: formatTable.addEntryFromPrefs(FORMAT_TEXT, "text");
84: formatTable.addEntryFromPrefs(FORMAT_COMMENT, "comment");
85: formatTable.addEntryFromPrefs(FORMAT_HEADER_NAME,
86: "headerName", "keyword");
87: formatTable.addEntryFromPrefs(FORMAT_HEADER_VALUE,
88: "headerValue", "operator");
89: formatTable.addEntryFromPrefs(FORMAT_NOT_FOUND,
90: "matchingText", "function");
91: formatTable.addEntryFromPrefs(FORMAT_STATUS, "status",
92: "comment");
93: }
94: return formatTable;
95: }
96: }
|