Source Code Cross Referenced for CollectStringLiterals.java in  » Code-Analyzer » hammurapi-3.20.0.3 » org » hammurapi » inspectors » samples » 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 » Code Analyzer » hammurapi 3.20.0.3 » org.hammurapi.inspectors.samples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Hammurapi
003:         * Automated Java code review system. 
004:         * Copyright (C) 2004  Hammurapi Group
005:         *
006:         * This program is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU General Public License as published by
008:         * the Free Software Foundation; either version 2 of the License, or
009:         *  (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         * URL: http://www.hammurapi.org
021:         * e-Mail: support@hammurapi.biz 
022:         */
023:        package org.hammurapi.inspectors.samples;
024:
025:        import java.io.FileWriter;
026:        import java.io.IOException;
027:        import java.io.Writer;
028:        import java.sql.PreparedStatement;
029:        import java.sql.ResultSet;
030:        import java.sql.SQLException;
031:        import java.util.Properties;
032:
033:        import org.hammurapi.InspectorBase;
034:        import org.hammurapi.HammurapiException;
035:        import org.hammurapi.HammurapiRuntimeException;
036:        import org.hammurapi.results.AnnotationContext;
037:        import org.hammurapi.results.LinkedAnnotation;
038:        import org.hammurapi.results.AnnotationContext.FileEntry;
039:
040:        import com.pavelvlasov.jsel.Repository;
041:        import com.pavelvlasov.jsel.expressions.StringConstant;
042:        import com.pavelvlasov.review.SourceMarker;
043:        import com.pavelvlasov.sql.Parameterizer;
044:        import com.pavelvlasov.sql.RowProcessor;
045:        import com.pavelvlasov.sql.SQLProcessor;
046:
047:        /**
048:         * This inspector demonstrates usage of annotations and persistency of inspector findings.
049:         * It collects all string literals and then outputs them alphabetially sorted
050:         * as an annotation in Summary.
051:         * This inspector cleans results from previous run before scan. As such it will report string literals only from modified
052:         * sources. 
053:         * @author Pavel Vlasov
054:         * @version $Revision: 1.4 $
055:         */
056:        public class CollectStringLiterals extends InspectorBase {
057:
058:            /**
059:             * Unique table name
060:             */
061:            private String tableName = "STRING_LITERALS";
062:
063:            /**
064:             * Method to inject table name from parameters.
065:             */
066:            public void setTableName(String tableName) {
067:                this .tableName = tableName;
068:            }
069:
070:            private String[] initSQL = {
071:                    "CREATE CACHED TABLE "
072:                            + tableName
073:                            + " (LITERAL VARCHAR(250), SOURCE VARCHAR(250), LINE INTEGER, COL INTEGER)",
074:                    "CREATE INDEX IX_" + tableName + " ON " + tableName
075:                            + " (LITERAL, SOURCE, LINE, COL)" };
076:
077:            //	private String[] destroySQL= {
078:            //			"DROP INDEX IX_"+tableName,	
079:            //			"DROP TABLE "+tableName
080:            //	};
081:
082:            /**
083:             * Creating a table to store results
084:             */
085:            public void initDb(SQLProcessor processor, Properties dbProperties) {
086:                for (int i = 0; i < initSQL.length; i++) {
087:                    try {
088:                        processor.processUpdate(initSQL[i], null);
089:                    } catch (SQLException e) {
090:                        throw new HammurapiRuntimeException(e);
091:                    }
092:                }
093:            }
094:
095:            public void init() throws HammurapiException {
096:                super .init();
097:                SQLProcessor processor = getContext().getSession()
098:                        .getProcessor();
099:                try {
100:                    processor.processUpdate("DELETE FROM " + tableName, null);
101:                } catch (SQLException e) {
102:                    disable("Could not clean " + tableName + ": " + e);
103:                }
104:            }
105:
106:            public void visit(final StringConstant constant) {
107:                SQLProcessor processor = getContext().getSession()
108:                        .getProcessor();
109:                try {
110:                    processor.processUpdate("INSERT INTO " + tableName
111:                            + " (LITERAL, SOURCE, LINE, COL) "
112:                            + "VALUES (?,?,?,?)", new Parameterizer() {
113:                        public void parameterize(PreparedStatement ps)
114:                                throws SQLException {
115:                            ps.setString(1, constant.getValue());
116:                            SourceMarker sourceMarker = (SourceMarker) constant;
117:                            ps.setString(2, sourceMarker.getSourceURL());
118:                            ps.setInt(3, sourceMarker.getLine());
119:                            ps.setInt(4, sourceMarker.getColumn());
120:                        }
121:                    });
122:                } catch (SQLException e) {
123:                    context.warn((SourceMarker) constant, e);
124:                }
125:            }
126:
127:            public void leave(Repository repo) {
128:                final SQLProcessor processor = getContext().getSession()
129:                        .getProcessor();
130:                if (processor != null) {
131:                    context.annotate(new LinkedAnnotation() {
132:                        String path;
133:
134:                        public String getPath() {
135:                            return path;
136:                        }
137:
138:                        public String getName() {
139:                            return "String literals";
140:                        }
141:
142:                        public void render(AnnotationContext context)
143:                                throws HammurapiException {
144:                            FileEntry a = context.getNextFile(".html");
145:                            path = a.getPath();
146:                            try {
147:                                final Writer w = new FileWriter(a.getFile());
148:                                try {
149:                                    w
150:                                            .write("<HTML><BODY><TABLE border=\"1\"><TR><TH>Literal</TH><TH>File</TH><TH>Line</TH><TH>Column</TH></TR>");
151:                                    processor
152:                                            .processSelect(
153:                                                    "SELECT * FROM "
154:                                                            + tableName
155:                                                            + " ORDER BY LITERAL, SOURCE, LINE, COL",
156:                                                    null, new RowProcessor() {
157:                                                        public boolean process(
158:                                                                ResultSet rs)
159:                                                                throws SQLException {
160:                                                            try {
161:                                                                w
162:                                                                        .write("<TR><TD>");
163:                                                                w
164:                                                                        .write(rs
165:                                                                                .getString("LITERAL"));
166:                                                                w
167:                                                                        .write("</TD><TD>");
168:                                                                w
169:                                                                        .write(rs
170:                                                                                .getString("SOURCE"));
171:                                                                w
172:                                                                        .write("</TD><TD aligh=\"right\">");
173:                                                                w
174:                                                                        .write(rs
175:                                                                                .getString("LINE"));
176:                                                                w
177:                                                                        .write("</TD><TD aligh=\"right\">");
178:                                                                w
179:                                                                        .write(rs
180:                                                                                .getString("COL"));
181:                                                                w
182:                                                                        .write("</TD><TR>");
183:                                                                return true;
184:                                                            } catch (IOException e) {
185:                                                                throw new HammurapiRuntimeException(
186:                                                                        e);
187:                                                            }
188:                                                        }
189:                                                    });
190:
191:                                    w.write("</TABLE></BODY></HTML>");
192:                                } finally {
193:                                    w.close();
194:                                }
195:                            } catch (SQLException e) {
196:                                throw new HammurapiException(e);
197:                            } catch (HammurapiRuntimeException e) {
198:                                throw new HammurapiException(e.getCause());
199:                            } catch (IOException e) {
200:                                throw new HammurapiException(e);
201:                            }
202:                        }
203:
204:                        public Properties getProperties() {
205:                            return null;
206:                        }
207:                    });
208:                }
209:
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.