KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > CheckPathFormatter


1 /*
2  * CheckPathFormatter.java
3  *
4  * Copyright (C) 2002 Peter Graves
5  * $Id: CheckPathFormatter.java,v 1.1.1.1 2002/09/24 16:08:14 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * 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 {
26     private static final byte FORMAT_TEXT = 0;
27     private static final byte FORMAT_COMMENT = 1;
28     private static final byte FORMAT_HEADER_NAME = 2;
29     private static final byte FORMAT_HEADER_VALUE = 4;
30     private static final byte FORMAT_NOT_FOUND = 5;
31     private static final byte FORMAT_STATUS = 6;
32
33     public CheckPathFormatter(Buffer buffer)
34     {
35         this.buffer = buffer;
36     }
37
38     public LineSegmentList formatLine(Line line)
39     {
40         clearSegmentList();
41         if (line == null) {
42             addSegment("", FORMAT_TEXT);
43             return segmentList;
44         }
45         parseLine(line);
46         return segmentList;
47
48     }
49
50     private void parseLine(Line line)
51     {
52         final String JavaDoc text = getDetabbedText(line);
53         if (text.endsWith(" -->")) {
54             addSegment(text, FORMAT_COMMENT);
55             return;
56         }
57         String JavaDoc trim = text.trim();
58         char c;
59         if (trim.length() > 0 && ((c = trim.charAt(0)) == '"' || c == '<')) {
60             if (text.endsWith(" NOT FOUND")) {
61                 int index = text.length() - 11;
62                 addSegment(text, 0, index, FORMAT_TEXT);
63                 addSegment(text, index, FORMAT_NOT_FOUND);
64             } else if (text.endsWith(" (Already listed)")) {
65                 int index = text.length() - 16;
66                 addSegment(text, 0, index, FORMAT_TEXT);
67                 addSegment(text, index, FORMAT_STATUS);
68             } else
69                 addSegment(text, FORMAT_TEXT);
70             return;
71         }
72         int index = text.indexOf(':');
73         if (index > 0) {
74             addSegment(text, 0, index+1, FORMAT_HEADER_NAME);
75             addSegment(text, index+1, FORMAT_HEADER_VALUE);
76             return;
77         }
78         // Default.
79
addSegment(text, FORMAT_TEXT);
80     }
81
82     public FormatTable getFormatTable()
83     {
84         if (formatTable == null) {
85             // Currently there's no CheckPathMode...
86
formatTable = new FormatTable("ListOccurrencesMode");
87             formatTable.addEntryFromPrefs(FORMAT_TEXT, "text");
88             formatTable.addEntryFromPrefs(FORMAT_COMMENT, "comment");
89             formatTable.addEntryFromPrefs(FORMAT_HEADER_NAME, "headerName", "keyword");
90             formatTable.addEntryFromPrefs(FORMAT_HEADER_VALUE, "headerValue", "operator");
91             formatTable.addEntryFromPrefs(FORMAT_NOT_FOUND, "matchingText", "function");
92             formatTable.addEntryFromPrefs(FORMAT_STATUS, "status", "comment");
93         }
94         return formatTable;
95     }
96 }
97
Popular Tags