Source Code Cross Referenced for XMLLogPropertyReader.java in  » J2EE » jag » com » finalist » util » log » 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 » J2EE » jag » com.finalist.util.log 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*   Copyright (C) 2003 Finalist IT Group
002:         *
003:         *   This file is part of JAG - the Java J2EE Application Generator
004:         *
005:         *   JAG is free software; you can redistribute it and/or modify
006:         *   it under the terms of the GNU General Public License as published by
007:         *   the Free Software Foundation; either version 2 of the License, or
008:         *   (at your option) any later version.
009:         *   JAG is distributed in the hope that it will be useful,
010:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         *   GNU General Public License for more details.
013:         *   You should have received a copy of the GNU General Public License
014:         *   along with JAG; if not, write to the Free Software
015:         *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
016:         */
017:
018:        package com.finalist.util.log;
019:
020:        import org.xml.sax.InputSource;
021:        import org.w3c.dom.Document;
022:        import org.w3c.dom.Element;
023:        import org.w3c.dom.NodeList;
024:        import org.w3c.dom.NamedNodeMap;
025:        import org.w3c.dom.Node;
026:
027:        // jaxp 1.0.1 imports
028:        import javax.xml.parsers.DocumentBuilderFactory;
029:        import javax.xml.parsers.DocumentBuilder;
030:
031:        import java.net.URL;
032:        import java.util.HashMap;
033:
034:        import com.finalist.util.PropertyReader;
035:
036:        /**
037:         * This class is an helper class for retrieve log settings from an xml file
038:         * @author Ronald Kramp - Finalist IT Group
039:         * @version $Revision: 1.1 $, $Date: 2004/11/12 14:06:44 $
040:         */
041:        public class XMLLogPropertyReader {
042:
043:            /** name for the appender tag in the xml file */
044:            public static final String APPENDER = "appender";
045:
046:            /** name for the name attribute of the appender in the xml file */
047:            public static final String NAME = "name";
048:
049:            /** name for the logfile attribute of the appender in the xml file */
050:            public static final String LOG_FILE = "logfile";
051:
052:            /** name for the append attribute of the appender in the xml file */
053:            public static final String APPEND = "append";
054:
055:            /** name for the maxbackupindex attribute of the appender in the xml file */
056:            public static final String MAX_BACKUP_INDEX = "maxbackupindex";
057:
058:            /** name for the maxfilesize attribute of the appender in the xml file */
059:            public static final String MAX_FILE_SIZE = "maxfilesize";
060:
061:            /** name for the shownumberoflastpackages attribute of the appender in the xml file */
062:            public static final String SHOW_NUMBER_OF_LAST_PACKAGES = "shownumberoflastpackages";
063:
064:            /** name for the datepattern attribute of the appender in the xml file */
065:            public static final String DATE_PATTERN = "datepattern";
066:
067:            /** name for the messageseparator attribute of the appender in the xml file */
068:            public static final String MESSAGE_SEPARATOR = "messageseparator";
069:
070:            /** name for the loglevel attribute of the appender in the xml file */
071:            public static final String LOG_LEVEL = "loglevel";
072:
073:            /**
074:             * Retrieving all appender setting from a configuration file.
075:             * @param location the directory + filename where to find the log configuration xml file
076:             * @return HashMap all log configurations
077:             */
078:            public static HashMap getLogConfigs(String location) {
079:                HashMap logConfigs = new HashMap();
080:                try {
081:                    //URL url = PropertyReader.getPropertiesURL(location);
082:                    URL url = PropertyReader.getPropertiesURL(location);
083:                    InputSource xmlInp = new InputSource(url.openStream());
084:                    Document doc = DocumentBuilderFactory.newInstance()
085:                            .newDocumentBuilder().parse(xmlInp);
086:                    NodeList appenders = doc.getElementsByTagName(APPENDER);
087:                    for (int i = 0; i < appenders.getLength(); i++) {
088:                        Node curNode = appenders.item(i);
089:                        if (curNode.getNodeName().equals(APPENDER)) {
090:                            NamedNodeMap nnm = curNode.getAttributes();
091:                            String appenderName = nnm.getNamedItem(NAME)
092:                                    .getNodeValue();
093:                            String logFile = nnm.getNamedItem(LOG_FILE)
094:                                    .getNodeValue();
095:                            String append = nnm.getNamedItem(APPEND)
096:                                    .getNodeValue();
097:
098:                            String maxBackupIndexString = nnm.getNamedItem(
099:                                    MAX_BACKUP_INDEX).getNodeValue();
100:                            int maxBackupIndex = -1;
101:                            try {
102:                                maxBackupIndex = Integer
103:                                        .parseInt(maxBackupIndexString);
104:                            } catch (Exception e) {
105:                                System.out
106:                                        .println("Incorrect number for maxBackupIndex with appender: "
107:                                                + appenderName + ": " + e);
108:                            }
109:
110:                            String maxFileSizeString = nnm.getNamedItem(
111:                                    MAX_FILE_SIZE).getNodeValue();
112:                            int maxFileSize = -1;
113:                            try {
114:                                maxFileSize = Integer
115:                                        .parseInt(maxFileSizeString);
116:                            } catch (Exception e) {
117:                                System.out
118:                                        .println("Incorrect number for maxfilesize with appender: "
119:                                                + appenderName + ": " + e);
120:                            }
121:
122:                            String showNumberOfLastPackagesString = nnm
123:                                    .getNamedItem(SHOW_NUMBER_OF_LAST_PACKAGES)
124:                                    .getNodeValue();
125:                            int showNumberOfLastPackages = -1;
126:                            try {
127:                                showNumberOfLastPackages = Integer
128:                                        .parseInt(showNumberOfLastPackagesString);
129:                            } catch (Exception e) {
130:                                System.out
131:                                        .println("Incorrect number for shownumberoflastpackages with appender: "
132:                                                + appenderName + ": " + e);
133:                            }
134:
135:                            String datePattern = nnm.getNamedItem(DATE_PATTERN)
136:                                    .getNodeValue();
137:                            String messageSeparator = nnm.getNamedItem(
138:                                    MESSAGE_SEPARATOR).getNodeValue();
139:                            String logLevel = nnm.getNamedItem(LOG_LEVEL)
140:                                    .getNodeValue();
141:                            LogConfig lg = new LogConfig(logFile, append
142:                                    .equals("true"), maxBackupIndex,
143:                                    maxFileSize, showNumberOfLastPackages,
144:                                    datePattern, messageSeparator, logLevel);
145:                            System.out.println("Logging for filter ["
146:                                    + appenderName + "] with setting\n");
147:                            System.out.println(lg);
148:                            logConfigs.put(appenderName, lg);
149:                        }
150:                    }
151:                } catch (Exception e) {
152:                    System.out.println("Exception: " + e);
153:                }
154:                return logConfigs;
155:            }
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.