Source Code Cross Referenced for UBTLogRecord.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 javax.servlet.http.HttpServletResponse;
010:        import javax.servlet.http.HttpServletRequest;
011:        import java.util.logging.LogRecord;
012:        import java.util.logging.Level;
013:        import java.util.logging.Logger;
014:        import java.util.Hashtable;
015:        import java.util.Enumeration;
016:        import java.util.StringTokenizer;
017:        import java.net.URLDecoder;
018:
019:        /**
020:         * This class represents the UBT specific LogRecord.
021:         */
022:        public class UBTLogRecord extends LogRecord {
023:            private static Logger logger = PortalLogger
024:                    .getLogger(UBTLogRecord.class);
025:            /**
026:             * Event for which this record is being created.
027:             */
028:            protected UBTEvent event;
029:            /**
030:             * Event ID
031:             */
032:            protected String eventID;
033:            /**
034:             * Client request.
035:             */
036:            protected HttpServletRequest request;
037:            /**
038:             * Response.
039:             */
040:            protected HttpServletResponse response;
041:            /**
042:             * User ID.
043:             */
044:            transient protected String userID;
045:            /**
046:             * Log field table.
047:             */
048:            protected Hashtable table = new Hashtable();
049:
050:            /**
051:             * Constructor.
052:             * @param event UBT Event
053:             * @param request Client request
054:             * @param response Response
055:             * @param userID User ID
056:             */
057:            public UBTLogRecord(final UBTEvent event,
058:                    final HttpServletRequest request,
059:                    final HttpServletResponse response, final String userID) {
060:                super (event.getLevel(), null);
061:                this .event = event;
062:                this .eventID = event.getID();
063:                this .request = request;
064:                this .response = response;
065:                this .userID = userID;
066:            }
067:
068:            /**
069:             * Constructor.
070:             * @param event UBT Event
071:             * @param request Client request
072:             * @param response Response
073:             */
074:            public UBTLogRecord(final UBTEvent event,
075:                    final HttpServletRequest request,
076:                    final HttpServletResponse response) {
077:                this (event, request, response, request.getRemoteUser());
078:            }
079:
080:            /**
081:             * Gets the log field table.
082:             * Any custom formatter should call this to get log fields to log. 
083:             * This method is 'final' to enforce  manipulation of UserID.
084:             * @return Hashtable of the log fields
085:             */
086:            public final Hashtable getLogFieldTable() {
087:                fillTable();
088:                //check if UserID need to be shown or not
089:                configUsrID();
090:                return table;
091:            }
092:
093:            private void configUsrID() {
094:                boolean showUserID = UBTLogManager.UBT_LOG_USER_ID_VALUE_DEFAULT;
095:                String value = UBTLogManager.getInstance().getProperty(
096:                        UBTLogManager.UBT_LOG_USER_ID_KEY);
097:                if (value != null)
098:                    showUserID = Boolean.valueOf(value.trim()).booleanValue();
099:                if (!showUserID)
100:                    table.remove(UBTLogField.USER_ID.getName());
101:            }
102:
103:            /**
104:             * Fill log field table with the values available from the request, response object and also default
105:             * fields.
106:             * Subclasses need to call this method first in the overriding method.
107:             */
108:            protected void fillTable() {
109:                try {
110:                    putIntoTable(UBTLogField.TIMESTAMP, new Long(this 
111:                            .getMillis()));
112:                    putIntoTable(UBTLogField.PORTAL_ID, System.getProperty(
113:                            UBTLogManager.PORTAL_ID_PROPERTY, "PortalID"));
114:                    putIntoTable(UBTLogField.INSTANCE_ID, System.getProperty(
115:                            UBTLogManager.PORTAL_INSTANCE_ID_PROPERTY,
116:                            "InstanceID"));
117:                    putIntoTable(UBTLogField.LEVEL, this .getLevel().getName());
118:                    putIntoTable(UBTLogField.EVENT_ID, eventID);
119:                    putIntoTable(UBTLogField.USER_ID, userID);
120:                    if (request != null) {
121:                        putIntoTable(
122:                                UBTLogField.SESSION_ID,
123:                                request
124:                                        .getAttribute(UBTLogManager.UBT_SESSION_ID_ATTRIBUTE));
125:                        parseQueryString();
126:                        putIntoTable(UBTLogField.CLIENT_HOST, request
127:                                .getRemoteHost());
128:                        putIntoTable(UBTLogField.CLIENT_IP, request
129:                                .getRemoteAddr());
130:                        putIntoTable(UBTLogField.SERVER_HOST, request
131:                                .getServerName());
132:                        putIntoTable(UBTLogField.SERVER_PORT, new Integer(
133:                                request.getServerPort()));
134:                        putIntoTable(UBTLogField.REQUEST_HEAD,
135:                                getRequestHeader());
136:                    }
137:                    getLogTableFromEvent();
138:                } catch (Exception e) {
139:                    logger.log(Level.FINEST, "PSUB_CSPU0018");
140:                }
141:            }
142:
143:            private void getLogTableFromEvent(){
144:        try{
145:            Hashtable table = event.getLogTable();
146:            Enumeration enum = table.keys();
147:            while (enum.hasMoreElements()){
148:                Object obj =enum.nextElement();
149:                putIntoTable((UBTLogField)obj, table.get(obj));
150:            }
151:        }catch (Exception e){
152:            logger.log(Level.FINEST, "PSUB_CSPU0019");
153:        }
154:    }
155:
156:            private void parseQueryString() {
157:                try {
158:                    String query = request.getQueryString();
159:                    StringTokenizer st = new StringTokenizer(query, "&");
160:                    while (st.hasMoreTokens()) {
161:                        String token = st.nextToken();
162:                        try {
163:                            String compare = token.substring(0, token
164:                                    .indexOf('='));
165:                            if (compare.endsWith(".targetProvider")) {
166:                                //decoding is done to cater to portlet request. in desktop it is already taken care of.
167:                                putIntoTable(
168:                                        UBTLogField.CONTAINER_NAME,
169:                                        URLDecoder
170:                                                .decode(compare
171:                                                        .substring(
172:                                                                0,
173:                                                                compare
174:                                                                        .indexOf(".targetProvider"))));
175:                                putIntoTable(UBTLogField.TARGET_PROVIDER,
176:                                        URLDecoder.decode(token.substring(token
177:                                                .indexOf('=') + 1)));
178:                            } else if (compare.equals("provider")) {
179:                                putIntoTable(UBTLogField.PROVIDER, URLDecoder
180:                                        .decode(token.substring(token
181:                                                .indexOf('=') + 1)));
182:                            } else if (compare
183:                                    .equalsIgnoreCase("targetProvider")) { //in Portlet it is targetprovider
184:                                putIntoTable(UBTLogField.TARGET_PROVIDER,
185:                                        URLDecoder.decode(token.substring(token
186:                                                .indexOf('=') + 1)));
187:                            } else if (compare.equals("containerName")) {
188:                                putIntoTable(UBTLogField.CONTAINER_NAME,
189:                                        URLDecoder.decode(token.substring(token
190:                                                .indexOf('=') + 1)));
191:                            }
192:                        } catch (Exception e) {
193:                            logger.log(Level.FINEST, "PSUB_CSPU0020");
194:                        }
195:                    }
196:                } catch (Exception e) {
197:                    logger.log(Level.FINEST, "PSUB_CSPU0021");
198:                }
199:            }
200:
201:            /**
202:             * Put a field with specified value in the table
203:             * @param logField field
204:             * @param fieldValue value
205:             */
206:            protected void putIntoTable(UBTLogField logField, Object fieldValue) {
207:                try {
208:                    if (logField.getLevel().intValue() < getLevel().intValue()) {
209:                        return;
210:                    }
211:                    table.put(logField.getName(), fieldValue);
212:                } catch (Exception e) {
213:                    logger.log(Level.FINEST, "PSUB_CSPU0022");
214:                }
215:            }
216:
217:            private String getRequestHeader() {
218:                String clientInfo = "";
219:                Enumeration headderNames = request.getHeaderNames();
220:                if (headderNames == null) {
221:                    return clientInfo;
222:                }
223:                while (headderNames.hasMoreElements()) {
224:                    String headerName = headderNames.nextElement().toString();
225:                    clientInfo += headerName + "="
226:                            + URLDecoder.decode(request.getHeader(headerName))
227:                            + " ";
228:                }
229:                clientInfo = clientInfo.trim();
230:                clientInfo = "[" + clientInfo + "]";
231:                return clientInfo;
232:            }
233:
234:            /**
235:             * Get the logger name associated with the record
236:             * @return name of the logger
237:             */
238:            public String getLoggerName() {
239:                return event.getLoggerName();
240:            }
241:
242:            /**
243:             * Get the level of the record
244:             * @return Level
245:             */
246:            public Level getLevel() {
247:                return event.getLevel();
248:            }
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.