Source Code Cross Referenced for LogFileParser.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » tools » tracesviewer » 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 » 6.0 JDK Modules » Java Advanced Imaging » tools.tracesviewer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package tools.tracesviewer;
002:
003:        //ifdef J2SDK1.4
004:        import javax.xml.parsers.SAXParser;
005:        import javax.xml.parsers.SAXParserFactory; //endif
006:
007:        import org.xml.sax.*;
008:        import org.xml.sax.helpers.DefaultHandler;
009:        import org.xml.sax.SAXException;
010:
011:        import java.io.*;
012:        import java.util.*;
013:
014:        /**
015:         * Parse the log files - sort them and organize by call id.
016:         */
017:        public class LogFileParser extends DefaultHandler {
018:            protected Hashtable messageLogs;
019:
020:            private XMLReader xmlReader;
021:
022:            private String transactionId;
023:
024:            private String from;
025:
026:            private String to;
027:
028:            private String time;
029:
030:            private String statusMessage;
031:
032:            private String firstLine;
033:
034:            private String callId;
035:
036:            private String isSender;
037:
038:            private String messageTimeStamp;
039:
040:            private StringBuffer message;
041:
042:            public String logDescription;
043:
044:            public String auxInfo;
045:
046:            public String logName;
047:
048:            private String currentTag;
049:
050:            private String debugLine;
051:
052:            private String previousDebug = null;
053:
054:            private TracesMessage messageLog;
055:
056:            public LogFileParser() {
057:                messageLogs = new Hashtable();
058:                try {
059:                    SAXParserFactory saxParserFactory = SAXParserFactory
060:                            .newInstance();
061:                    SAXParser saxParser = saxParserFactory.newSAXParser();
062:                    this .xmlReader = saxParser.getXMLReader();
063:
064:                    xmlReader.setContentHandler(this );
065:
066:                    xmlReader.setFeature(
067:                            "http://xml.org/sax/features/validation", false);
068:                    // parse the xml specification for the event tags.
069:
070:                } catch (Exception pce) {
071:                    // Parser with specified options can't be built
072:                    pce.printStackTrace();
073:                }
074:
075:            }
076:
077:            public Hashtable parseLogs(InputSource inputSource) {
078:                try {
079:                    this .xmlReader.parse(inputSource);
080:                    return messageLogs;
081:                } catch (SAXParseException spe) {
082:                    spe.printStackTrace();
083:                } catch (SAXException sxe) {
084:                    sxe.printStackTrace();
085:                } catch (IOException ioe) {
086:                    // I/O error
087:                    ioe.printStackTrace();
088:                }
089:                return messageLogs;
090:            }
091:
092:            // ===========================================================
093:            // SAX DocumentHandler methods
094:            // ===========================================================
095:
096:            public void startDocument() throws SAXException {
097:            }
098:
099:            public void endDocument() throws SAXException {
100:            }
101:
102:            public void startElement(String namespaceURI, String lName, // local name
103:                    String qName, // qualified name
104:                    Attributes attrs) throws SAXException {
105:                currentTag = qName;
106:
107:                // System.out.println("currentTag:"+currentTag);
108:                if (qName.equalsIgnoreCase("debug")) {
109:
110:                }
111:                if (qName.equalsIgnoreCase("message")) {
112:                    from = attrs.getValue("from");
113:                    to = attrs.getValue("to");
114:                    time = attrs.getValue("time");
115:                    statusMessage = attrs.getValue("statusMessage");
116:                    transactionId = attrs.getValue("transactionId");
117:                    firstLine = attrs.getValue("firstLine");
118:                    callId = attrs.getValue("callId");
119:                    isSender = attrs.getValue("isSender");
120:                    debugLine = attrs.getValue("debugLine");
121:                    messageTimeStamp = attrs.getValue("timeStamp");
122:                    message = new StringBuffer();
123:
124:                }
125:                if (qName.equalsIgnoreCase("description")) {
126:                    logName = attrs.getValue("name");
127:                    logDescription = attrs.getValue("logDescription");
128:                    auxInfo = attrs.getValue("auxInfo");
129:                }
130:
131:            }
132:
133:            public void endElement(String namespaceURI, String sName, // simple name
134:                    String qName // qualified name
135:            ) throws SAXException {
136:                if (qName.equalsIgnoreCase("message")) {
137:                    boolean sflag = isSender.equals("true");
138:                    messageLog = new TracesMessage(from, to, time, firstLine,
139:                            message.toString(), statusMessage, transactionId,
140:                            messageTimeStamp, debugLine);
141:
142:                    MessageLogList messageLogList = (MessageLogList) messageLogs
143:                            .get(callId);
144:                    if (messageLogList == null) {
145:                        messageLogList = new MessageLogList(new LogComparator());
146:                        messageLogs.put(callId, messageLogList);
147:                    }
148:                    if (!messageLogList.contains(messageLog))
149:                        messageLogList.add(messageLog);
150:                }
151:            }
152:
153:            public void characters(char buf[], int offset, int len)
154:                    throws SAXException {
155:                if (buf == null)
156:                    return;
157:
158:                if (currentTag.equalsIgnoreCase("message")) {
159:                    // StringBuffer s = new StringBuffer();
160:                    // s.append(new String(buf, offset, len));
161:
162:                    String str = new String(buf, offset, len); // s.toString().trim();
163:
164:                    if (str.equals(""))
165:                        return;
166:                    message.append(str);
167:
168:                }
169:
170:                if (currentTag.equalsIgnoreCase("debug")) {
171:                    StringBuffer s = new StringBuffer();
172:                    s.append(new String(buf, offset, len));
173:                    String str = s.toString().trim();
174:
175:                    if (str.equals(""))
176:                        return;
177:
178:                    // System.out.println("cdata:"+str);
179:
180:                    if (messageLog != null) {
181:                        messageLog.beforeDebug = previousDebug;
182:                        // System.out.println("messageLog.beforeDebug:"+messageLog.beforeDebug);
183:                        messageLog.afterDebug = str;
184:                        // System.out.println("messageLog.afterDebug:"+messageLog.afterDebug);
185:                        previousDebug = str;
186:                    } else {
187:                        previousDebug = str;
188:                    }
189:                }
190:            }
191:
192:            /**
193:             * Generate a file that can be digested by the trace viewer.
194:             */
195:            public Hashtable parseLogsFromDebugFile(String logFileName) {
196:                try {
197:
198:                    // FileWriter fw=new FileWriter(logFileName);
199:                    // fw.write("]]></debug>");
200:                    File file = new File(logFileName);
201:                    long length = file.length();
202:                    char[] cbuf = new char[(int) length];
203:                    FileReader fr = new FileReader(file);
204:                    fr.read(cbuf);
205:                    fr.close();
206:
207:                    StringBuffer sb = new StringBuffer();
208:                    sb.append("<?xml version='1.0' encoding='us-ascii'?>\n")
209:                            .append("<messages>\n").append(new String(cbuf))
210:                            .append("]]></debug></messages>\n");
211:
212:                    // System.out.println(sb.toString());
213:
214:                    InputSource inputSource = new InputSource(
215:                            new ByteArrayInputStream(sb.toString().getBytes()));
216:                    return this .parseLogs(inputSource);
217:                } catch (IOException ex) {
218:                    ex.printStackTrace();
219:
220:                    return null;
221:                }
222:            }
223:
224:            /**
225:             * Generate a file that can be digested by the trace viewer.
226:             */
227:            public Hashtable parseLogsFromFile(String logFileName) {
228:                try {
229:
230:                    // FileWriter fw=new FileWriter(logFileName);
231:                    // fw.write("]]></debug>");
232:                    File file = new File(logFileName);
233:                    long length = file.length();
234:                    char[] cbuf = new char[(int) length];
235:                    FileReader fr = new FileReader(file);
236:                    fr.read(cbuf);
237:                    fr.close();
238:
239:                    StringBuffer sb = new StringBuffer();
240:                    sb.append("<?xml version='1.0' encoding='us-ascii'?>\n")
241:                            .append("<messages>\n").append(new String(cbuf))
242:                            .append("</messages>\n");
243:
244:                    System.out.println(sb.toString());
245:
246:                    InputSource inputSource = new InputSource(
247:                            new ByteArrayInputStream(sb.toString().getBytes()));
248:                    return this .parseLogs(inputSource);
249:                } catch (IOException ex) {
250:                    ex.printStackTrace();
251:
252:                    return null;
253:                }
254:            }
255:
256:            public Hashtable parseLogsFromString(String logString) {
257:                StringBuffer sb = new StringBuffer();
258:                sb.append("<?xml version='1.0' encoding='us-ascii'?>\n")
259:                        .append("<messages>\n").append(logString).append(
260:                                "</messages>\n");
261:                // System.out.println(sb.toString());
262:                InputSource inputSource = new InputSource(
263:                        new ByteArrayInputStream(sb.toString().getBytes()));
264:                return this.parseLogs(inputSource);
265:            }
266:
267:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.