Source Code Cross Referenced for SqlKeywordHandler.java in  » Database-Client » SQL-Workbench » workbench » db » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » SQL Workbench » workbench.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SqlKeywordHandler.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.db;
013:
014:        import java.io.File;
015:        import java.io.FileInputStream;
016:        import java.io.InputStream;
017:        import java.sql.Connection;
018:        import java.util.Collection;
019:        import java.util.List;
020:        import java.util.Set;
021:        import java.util.TreeSet;
022:        import workbench.WbManager;
023:        import workbench.log.LogMgr;
024:        import workbench.resource.Settings;
025:        import workbench.util.StringUtil;
026:        import workbench.util.TextlistReader;
027:
028:        /**
029:         *
030:         * @author support@sql-workbench.net
031:         */
032:        public class SqlKeywordHandler {
033:            private Set<String> keywords;
034:
035:            public SqlKeywordHandler(Connection con) {
036:                readKeywords(con, null);
037:            }
038:
039:            public SqlKeywordHandler(Connection con, String dbid) {
040:                readKeywords(con, dbid);
041:            }
042:
043:            public Collection<String> getSqlKeywords() {
044:                return this .keywords;
045:            }
046:
047:            /**
048:             * Read the keywords for the current DBMS that the JDBC driver returns.
049:             * If the driver does not return all keywords, this list can be manually
050:             * extended by defining the property workbench.db.<dbid>.syntax.keywords
051:             * with a comma separated list of additional keywords
052:             */
053:            private void readKeywords(Connection con, String dbId) {
054:                this .keywords = new TreeSet<String>();
055:                if (dbId != null) {
056:                    try {
057:                        String keys = con.getMetaData().getSQLKeywords();
058:                        List<String> keyList = StringUtil.stringToList(keys,
059:                                ",");
060:                        this .keywords.addAll(keyList);
061:                    } catch (Exception e) {
062:                        LogMgr
063:                                .logWarning("SqlKeywordHandler.readKeywords",
064:                                        "Error reading SQL keywords: "
065:                                                + e.getMessage());
066:                    }
067:
068:                    String userKeys = Settings.getInstance().getProperty(
069:                            "workbench.db. + " + dbId + ".syntax.keywords",
070:                            null);
071:                    if (userKeys != null) {
072:                        List<String> l = StringUtil.stringToList(userKeys
073:                                .toUpperCase(), ",");
074:                        this .keywords.addAll(l);
075:                    }
076:                }
077:
078:                // Read the base set of keywords (which cannot be configured)
079:                try {
080:                    InputStream in = this .getClass().getResourceAsStream(
081:                            "SqlKeywords.txt");
082:
083:                    // TextlistReader will close the input stream
084:                    TextlistReader reader = new TextlistReader(in);
085:                    Collection<String> values = reader.getValues();
086:                    if (values != null)
087:                        this .keywords.addAll(values);
088:
089:                    // When running tests, the WbManager is not necessarily available
090:                    WbManager mgr = WbManager.getInstance();
091:                    if (mgr != null) {
092:                        File baseDir = new File(mgr.getJarPath());
093:                        File f = new File(baseDir, "SqlKeywords.txt");
094:                        if (f.exists()) {
095:                            LogMgr.logDebug("SqlKeywordHandler.readKeywords()",
096:                                    "Reading addtional keywords from "
097:                                            + f.getCanonicalPath());
098:                            in = new FileInputStream(f);
099:                            reader = new TextlistReader(in);
100:                            values = reader.getValues();
101:                            if (values != null)
102:                                this .keywords.addAll(values);
103:                        }
104:                    }
105:                } catch (Exception e) {
106:                    LogMgr.logError("SqlKeywordHandler.readKeywords",
107:                            "Error reading SQL keywords", e);
108:                }
109:
110:                // Now remove any keywords that the user defined.
111:
112:                try {
113:                    String words = Settings.getInstance()
114:                            .getProperty(
115:                                    "workbench.db." + dbId
116:                                            + ".syntax.nokeywords", null);
117:                    List l = StringUtil.stringToList(words, ",", true, true,
118:                            false);
119:                    this .keywords.removeAll(l);
120:                } catch (Exception e) {
121:                    e.printStackTrace();
122:                }
123:            }
124:
125:            public boolean isKeyword(String verb) {
126:                if (verb == null)
127:                    return false;
128:                if (this .keywords == null)
129:                    return false;
130:                return this.keywords.contains(verb.trim().toUpperCase());
131:            }
132:
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.