KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > log > DumpTag


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.log;
18
19 import java.util.Enumeration JavaDoc;
20
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.PageContext JavaDoc;
23 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
24
25 public class DumpTag extends TagSupport JavaDoc {
26     
27     private int scope;
28     
29     
30     public void setScope(String JavaDoc sc) throws JspException JavaDoc {
31         if (sc.equalsIgnoreCase("session")) {
32             this.scope = PageContext.SESSION_SCOPE;
33         }
34         else if (sc.equalsIgnoreCase("request")) {
35             this.scope = PageContext.REQUEST_SCOPE;
36         }
37         else if (sc.equalsIgnoreCase("application")) {
38             this.scope = PageContext.APPLICATION_SCOPE;
39         }
40         else if (sc.equalsIgnoreCase("page")) {
41             this.scope = PageContext.PAGE_SCOPE;
42         }
43         else {
44             throw new JspException JavaDoc(
45                 "Scope must be page, request, session or application."
46             );
47         }
48     }
49     
50     public int doEndTag() throws JspException JavaDoc {
51         try {
52             Enumeration JavaDoc names = pageContext.getAttributeNamesInScope(scope);
53             pageContext.getOut().write("<dl>");
54             while(names.hasMoreElements()) {
55                 String JavaDoc name = (String JavaDoc) names.nextElement();
56                 Object JavaDoc value = pageContext.getAttribute(name, scope);
57                 
58                 pageContext.getOut().write("<dt><code>"+name+"</code></dt>");
59                 pageContext.getOut().write("<dd><code>"+value+"</code></dd>");
60             }
61             pageContext.getOut().write("</dl>");
62         }
63         catch (Exception JavaDoc e) {
64             throw new JspException JavaDoc("Exception: "+e.getMessage());
65         }
66         return EVAL_PAGE;
67     }
68 }
69
Popular Tags