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