Source Code Cross Referenced for LogReader.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » runtime » logview » 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 Eclipse » Eclipse plug in development » org.eclipse.pde.internal.runtime.logview 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.pde.internal.runtime.logview;
011:
012:        import java.io.BufferedReader;
013:        import java.io.File;
014:        import java.io.FileNotFoundException;
015:        import java.io.IOException;
016:        import java.io.InputStreamReader;
017:        import java.io.PrintWriter;
018:        import java.io.StringWriter;
019:        import java.util.ArrayList;
020:        import java.util.Date;
021:
022:        import org.eclipse.core.runtime.IStatus;
023:        import org.eclipse.ui.IMemento;
024:
025:        class LogReader {
026:            private static final int SESSION_STATE = 10;
027:            public static final long MAX_FILE_LENGTH = 1024 * 1024;
028:            private static final int ENTRY_STATE = 20;
029:            private static final int SUBENTRY_STATE = 30;
030:            private static final int MESSAGE_STATE = 40;
031:            private static final int STACK_STATE = 50;
032:            private static final int TEXT_STATE = 60;
033:            private static final int UNKNOWN_STATE = 70;
034:
035:            private static LogSession currentSession;
036:
037:            public static void parseLogFile(File file, ArrayList entries,
038:                    IMemento memento) {
039:                ArrayList parents = new ArrayList();
040:                LogEntry current = null;
041:                LogSession session = null;
042:                int writerState = UNKNOWN_STATE;
043:                StringWriter swriter = null;
044:                PrintWriter writer = null;
045:                int state = UNKNOWN_STATE;
046:                currentSession = null;
047:                BufferedReader reader = null;
048:                try {
049:
050:                    reader = new BufferedReader(
051:                            new InputStreamReader(new TailInputStream(file,
052:                                    MAX_FILE_LENGTH), "UTF-8")); //$NON-NLS-1$
053:                    for (;;) {
054:                        String line = reader.readLine();
055:                        if (line == null)
056:                            break;
057:                        line = line.trim();
058:                        if (line.length() == 0)
059:                            continue;
060:
061:                        if (line.startsWith("!SESSION")) { //$NON-NLS-1$
062:                            state = SESSION_STATE;
063:                        } else if (line.startsWith("!ENTRY")) { //$NON-NLS-1$
064:                            state = ENTRY_STATE;
065:                        } else if (line.startsWith("!SUBENTRY")) { //$NON-NLS-1$
066:                            state = SUBENTRY_STATE;
067:                        } else if (line.startsWith("!MESSAGE")) { //$NON-NLS-1$
068:                            state = MESSAGE_STATE;
069:                        } else if (line.startsWith("!STACK")) { //$NON-NLS-1$
070:                            state = STACK_STATE;
071:                        } else
072:                            state = TEXT_STATE;
073:
074:                        if (state == TEXT_STATE) {
075:                            if (writer != null)
076:                                writer.println(line);
077:                            continue;
078:                        }
079:
080:                        if (writer != null) {
081:                            if (writerState == STACK_STATE && current != null) {
082:                                current.setStack(swriter.toString());
083:                            } else if (writerState == SESSION_STATE
084:                                    && session != null) {
085:                                session.setSessionData(swriter.toString());
086:                            } else if (writerState == MESSAGE_STATE
087:                                    && current != null) {
088:                                StringBuffer sb = new StringBuffer(current
089:                                        .getMessage());
090:                                sb.append(swriter.toString());
091:                                current.setMessage(sb.toString().trim());
092:                            }
093:                            writerState = UNKNOWN_STATE;
094:                            swriter = null;
095:                            writer.close();
096:                            writer = null;
097:                        }
098:
099:                        if (state == STACK_STATE) {
100:                            swriter = new StringWriter();
101:                            writer = new PrintWriter(swriter, true);
102:                            writerState = STACK_STATE;
103:                        } else if (state == SESSION_STATE) {
104:                            session = new LogSession();
105:                            session.processLogLine(line);
106:                            swriter = new StringWriter();
107:                            writer = new PrintWriter(swriter, true);
108:                            writerState = SESSION_STATE;
109:                            updateCurrentSession(session);
110:                            if (!currentSession.equals(session)
111:                                    && !memento.getString(
112:                                            LogView.P_SHOW_ALL_SESSIONS)
113:                                            .equals("true")) //$NON-NLS-1$
114:                                entries.clear();
115:                        } else if (state == ENTRY_STATE) {
116:                            LogEntry entry = new LogEntry();
117:                            entry.setSession(session);
118:                            entry.processEntry(line);
119:                            setNewParent(parents, entry, 0);
120:                            current = entry;
121:                            addEntry(current, entries, memento, false);
122:                        } else if (state == SUBENTRY_STATE) {
123:                            if (parents.size() > 0) {
124:                                LogEntry entry = new LogEntry();
125:                                entry.setSession(session);
126:                                int depth = entry.processSubEntry(line);
127:                                setNewParent(parents, entry, depth);
128:                                current = entry;
129:                                LogEntry parent = (LogEntry) parents
130:                                        .get(depth - 1);
131:                                parent.addChild(entry);
132:                            }
133:                        } else if (state == MESSAGE_STATE) {
134:                            swriter = new StringWriter();
135:                            writer = new PrintWriter(swriter, true);
136:                            String message = ""; //$NON-NLS-1$
137:                            if (line.length() > 8)
138:                                message = line.substring(9).trim();
139:                            message = message.trim();
140:                            if (current != null)
141:                                current.setMessage(message);
142:                            writerState = MESSAGE_STATE;
143:                        }
144:                    }
145:
146:                    if (swriter != null && current != null
147:                            && writerState == STACK_STATE)
148:                        current.setStack(swriter.toString());
149:                } catch (FileNotFoundException e) {
150:                } catch (IOException e) {
151:                } finally {
152:                    try {
153:                        if (reader != null)
154:                            reader.close();
155:                    } catch (IOException e1) {
156:                    }
157:                    if (writer != null)
158:                        writer.close();
159:                }
160:            }
161:
162:            private static void updateCurrentSession(LogSession session) {
163:                if (currentSession == null) {
164:                    currentSession = session;
165:                    return;
166:                }
167:                Date currentDate = currentSession.getDate();
168:                Date sessionDate = session.getDate();
169:                if (currentDate == null && sessionDate != null)
170:                    currentSession = session;
171:                else if (currentDate != null && sessionDate == null)
172:                    currentSession = session;
173:                else if (currentDate != null && sessionDate != null
174:                        && sessionDate.after(currentDate))
175:                    currentSession = session;
176:            }
177:
178:            public synchronized static void addEntry(LogEntry current,
179:                    ArrayList entries, IMemento memento,
180:                    boolean useCurrentSession) {
181:                int severity = current.getSeverity();
182:                boolean doAdd = true;
183:                switch (severity) {
184:                case IStatus.INFO:
185:                    doAdd = memento.getString(LogView.P_LOG_INFO)
186:                            .equals("true"); //$NON-NLS-1$
187:                    break;
188:                case IStatus.WARNING:
189:                    doAdd = memento.getString(LogView.P_LOG_WARNING).equals(
190:                            "true"); //$NON-NLS-1$
191:                    break;
192:                case IStatus.ERROR:
193:                    doAdd = memento.getString(LogView.P_LOG_ERROR).equals(
194:                            "true"); //$NON-NLS-1$
195:                    break;
196:                }
197:                if (doAdd) {
198:                    if (useCurrentSession)
199:                        current.setSession(currentSession);
200:                    entries.add(0, current);
201:
202:                    if (memento.getString(LogView.P_USE_LIMIT).equals("true") //$NON-NLS-1$
203:                            && entries.size() > memento.getInteger(
204:                                    LogView.P_LOG_LIMIT).intValue())
205:                        entries.remove(entries.size() - 1);
206:                }
207:            }
208:
209:            private static void setNewParent(ArrayList parents, LogEntry entry,
210:                    int depth) {
211:                if (depth + 1 > parents.size())
212:                    parents.add(entry);
213:                else
214:                    parents.set(depth, entry);
215:            }
216:
217:            public static void reset() {
218:                currentSession = null;
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.