1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.taglib;
18
19 import java.io.IOException;
20 import java.util.Enumeration;
21 import javax.servlet.jsp.JspException;
22 import javax.servlet.jsp.PageContext;
23 import javax.servlet.jsp.tagext.Tag;
24 import javax.servlet.jsp.tagext.TagSupport;
25
26
27
28
29
30
31 public class DumpTag extends TagSupport {
32 private static final long serialVersionUID = 1L;
33
34 private int scope;
35
36 public DumpTag() {
37 super();
38 init();
39 }
40
41 @Override
42 public void release() {
43 super.release();
44 this.init();
45 }
46
47 private void init() {
48 this.scope = PageContext.PAGE_SCOPE;
49 }
50
51 public void setScope(final String scope) {
52 this.scope = TagUtils.getScope(scope);
53 }
54
55 @Override
56 public int doEndTag() throws JspException {
57 try {
58 final Enumeration<String> names = this.pageContext.getAttributeNamesInScope(this.scope);
59 this.pageContext.getOut().write("<dl>");
60 while (names != null && names.hasMoreElements()) {
61 final String name = names.nextElement();
62 final Object value = this.pageContext.getAttribute(name, this.scope);
63
64 this.pageContext.getOut().write("<dt><code>" + name + "</code></dt>");
65 this.pageContext.getOut().write("<dd><code>" + value + "</code></dd>");
66 }
67 this.pageContext.getOut().write("</dl>");
68 } catch (final IOException e) {
69 throw new JspException("Could not write scope contents. Cause: " + e.toString(), e);
70 }
71
72 return Tag.EVAL_PAGE;
73 }
74 }