01: package org.drools.eclipse.editors;
02:
03: import java.io.BufferedReader;
04: import java.io.IOException;
05: import java.io.InputStream;
06: import java.io.InputStreamReader;
07: import java.util.ArrayList;
08: import java.util.List;
09:
10: /**
11: * This provides a list of keywords for syntax highlighting.
12: * Uses a pseudo properties file format.
13: * @author Michael Neale
14: */
15: public class Keywords {
16:
17: private String[] allDrools;
18: private String[] allJava;
19: private String[] allMvel;
20: private static Keywords instance;
21:
22: public static Keywords getInstance() {
23: if (instance == null) {
24: instance = new Keywords();
25: }
26: return instance;
27: }
28:
29: public String[] getAllDroolsKeywords() {
30: return allDrools;
31: }
32:
33: public String[] getAllJavaKeywords() {
34: return allJava;
35: }
36:
37: public String[] getAllMvelKeywords() {
38: return allMvel;
39: }
40:
41: private Keywords() {
42: allDrools = readKeywords("keywords.properties");
43: allJava = readKeywords("java_keywords.properties");
44: allMvel = readKeywords("mvel_keywords.properties");
45: }
46:
47: private String[] readKeywords(String fileName) {
48: InputStream stream = this .getClass().getResourceAsStream(
49: fileName);
50: try {
51: BufferedReader reader = new BufferedReader(
52: new InputStreamReader(stream));
53:
54: List list = new ArrayList();
55:
56: String line = null;
57: while ((line = reader.readLine()) != null) {
58: if (!line.startsWith("#"))
59: list.add(line);
60: }
61:
62: return (String[]) list.toArray(new String[list.size()]);
63: } catch (IOException e) {
64: throw new IllegalArgumentException(
65: "Could not load keywords for editor.");
66: } finally {
67: try {
68: stream.close();
69: } catch (IOException e) {
70: throw new IllegalStateException("Error closing stream.");
71: }
72: }
73: }
74:
75: }
|