KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > request > LogTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.request;
18
19 import java.io.*;
20 import javax.servlet.*;
21 import javax.servlet.jsp.*;
22 import javax.servlet.jsp.tagext.*;
23 import javax.servlet.http.*;
24
25 /**
26  * JSP Tag <b>log</b>, used to log the content of the log
27  * tag body to the servlet context log.
28  * <p>
29  * JSP Tag Lib Descriptor
30  * <p><pre>
31  * &lt;name&gt;log&lt;/name&gt;
32  * &lt;tagclass&gt;org.apache.taglibs.request.LogTag&lt;/tagclass&gt;
33  * &lt;bodycontent&gt;JSP&lt;/bodycontent&gt;
34  * &lt;info&gt;Logs the body of the tag to the servlet context log.&lt;/info&gt;
35  * </pre>
36  *
37  * @author Glenn Nielsen
38  */

39
40 public class LogTag extends BodyTagSupport
41 {
42     /**
43      * Always include the body so it can be logged.
44      *
45      * @return EVAL_BODY_TAG
46      */

47     public final int doStartTag() throws JspException
48     {
49         return EVAL_BODY_TAG;
50     }
51
52     /**
53      * Log the content of the log tag body to the servlet context log.
54      *
55      * @return SKIP_BODY
56      */

57     public final int doAfterBody() throws JspException
58     {
59         // Use the body of the tag as message to log
60
BodyContent body = getBodyContent();
61         String JavaDoc s = body.getString().trim();
62         // Clear the body since we use tag body as log message
63
body.clearBody();
64         // Get the servlet context to log the message
65
ServletContext ctx = pageContext.getServletContext();
66         ctx.log(s);
67         return SKIP_BODY;
68     }
69
70 }
71
Popular Tags