Source Code Cross Referenced for LogalizerHandler.java in  » Search-Engine » yacy » de » anomic » server » logging » 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 » Search Engine » yacy » de.anomic.server.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //LogalizerHandler.java 
002:        //-------------------------------------
003:        //part of YACY
004:        //(C) by Michael Peter Christen; mc@anomic.de
005:        //first published on http://www.anomic.de
006:        //Frankfurt, Germany, 2004
007:        //
008:        //This file ist contributed by Matthias Soehnholz
009:        //last major change: $LastChangedDate: 2008-01-23 23:08:32 +0000 (Mi, 23 Jan 2008) $ by $LastChangedBy: orbiter $
010:        //Revision: $LastChangedRevision: 4382 $
011:        //
012:        //This program is free software; you can redistribute it and/or modify
013:        //it under the terms of the GNU General Public License as published by
014:        //the Free Software Foundation; either version 2 of the License, or
015:        //(at your option) any later version.
016:        //
017:        //This program is distributed in the hope that it will be useful,
018:        //but WITHOUT ANY WARRANTY; without even the implied warranty of
019:        //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
020:        //GNU General Public License for more details.
021:        //
022:        //You should have received a copy of the GNU General Public License
023:        //along with this program; if not, write to the Free Software
024:        //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
025:        //
026:        //Using this software in any meaning (reading, learning, copying, compiling,
027:        //running) means that you agree that the Author(s) is (are) not responsible
028:        //for cost, loss of data or any harm that may be caused directly or indirectly
029:        //by usage of this softare or this documentation. The usage of this software
030:        //is on your own risk. The installation and usage (starting/running) of this
031:        //software may allow other people or application to access your computer and
032:        //any attached devices and is highly dependent on the configuration of the
033:        //software which must be done by the user of the software; the author(s) is
034:        //(are) also not responsible for proper configuration and usage of the
035:        //software, even if provoked by documentation provided together with
036:        //the software.
037:        //
038:        //Any changes to this file according to the GPL as documented in the file
039:        //gpl.txt aside this file in the shipment you received can be done to the
040:        //lines that follows this copyright notice here, but changes must not be
041:        //done inside the copyright notive above. A re-distribution must contain
042:        //the intact and unchanged copyright notice.
043:        //Contributions and changes to the program code must be marked as such.
044:
045:        package de.anomic.server.logging;
046:
047:        import java.io.File;
048:        import java.io.FilenameFilter;
049:        import java.net.URI;
050:        import java.net.URISyntaxException;
051:        import java.util.HashMap;
052:        import java.util.Hashtable;
053:        import java.util.Iterator;
054:        import java.util.Set;
055:        import java.util.logging.Handler;
056:        import java.util.logging.LogManager;
057:        import java.util.logging.LogRecord;
058:
059:        import de.anomic.plasma.plasmaParser;
060:        import de.anomic.server.logging.logParsers.LogParser;
061:
062:        public class LogalizerHandler extends Handler {
063:
064:            public static boolean enabled = false;
065:            public static boolean debug = false;
066:            private String logParserPackage;
067:            private HashMap<String, Object> parsers;
068:
069:            public LogalizerHandler() {
070:                super ();
071:                configure();
072:            }
073:
074:            private HashMap<String, Object> loadParsers() {
075:                HashMap<String, Object> parsers = new HashMap<String, Object>();
076:                try {
077:                    if (debug)
078:                        System.out
079:                                .println("Searching for additional content parsers in package "
080:                                        + logParserPackage);
081:                    // getting an uri to the parser subpackage
082:                    String packageURI = plasmaParser.class.getResource(
083:                            "/" + logParserPackage.replace('.', '/'))
084:                            .toString();
085:                    if (debug)
086:                        System.out.println("LogParser directory is "
087:                                + packageURI);
088:
089:                    File parserDir = new File(new URI(packageURI));
090:                    //System.out.println(parserDir.toString());
091:                    String[] parserDirFiles = parserDir.list(parserNameFilter);
092:                    if (parserDirFiles == null && debug) {
093:                        System.out.println("Can't find any parsers in "
094:                                + parserDir.getAbsolutePath());
095:                    }
096:                    //System.out.println(parserDirFiles.length);
097:                    for (int i = 0; i < parserDirFiles.length; i++) {
098:                        String tmp = parserDirFiles[i].substring(0,
099:                                parserDirFiles[i].indexOf(".class"));
100:                        Class<?> tempClass = Class.forName(logParserPackage
101:                                + "." + tmp);
102:                        if (tempClass.isInterface()) {
103:                            if (debug)
104:                                System.out.println(tempClass.getName()
105:                                        + " is an Interface");
106:                        } else {
107:                            Object theParser = tempClass.newInstance();
108:                            if (theParser instanceof  LogParser) {
109:                                LogParser theLogParser = (LogParser) theParser;
110:                                //System.out.println(bla.getName() + " is a logParser");
111:                                parsers.put(theLogParser.getParserType(),
112:                                        theParser);
113:
114:                                if (debug)
115:                                    System.out.println("Added "
116:                                            + theLogParser.getClass().getName()
117:                                            + " as "
118:                                            + theLogParser.getParserType()
119:                                            + " Parser.");
120:                            } else {
121:                                //System.out.println(bla.getName() + " is not a logParser");
122:                                if (debug)
123:                                    System.out
124:                                            .println("Rejected "
125:                                                    + tempClass.getName()
126:                                                    + ". Class does not implement the logParser-Interface");
127:
128:                            }
129:                        }
130:                    }
131:                } catch (ClassNotFoundException e) {
132:                    e.printStackTrace();
133:                } catch (InstantiationException e) {
134:                    e.printStackTrace();
135:                } catch (IllegalAccessException e) {
136:                    e.printStackTrace();
137:                } catch (URISyntaxException e) {
138:                    e.printStackTrace();
139:                }
140:                return parsers;
141:            }
142:
143:            /**
144:             * Get any configuration properties set
145:             */
146:            private void configure() {
147:                LogManager manager = LogManager.getLogManager();
148:                String className = getClass().getName();
149:
150:                if (manager.getProperty(className + ".enabled")
151:                        .equalsIgnoreCase("true"))
152:                    enabled = true;
153:                if (manager.getProperty(className + ".debug").equalsIgnoreCase(
154:                        "true"))
155:                    debug = true;
156:
157:                logParserPackage = manager.getProperty(className
158:                        + ".parserPackage");
159:
160:                parsers = loadParsers();
161:            }
162:
163:            public void publish(LogRecord record) {
164:                if (enabled) {
165:                    LogParser temp = (LogParser) parsers.get(record
166:                            .getLoggerName());
167:                    if (temp != null) {
168:                        int returnV = temp.parse(record.getLevel().toString(),
169:                                record.getMessage());
170:                        //if (debug) System.out.println("Logalizertest: " + returnV + " --- " + record.getLevel() + " --- " + record.getMessage());
171:                        if (debug)
172:                            System.out.println("Logalizertest: " + returnV
173:                                    + " --- " + record.getLevel());
174:                    }
175:                }
176:            }
177:
178:            public Set<String> getParserNames() {
179:                return parsers.keySet();
180:            }
181:
182:            public LogParser getParser(int number) {
183:                String o;
184:                Iterator<String> it = parsers.keySet().iterator();
185:                int i = 0;
186:                while (it.hasNext()) {
187:                    o = it.next();
188:                    if (i++ == number)
189:                        return (LogParser) parsers.get(o);
190:                }
191:                return null;
192:            }
193:
194:            public Hashtable<String, Object> getParserResults(
195:                    LogParser parsername) {
196:                return parsername.getResults();
197:            }
198:
199:            public void close() throws SecurityException {
200:                // TODO Auto-generated method stub
201:
202:            }
203:
204:            public void flush() {
205:                // TODO Auto-generated method stub
206:
207:            }
208:
209:            private static final FilenameFilter parserNameFilter = new FilenameFilter() {
210:                public boolean accept(File dir, String name) {
211:                    return name.matches(".*.class");
212:                }
213:            };
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.