1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.monitoring.web.jsp;
19
20 import org.apache.commons.monitoring.Role;
21 import org.apache.commons.monitoring.counters.Counter;
22 import org.apache.commons.monitoring.repositories.Repository;
23 import org.apache.commons.monitoring.stopwatches.StopWatch;
24
25 import javax.servlet.jsp.JspException;
26 import javax.servlet.jsp.tagext.TagSupport;
27
28 import static org.apache.commons.monitoring.web.jsp.TagUtils.getScope;
29
30
31
32
33
34
35 public class StartTag extends TagSupport {
36 private String id;
37 private String scope;
38 private String name;
39
40 public void setId(String id) {
41 this.id = id;
42 }
43
44 @Override
45 public int doStartTag() throws JspException {
46 final StopWatch stopWatch = Repository.INSTANCE.start(Repository.INSTANCE.getCounter(new Counter.Key(Role.JSP, name)));
47 if (scope != null) {
48 pageContext.setAttribute(id, stopWatch, getScope(scope));
49 } else {
50 pageContext.setAttribute(id, stopWatch);
51 }
52 return EVAL_PAGE;
53 }
54
55 public void setScope(String scope) {
56 this.scope = scope;
57 }
58
59 public void setName(String name) {
60 this.name = name;
61 }
62 }