jTracer  1.03
Stack trace visualization tool
Highlighter.java
Go to the documentation of this file.
1 
7 package org.libcsdbg.jtracer;
8 
9 import java.util.Vector;
10 import java.util.Hashtable;
11 
12 import java.io.File;
13 import java.io.FileReader;
14 import java.io.BufferedReader;
15 import java.io.IOException;
16 
20 public class Highlighter extends Hashtable<String, Vector<String>>
21 {
23  private static final long serialVersionUID = 0x02;
24 
26  private static Highlighter current = null;
27 
28 
32  Highlighter()
33  {
34  current = this;
35 
36  try {
37  loadDictionary("type");
38  loadDictionary("keyword");
39  loadDictionary("extension");
40  }
41 
42  catch (Throwable t) {
43  Registry.debug(t);
44  }
45  }
46 
47 
53  public void loadDictionary(String nm) throws IOException
54  {
55  File src = Registry.getCurrent().getResource("config/" + nm + ".dict");
56  String path = src.getCanonicalPath();
57 
58  if (!src.isFile())
59  throw new IOException("Dictionary '" + path + "' doesn't exist");
60 
61  else if (!src.canRead())
62  throw new IOException("Can't read dictionary '" + path + "'");
63 
64  BufferedReader reader = new BufferedReader(new FileReader(src));
65  Vector<String> words = new Vector<String>();
66 
67  while (true) {
68  String line = reader.readLine();
69  if (line == null)
70  break;
71 
72  line = line.trim();
73  if (line.length() > 0)
74  words.add(line);
75  }
76 
77  reader.close();
78  put(nm, words);
79  }
80 
81 
93  public boolean lookup(String token, String nm, boolean regex)
94  {
95  Vector<String> words = get(nm);
96  if (words == null)
97  return false;
98 
99  for (int i = 0, cnt = words.size(); i < cnt; i++) {
100  String exp = words.get(i);
101 
102  if (regex) {
103  if (token.matches(exp))
104  return true;
105  }
106 
107  else if (token.equals(exp))
108  return true;
109  }
110 
111  return false;
112  }
113 
114 
120  public static Highlighter getCurrent()
121  {
122  return current;
123  }
124 }
125 
boolean lookup(String token, String nm, boolean regex)
Check if a word belongs in a dictionary.
static Highlighter current
Current highlighter.
static final long serialVersionUID
Class version.
void loadDictionary(String nm)
Load a dictionary.
C++ stack trace syntax highlighter.
static Highlighter getCurrent()
Get the current highlighter.