01: /*
02: * SqlKeywordHelper.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.sql.syntax;
13:
14: import java.io.BufferedReader;
15: import java.io.File;
16: import java.io.FileReader;
17: import java.io.InputStream;
18: import java.io.InputStreamReader;
19: import java.util.Collection;
20: import java.util.HashSet;
21: import java.util.Set;
22: import workbench.log.LogMgr;
23: import workbench.resource.Settings;
24: import workbench.util.FileUtil;
25:
26: /**
27: * Manage
28: * @author support@sql-workbench.net
29: */
30: public class SqlKeywordHelper {
31:
32: public SqlKeywordHelper() {
33: }
34:
35: public Set<String> getKeywords() {
36: return loadKeywordsFromFile("keywords.wb");
37: }
38:
39: public Set<String> getDataTypes() {
40: return loadKeywordsFromFile("datatypes.wb");
41: }
42:
43: public Set<String> getOperators() {
44: return loadKeywordsFromFile("operators.wb");
45: }
46:
47: public Set<String> getSystemFunctions() {
48: return loadKeywordsFromFile("functions.wb");
49: }
50:
51: private Set<String> loadKeywordsFromFile(String filename) {
52: // First read the built-in functions
53: InputStream s = SqlKeywordHelper.class
54: .getResourceAsStream(filename);
55: BufferedReader in = new BufferedReader(new InputStreamReader(s));
56:
57: Collection<String> builtin = FileUtil.getLines(in);
58: Set<String> result = new HashSet<String>(builtin.size());
59: result.addAll(builtin);
60:
61: // Try to read the file in the current directory.
62: File f = new File(filename);
63: if (!f.exists()) {
64: // nothing in the current directory, try the config dir
65: f = new File(Settings.getInstance().getConfigDir(),
66: filename);
67: }
68:
69: if (f.exists()) {
70: try {
71: BufferedReader customFile = new BufferedReader(
72: new FileReader(f));
73: Collection<String> custom = FileUtil
74: .getLines(customFile);
75: result.addAll(custom);
76: } catch (Exception e) {
77: LogMgr.logError(
78: "SqlKeywordHelper.loadKeywordsFromfile()",
79: "Error reading external file", e);
80: }
81: }
82:
83: return result;
84: }
85: }
|