KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > ui > servlet > ServletBase


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Jul 19, 2005
14  * @author James Dixon
15  *
16  */

17
18 package org.pentaho.ui.servlet;
19
20 import javax.servlet.http.HttpServlet JavaDoc;
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22
23 import org.apache.commons.logging.Log;
24 import org.pentaho.core.session.IPentahoSession;
25 import org.pentaho.core.system.PentahoSystem;
26 import org.pentaho.core.util.UIUtil;
27 import org.pentaho.util.logging.ILogger;
28
29 public abstract class ServletBase extends HttpServlet JavaDoc implements ILogger {
30
31     public static final boolean debug = PentahoSystem.debug;
32
33     private int loggingLevel = ERROR;
34
35     private String JavaDoc logId = ""; //$NON-NLS-1$
36

37     protected IPentahoSession getPentahoSession(HttpServletRequest JavaDoc request) {
38         return UIUtil.getPentahoSession(request);
39     }
40
41     public abstract Log getLogger();
42
43     public String JavaDoc getLogId() {
44         return logId;
45     }
46
47     public void setLogId(String JavaDoc lId) {
48         logId = lId;
49     }
50
51     /* ILogger Implementation */
52
53     public String JavaDoc getObjectName() {
54         return this.getClass().getName();
55     }
56
57     public int getLoggingLevel() {
58         return loggingLevel;
59     }
60
61     public void setLoggingLevel(int logLevel) {
62         this.loggingLevel = logLevel;
63     }
64
65     public void trace(String JavaDoc message) {
66         if (loggingLevel <= TRACE) {
67             getLogger().trace(getLogId() + message);
68         }
69     }
70
71     public void debug(String JavaDoc message) {
72         if (loggingLevel <= DEBUG) {
73             getLogger().debug(getLogId() + message);
74         }
75     }
76
77     public void info(String JavaDoc message) {
78         if (loggingLevel <= INFO) {
79             getLogger().info(getLogId() + message);
80         }
81     }
82
83     public void warn(String JavaDoc message) {
84         if (loggingLevel <= WARN) {
85             getLogger().warn(getLogId() + message);
86         }
87     }
88
89     public void error(String JavaDoc message) {
90         if (loggingLevel <= ERROR) {
91             getLogger().error(getLogId() + message);
92         }
93     }
94
95     public void fatal(String JavaDoc message) {
96         if (loggingLevel <= FATAL) {
97             getLogger().fatal(getLogId() + message);
98         }
99     }
100
101     public void trace(String JavaDoc message, Throwable JavaDoc error) {
102         if (loggingLevel <= TRACE) {
103             getLogger().trace(getLogId() + message, error);
104         }
105     }
106
107     public void debug(String JavaDoc message, Throwable JavaDoc error) {
108         if (loggingLevel <= DEBUG) {
109             getLogger().debug(getLogId() + message, error);
110         }
111     }
112
113     public void info(String JavaDoc message, Throwable JavaDoc error) {
114         if (loggingLevel <= INFO) {
115             getLogger().info(getLogId() + message, error);
116         }
117     }
118
119     public void warn(String JavaDoc message, Throwable JavaDoc error) {
120         if (loggingLevel <= WARN) {
121             getLogger().warn(getLogId() + message, error);
122         }
123     }
124
125     public void error(String JavaDoc message, Throwable JavaDoc error) {
126         if (loggingLevel <= ERROR) {
127             getLogger().error(getLogId() + message, error);
128         }
129     }
130
131     public void fatal(String JavaDoc message, Throwable JavaDoc error) {
132         if (loggingLevel <= FATAL) {
133             getLogger().fatal(getLogId() + message, error);
134         }
135     }
136
137 }
138
Popular Tags