Source Code Cross Referenced for FilterLog.java in  » Portal » Open-Portal » com » sun » portal » search » robot » 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 » Portal » Open Portal » com.sun.portal.search.robot 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:
006:        package com.sun.portal.search.robot;
007:
008:        import java.lang.*;
009:        import java.io.*;
010:        import java.util.*;
011:        import java.text.*;
012:
013:        public class FilterLog {
014:            public static DateFormat df = new SimpleDateFormat(
015:                    "dd/MMM/yyyy:HH:mm:ss", Locale.US);
016:            public static DateFormat listdf = new SimpleDateFormat(
017:                    "dd/MMM -  HH:mm:ss");
018:            protected ArrayList runList = new ArrayList();
019:            protected PrintWriter debug = null;
020:            private String dateStr = null;
021:            private String reasonStr = null;
022:            private int reasonIndex = -1;
023:            private Hashtable ExReasons = new Hashtable();
024:            private ArrayList ExReasonsArray = new ArrayList();
025:            private ArrayList FilteredList = new ArrayList();
026:            private int total = 0;
027:
028:            static public void main(String[] args) {
029:                FilterLog filterLog = null;
030:                if (args.length == 1) {
031:                    filterLog = new FilterLog(args[0]);
032:                } else if (args.length == 2) {
033:                    filterLog = new FilterLog(args[0], args[1]);
034:                } else if (args.length == 3) {
035:                    filterLog = new FilterLog(args[0], args[1], args[2]);
036:                } else {
037:                    System.out
038:                            .println("Usage:FilterLog filterLogPath [selectedDate [selectedReason]]");
039:                    return;
040:                }
041:
042:                filterLog.printResult(System.out);
043:            }
044:
045:            public FilterLog(String file, PrintWriter out) {
046:                debug = out;
047:                out.println("FilterLog debug enabled");
048:                parserFilterLog(file);
049:            }
050:
051:            public FilterLog(String file, String date, PrintWriter out) {
052:                debug = out;
053:                dateStr = date;
054:                out.println("FilterLog debug enabled");
055:                parserFilterLog(file);
056:            }
057:
058:            public FilterLog(String file, String date, String reason,
059:                    PrintWriter out) {
060:                debug = out;
061:                dateStr = date;
062:                reasonStr = reason;
063:                out.println("FilterLog debug enabled");
064:                parserFilterLog(file);
065:            }
066:
067:            public FilterLog(String file) {
068:                parserFilterLog(file);
069:            }
070:
071:            public FilterLog(String file, String date) {
072:                dateStr = date;
073:                parserFilterLog(file);
074:            }
075:
076:            public FilterLog(String file, String date, String reason) {
077:                dateStr = date;
078:                reasonStr = reason;
079:                parserFilterLog(file);
080:            }
081:
082:            public FilterLog(String file, String date, int reason) {
083:                dateStr = date;
084:                reasonIndex = reason;
085:                parserFilterLog(file);
086:            }
087:
088:            public void parserFilterLog(String filterlog_path) {
089:                BufferedReader in = null;
090:                String oldline = null;
091:                String line = null;
092:                String preLine = null;
093:                Date date = null;
094:                boolean inSelectedDate = false;
095:                boolean inSelectedReason = false;
096:                int lineNum = 0; // line number starts with 1
097:                try {
098:                    in = new BufferedReader(new InputStreamReader(
099:                            new FileInputStream(filterlog_path), "ISO-8859-1"));
100:                    while ((oldline = in.readLine()) != null) {
101:                        lineNum++;
102:                        try {
103:                            line = new String(oldline.getBytes("ISO-8859-1"),
104:                                    "UTF-8");
105:                        } catch (Exception e) {
106:                            continue;
107:                        }
108:                        // expecting
109:                        //[22/Jan/2002:10:48:19]  9883@001:	 Filter log started
110:                        if (line.startsWith("[") /*|| line.startsWith("Time:")*/) {
111:                            int start = line.indexOf('[');
112:                            int end = line.indexOf(']');
113:                            if (start >= 0 && end > start) {
114:                                String datestr = line.substring(start + 1, end);
115:                                try {
116:                                    date = df.parse(datestr);
117:                                    if (debug != null) {
118:                                        debug.println("add date : "
119:                                                + df.format(date));
120:                                    }
121:                                    runList.add(date);
122:                                    if (dateStr != null
123:                                            && datestr.compareTo(dateStr) == 0) {
124:                                        inSelectedDate = true;
125:                                    } else {
126:                                        inSelectedDate = false;
127:                                    }
128:                                } catch (ParseException e) {
129:                                    if (debug != null) {
130:                                        debug
131:                                                .println("ParseException at position("
132:                                                        + e.getErrorOffset()
133:                                                        + ")");
134:                                        debug.println(line);
135:                                    } else {
136:                                        System.out
137:                                                .println("ParseException at position("
138:                                                        + e.getErrorOffset()
139:                                                        + ")");
140:                                        System.out.println(line);
141:                                    }
142:                                }
143:                            }
144:                        } else if (inSelectedDate && line.startsWith("Hint:")) {
145:                            String hint = line.substring(5).trim();
146:                            if (hint.startsWith("File Not Found.")) {
147:                                hint = "File Not Found.";
148:                            }
149:                            if (preLine != null) {
150:                                int c = 1;
151:                                if (ExReasons.containsKey(hint)) {
152:                                    Integer count = (Integer) ExReasons
153:                                            .get(hint);
154:                                    c = count.intValue();
155:                                    c++;
156:                                    ExReasons.put(hint, new Integer(c));
157:                                } else {
158:                                    ExReasons.put(hint, new Integer(c));
159:                                    ExReasonsArray.add(hint);
160:                                }
161:                                total++;
162:                                if ((reasonStr != null && reasonStr
163:                                        .compareToIgnoreCase(hint) == 0)
164:                                        || ((reasonIndex >= 0
165:                                                && ExReasonsArray.size() > reasonIndex && ((String) ExReasonsArray
166:                                                .get(reasonIndex))
167:                                                .compareToIgnoreCase(hint) == 0))) {
168:                                    FilteredList.add(preLine);
169:                                }
170:                                preLine = null;
171:                            }
172:                        } else if (inSelectedDate) {
173:                            preLine = line;
174:                        }
175:                    }
176:                } catch (IOException e) {
177:                    if (debug != null) {
178:                        debug.println("IOException:" + e.getMessage()
179:                                + " at line# " + lineNum);
180:                    } else {
181:                        System.out.println("IOException:" + e.getMessage()
182:                                + " at line# " + lineNum);
183:                    }
184:                }
185:            }
186:
187:            /*    public void printRunList(PrintWriter out)
188:             {
189:             for (int i=0; i < runList.size(); i++) {
190:             out.println(i + " run - " + listdf.format((Date)runList.get(i)) );
191:             }
192:             }
193:             */
194:            public void printResult(PrintStream out) {
195:                for (int i = 0; i < runList.size(); i++) {
196:                    out.println(i + " run - "
197:                            + listdf.format((Date) runList.get(i)));
198:                }
199:                if (dateStr != null) {
200:                    Enumeration e = ExReasons.keys();
201:                    while (e.hasMoreElements()) {
202:                        String reason = (String) e.nextElement();
203:                        Integer count = (Integer) ExReasons.get(reason);
204:                        out.println(reason + ":" + count);
205:                    }
206:                    if (reasonStr != null) {
207:                        for (int i = 0; i < FilteredList.size(); i++) {
208:                            out.println((String) FilteredList.get(i));
209:                        }
210:                    }
211:                }
212:
213:            }
214:
215:            public Object[] getRunArray() {
216:                return runList.toArray();
217:            }
218:
219:            public ArrayList getRunArrayList() {
220:                return runList;
221:            }
222:
223:            public void setDebug(PrintWriter out) {
224:                debug = out;
225:            }
226:
227:            public String[] getReasons() {
228:                return (String[]) ExReasonsArray.toArray(new String[0]);
229:            }
230:
231:            public int getReasonSubTotal(String reason) {
232:                if (ExReasons != null) {
233:                    Integer count = (Integer) ExReasons.get(reason);
234:                    return count.intValue();
235:                }
236:                return 0;
237:            }
238:
239:            public ArrayList getFilteredURL() {
240:                return FilteredList;
241:            }
242:
243:            public String getReason() {
244:                return reasonStr;
245:            }
246:
247:            public String getReasonByIndex(int index) {
248:                try {
249:                    return (String) ExReasonsArray.get(index);
250:                } catch (Exception e) {
251:                    return null;
252:                }
253:            }
254:
255:            public int getTotal() {
256:                return total;
257:            }
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.