Source Code Cross Referenced for FindBugsMessagesReader.java in  » IDE » tIDE » tide » exttools » findbugs » 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 » IDE » tIDE » tide.exttools.findbugs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package tide.exttools.findbugs;
002:
003:        import java.util.*;
004:        import java.util.jar.JarFile;
005:        import java.util.zip.*;
006:        import java.io.*;
007:        import snow.utils.storage.FileUtils;
008:
009:        import org.xml.sax.*;
010:        import org.xml.sax.helpers.*;
011:        import org.xml.sax.SAXException;
012:        import javax.xml.parsers.SAXParser;
013:        import javax.xml.parsers.SAXParserFactory;
014:
015:        /** reads the messages from C:/Java/analysis_tools/findbugs/findbugs-1.2.0/plugin/coreplugin.jar
016:         */
017:        class FindBugsMessagesReader {
018:            final Map<String, BugDescription> bugTypes = new HashMap<String, BugDescription>();
019:            final Set<String> categories = new HashSet<String>();
020:
021:            public FindBugsMessagesReader() throws Exception {
022:                File f = new File(
023:                        "C:/Java/analysis_tools/findbugs/findbugs-1.2.0/plugin/coreplugin.jar");
024:                JarFile jarFile = new JarFile(f);
025:
026:                // information is distributed across several entries !
027:                ZipEntry ze = jarFile.getEntry("messages.xml");
028:                parse(jarFile, ze);
029:                ze = jarFile.getEntry("findbugs.xml");
030:                parse(jarFile, ze);
031:
032:                System.out.println(categories);
033:                System.out.println(bugTypes.values());
034:            }
035:
036:            public static void main(String[] arguments) throws Exception {
037:                new FindBugsMessagesReader();
038:            }
039:
040:            void parse(JarFile jarFile, ZipEntry ze) throws Exception {
041:                InputStream is = jarFile.getInputStream(ze);
042:                String cont = FileUtils.getStringContent(is);
043:                //System.out.println(""+cont.substring(0, 50000));
044:                // Use the default (non-validating) parser
045:                SAXParserFactory factory = SAXParserFactory.newInstance();
046:                SAXParser saxParser = factory.newSAXParser();
047:                //BufferedReader is = new BufferedReader(new StringReader(cont));
048:                InputSource iso = new InputSource(new StringReader(cont));
049:                BugTypesParser rp = new BugTypesParser();
050:                saxParser.parse(iso, rp);
051:                is.close();
052:            }
053:
054:            public class BugDescription {
055:                String category;
056:                String abbrev;
057:                final String type;
058:                String description;
059:                boolean experimental;
060:
061:                public BugDescription(String t) {
062:                    type = t;
063:                }
064:
065:                @Override
066:                public final String toString() {
067:                    StringBuilder sb = new StringBuilder();
068:                    sb.append("\n" + type);
069:                    sb.append(": ");
070:                    sb.append(abbrev);
071:                    sb.append(": ");
072:                    sb.append(category);
073:                    sb.append(": ");
074:                    if (experimental)
075:                        sb.append("(EXPERIMENTAL)");
076:                    sb.append(description);
077:
078:                    return sb.toString();
079:                }
080:            }
081:
082:            /** called once for messages.xml and once for findbugs.xml
083:             */
084:            class BugTypesParser extends DefaultHandler {
085:
086:                boolean isInPattern = false;
087:                StringBuilder lastChars = new StringBuilder();
088:                BugDescription actualBugDescription = null;
089:
090:                @Override
091:                public void startDocument() {
092:                }
093:
094:                @Override
095:                public void endDocument() {
096:                }
097:
098:                @Override
099:                public void startElement(String namespaceURI, String sName,
100:                        String qName, Attributes attributes)
101:                        throws SAXException {
102:                    // reset
103:                    lastChars.setLength(0);
104:                    if (qName.equalsIgnoreCase("BugCategory")) {
105:                        categories.add(attributes.getValue("category"));
106:                    } else if (qName.equalsIgnoreCase("BugPattern")) {
107:                        String type = attributes.getValue("type");
108:
109:                        if (bugTypes.containsKey(type)) {
110:                            actualBugDescription = bugTypes.get(type);
111:                        } else {
112:                            actualBugDescription = new BugDescription(type);
113:                            bugTypes.put(actualBugDescription.type,
114:                                    actualBugDescription);
115:                        }
116:
117:                        // found in findbugs.xml
118:                        if (attributes.getValue("abbrev") != null)
119:                            actualBugDescription.abbrev = attributes
120:                                    .getValue("abbrev");
121:                        if (attributes.getValue("category") != null)
122:                            actualBugDescription.category = attributes
123:                                    .getValue("category");
124:                        if (attributes.getValue("experimental") != null)
125:                            actualBugDescription.experimental = attributes
126:                                    .getValue("experimental").equalsIgnoreCase(
127:                                            "true");
128:
129:                        isInPattern = true;
130:                        lastChars.setLength(0);
131:                    }
132:                }
133:
134:                @Override
135:                public void endElement(String namespaceURI, String sName, // simple name
136:                        String qName // qualified name
137:                ) throws SAXException {
138:                    if (isInPattern) {
139:                        if (qName.equalsIgnoreCase("ShortDescription")) {
140:                            actualBugDescription.description = lastChars
141:                                    .toString().trim();
142:                            lastChars.setLength(0);
143:                        }
144:                    }
145:
146:                }
147:
148:                @Override
149:                public void characters(char[] buf, int offset, int len)
150:                        throws SAXException {
151:                    if (lastChars.length() > 0)
152:                        lastChars.append(" ");
153:                    lastChars.append(new String(buf, offset, len).trim());
154:                }
155:
156:            }
157:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.