View Javadoc

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