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


001:        /*
002:         * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:        package com.sun.portal.ubt;
006:
007:        import com.sun.portal.log.common.PortalLogger;
008:
009:        import java.util.logging.*;
010:        import java.util.Hashtable;
011:        import java.util.Date;
012:        import java.util.Vector;
013:        import java.text.SimpleDateFormat;
014:
015:        /**
016:         * This is a simple ELF formatter meant for UBTLogRecord. 
017:         * This formats various different fields of UBTLogRecord into a tab seperated 
018:         * String. The fields appear in the order that is given by getHead(Handler)
019:         * method. If a field does not have any value or is not part of UBTLogRecord
020:         * it is formatted as '-'. 
021:         * <p>
022:         * There is no message to localize. So formatMessage is not used.
023:         * If needed can be delegated to the super class
024:         */
025:        public class UBTELFFormatter extends Formatter {
026:            private static Logger logger = PortalLogger
027:                    .getLogger(UBTELFFormatter.class);
028:            private SimpleDateFormat dateFormat = new SimpleDateFormat(
029:                    "yyyy.MM.dd G 'at' HH:mm:ss z");
030:            private String fieldDelimiter = "\t";
031:            private String fieldEnclosure = "";
032:            private String fieldNull = "-";
033:            private String lineSeparator = (String) java.security.AccessController
034:                    .doPrivileged(new sun.security.action.GetPropertyAction(
035:                            "line.separator"));
036:            private Vector fields;
037:
038:            /**
039:             * Gets the representation of a null fields in this formatter.
040:             */
041:            public String getFieldNull() {
042:                return fieldNull;
043:            }
044:
045:            /**
046:             * Gets the date format that is used by this formatter.
047:             */
048:            public SimpleDateFormat getDateFormat() {
049:                return dateFormat;
050:            }
051:
052:            /**
053:             * Gets the string used to enclose the fields, if any.
054:             * @return String field enclosure
055:             */
056:            public String getFieldEnclosure() {
057:                return fieldEnclosure;
058:            }
059:
060:            /**
061:             * Gets the field delimiter in the formatted message.
062:             * @return String field delimiter
063:             */
064:            public String getFieldDelimiter() {
065:                return fieldDelimiter;
066:            }
067:
068:            /**
069:             * Gets the head message of this formatter.
070:             * A handler uses this method to log the head message of its formatter
071:             * whenever it opens handler to log messages.
072:             * The head message of this formatter represents the order of appearence
073:             * of the fields for a log level.
074:             * Field identifiers are listed based on the handler's log level.
075:             * @return  String Head message
076:             * @param handler Handler to which this formatter is added.
077:             */
078:            public String getHead(Handler handler) {
079:                StringBuffer sbuffer = new StringBuffer();
080:                if (handler instanceof  java.util.logging.FileHandler) {
081:                    sbuffer.append("#Version: 1.0").append(lineSeparator);
082:                    sbuffer.append("#Date: ").append(
083:                            dateFormat.format(new Date()))
084:                            .append(lineSeparator);
085:                    sbuffer.append("#Fields: ").append(lineSeparator);
086:                    //this could have been based on the handler's level. Since, details are based on
087:                    // the log level, field details of all possible levels are mentioned in the log file
088:                    //Also it possible that the logger  levels  are modified dynamically
089:                    sbuffer.append("#Level INFO: ").append(
090:                            getFieldIdentifiers(Level.INFO)).append(
091:                            lineSeparator);
092:                    sbuffer.append("#Level FINE: ").append(
093:                            getFieldIdentifiers(Level.FINE)).append(
094:                            lineSeparator);
095:                    sbuffer.append("#Level FINER: ").append(
096:                            getFieldIdentifiers(Level.FINER)).append(
097:                            lineSeparator);
098:                    //'!' in the following line is used for deciding on the file schema dynamically.  So don't change it
099:                    sbuffer.append("!Level FINEST: ").append(
100:                            getFieldIdentifiers(Level.FINEST)).append(
101:                            lineSeparator);
102:                }
103:                return sbuffer.toString();
104:            }
105:
106:            private void getLogFields(Level level) {
107:                fields = UBTLogManager.getInstance().getLogFields(level);
108:            }
109:
110:            private String getFieldIdentifiers(Level level) {
111:                StringBuffer fieldBuff = new StringBuffer();
112:                getLogFields(level);
113:                for (int i = 0; i < fields.size(); i++) {
114:                    fieldBuff.append(fields.get(i)).append(fieldDelimiter);
115:                }
116:                return fieldBuff.toString();
117:            }
118:
119:            /**
120:             * Gets the tail message of the formatter.
121:             * A handler calls this method before closing itself.
122:             * In this formatter, this message provides the time of the call.
123:             * @return  String Tail message
124:             * @param handler Handler to which this formatter is added.
125:             */
126:            public String getTail(Handler handler) {
127:                return "#Closed...Date: " + dateFormat.format(new Date())
128:                        + lineSeparator;
129:            }
130:
131:            /**
132:             * Method to format the message of record.
133:             * In this formatter, record is expected to be UBTLogRecord and on that
134:             * record, getLogFieldTable() is called to get the HashTable of field 
135:             * name value pair.
136:             * @return String formatted message
137:             * @param record LogRecord message of which need to be formatted.
138:             */
139:            public synchronized String format(LogRecord record) {
140:                // this is done twice - once here and once in getHead(..)
141:                // since format is called first and getHead() is called later
142:                // with LogRecord and handler as parameters. Handler would not let
143:                // any LogRecord go through to formatter if its level is lower than
144:                // that of record's. So, getHead() should display Handler's level fields.
145:                // and accordingly the record should be formatted
146:                getLogFields(record.getLevel());
147:                StringBuffer logbuff = new StringBuffer();
148:                try {
149:                    Hashtable logInfoTable = null;
150:                    UBTLogRecord rec = ((UBTLogRecord) record);
151:                    logInfoTable = rec.getLogFieldTable();
152:                    for (int i = 0; i < fields.size(); i++) {
153:                        Object val = logInfoTable.get(fields.get(i));
154:                        logbuff.append(fieldEnclosure);
155:                        if (val != null)
156:                            logbuff.append(val.toString());
157:                        else
158:                            logbuff.append(fieldNull);
159:                        logbuff.append(fieldEnclosure).append(fieldDelimiter);
160:                    }
161:                } catch (Exception e) {
162:                    //something went wrong.
163:                    logger.log(Level.INFO, "PSUB_CSPU0001", e);
164:                }
165:                if (logbuff.length() > 0)
166:                    //introduced check when a newline
167:                    //is displayed even if the event level is OFF / lower than logger's level
168:                    logbuff.append(lineSeparator);
169:                return logbuff.toString();
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.