01: /*
02: * CommandTester.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.wbcommands;
13:
14: import java.util.HashMap;
15: import java.util.HashSet;
16: import java.util.Map;
17: import java.util.Set;
18:
19: /**
20: * A class to test whether a given SQL Verb is an internal
21: * Workbench command. This is used by the SqlFormatter, because
22: * the verbs for WbXXXX commands are not formatted in uppercase.
23: *
24: * This is also used by the code completion to check for WB specific commands.
25: *
26: * @see workbench.sql.formatter.SqlFormatter
27: * @see workbench.gui.completion.StatementContext
28: *
29: * @author support@sql-workbench.net
30: */
31: public class CommandTester {
32: private final Set<String> commands;
33: private final Map<String, String> formattedWords;
34:
35: public CommandTester() {
36: commands = new HashSet<String>();
37: commands.add(WbCall.VERB);
38: commands.add(WbConfirm.VERB);
39: commands.add(WbCopy.VERB);
40: commands.add(WbDefinePk.VERB);
41: commands.add(WbDefineVar.VERB_DEFINE_LONG);
42: commands.add(WbDefineVar.VERB_DEFINE_SHORT);
43: commands.add(WbEndBatch.VERB);
44: commands.add(WbExport.VERB);
45: commands.add(WbFeedback.VERB);
46: commands.add(WbImport.VERB);
47: commands.add(WbInclude.VERB);
48: commands.add(WbListPkDef.VERB);
49: commands.add(WbLoadPkMapping.VERB);
50: commands.add(WbRemoveVar.VERB);
51: commands.add(WbSavePkMapping.VERB);
52: commands.add(WbSchemaDiff.VERB);
53: commands.add(WbSchemaReport.VERB);
54: commands.add(WbSelectBlob.VERB);
55: commands.add(WbStartBatch.VERB);
56: commands.add(WbXslt.VERB);
57:
58: formattedWords = new HashMap<String, String>();
59: formattedWords.put(WbSavePkMapping.VERB,
60: WbSavePkMapping.FORMATTED_VERB);
61: formattedWords.put(WbLoadPkMapping.VERB,
62: WbLoadPkMapping.FORMATTED_VERB);
63: formattedWords.put(WbDefineVar.DEFINE_LONG.getVerb(),
64: "WbVarDefine");
65: formattedWords.put(WbDefineVar.DEFINE_SHORT.getVerb(),
66: "WbVarDef");
67: formattedWords
68: .put(WbListPkDef.VERB, WbListPkDef.FORMATTED_VERB);
69: formattedWords.put(WbEndBatch.VERB, "WbEndBatch");
70: formattedWords.put(WbStartBatch.VERB, "WbStartBatch");
71: formattedWords.put(WbSchemaDiff.VERB, "WbSchemaDiff");
72: }
73:
74: public boolean isWbCommand(String verb) {
75: if (verb == null)
76: return false;
77: return commands.contains(verb.trim().toUpperCase());
78: }
79:
80: public String formatVerb(String verb) {
81: String f = formattedWords.get(verb.toUpperCase());
82: if (f != null) {
83: return f;
84: } else {
85: return fixCase(verb);
86: }
87: }
88:
89: private String fixCase(String verb) {
90: if (!verb.toLowerCase().startsWith("wb"))
91: return verb;
92: String s = "Wb" + Character.toUpperCase(verb.charAt(2))
93: + verb.substring(3).toLowerCase();
94: return s;
95: }
96:
97: }
|