01: /*
02: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: */
19:
20: package com.nabhinc.portal.login;
21:
22: import java.util.StringTokenizer;
23:
24: import com.nabhinc.portal.core.ServletInitable;
25:
26: /**
27: * A portlet interceptor that logs a portlet hit in a database.
28: *
29: * @author Padmanabh Dabke
30: * (c) 2002, 2003 Nabh Information Systems, Inc. All Rights Reserved.
31: */
32: public abstract class BaseLogger implements ServletInitable {
33:
34: // Constants that indicate which parameters are to be logged.
35:
36: public static final int LOG_PORTLET_NAME = 0;
37: public static final int LOG_TIMESTAMP = 1;
38: public static final int LOG_REMOTE_USER = 2;
39: public static final int LOG_REMOTE_ADDR = 3;
40: public static final int LOG_REMOTE_HOST = 4;
41: public static final int LOG_EVENT_TYPE = 5;
42: public static final int LOG_SESSION_ID = 6;
43:
44: protected String blParamStr = null;
45:
46: /**
47: * Holds codes corresponding to parameters selected for logging.
48: */
49: protected transient int[] blParams = null;
50:
51: /**
52: * Number of logged params (maintained for efficiency)
53: */
54: protected int blNumParams = 0;
55:
56: public String getLoggedParams() {
57: return this .blParamStr;
58: }
59:
60: public void setLoggedParams(String paramStr) {
61: this .blParamStr = paramStr;
62:
63: StringTokenizer st = new StringTokenizer(blParamStr, ",");
64: blNumParams = st.countTokens();
65: blParams = new int[blNumParams];
66:
67: for (int i = 0; i < blNumParams; i++) {
68: String param = st.nextToken().trim();
69: if (param == null || param.trim().equals(""))
70: throw new IllegalArgumentException(
71: "Empty logged parameter.");
72: if (param.equals("portlet-name")) {
73: blParams[i] = LOG_PORTLET_NAME;
74: } else if (param.equals("timestamp")) {
75: blParams[i] = LOG_TIMESTAMP;
76: } else if (param.equals("user-name")) {
77: blParams[i] = LOG_REMOTE_USER;
78: } else if (param.equals("remote-address")) {
79: blParams[i] = LOG_REMOTE_ADDR;
80: } else if (param.equals("remote-host")) {
81: blParams[i] = LOG_REMOTE_HOST;
82: } else if (param.equals("event-type")) {
83: blParams[i] = LOG_EVENT_TYPE;
84: } else if (param.equals("session-id")) {
85: blParams[i] = LOG_SESSION_ID;
86: } else {
87: throw new IllegalArgumentException(
88: "Invalid logging parameter: " + param + ".");
89: }
90: }
91: }
92:
93: }
|