1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.access.net;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import ch.qos.logback.access.spi.IAccessEvent;
20 import ch.qos.logback.core.boolex.EvaluationException;
21 import ch.qos.logback.core.boolex.EventEvaluator;
22 import ch.qos.logback.core.spi.ContextAwareBase;
23 import ch.qos.logback.core.spi.LifeCycle;
24
25 public class URLEvaluator extends ContextAwareBase implements EventEvaluator, LifeCycle {
26
27 boolean started;
28 String name;
29 private List<String> URLList = new ArrayList<String>();
30
31 public void addURL(String url) {
32 URLList.add(url);
33 }
34
35 public void start() {
36 if (URLList.size() == 0) {
37 addWarn("No URL was given to URLEvaluator");
38 } else {
39 started = true;
40 }
41 }
42
43 public boolean evaluate(Object eventObject) throws NullPointerException, EvaluationException {
44 IAccessEvent event = (IAccessEvent)eventObject;
45 String url = event.getRequestURL();
46 for(String expected:URLList) {
47 if (url.contains(expected)) {
48 return true;
49 }
50 }
51 return false;
52 }
53
54 public String getName() {
55 return name;
56 }
57
58 public void setName(String name) {
59 this.name = name;
60 }
61
62 public boolean isStarted() {
63 return started;
64 }
65
66 public void stop() {
67 started = false;
68 }
69 }