View Javadoc

1   package org.lsst.ccs.plugin.jas3.console;
2   
3   import java.util.regex.Pattern;
4   import org.lsst.ccs.bus.BusMessage;
5   
6   /**
7    * Accepts or reject bus messages based on regular expressions applied to the
8    * "toString" output of the message.
9    *
10   * @author tonyj
11   */
12  public class RegularExpressionMessageFilter implements MessageFilter {
13  
14      private Pattern veto;
15      private Pattern accept;
16  
17      @Override
18      public boolean accept(BusMessage message) {
19          String str = message.toString();
20          if (veto != null) {
21              if (veto.matcher(str).find()) {
22                  return false;
23              }
24          }
25          if (accept != null) {
26              return accept.matcher(str).find();
27          }
28          return true;
29      }
30  
31      public Pattern getVeto() {
32          return veto;
33      }
34  
35      /**
36       * If this pattern is found in the message it will be vetoed (not
37       * displayed). The pattern is ignored if
38       * <code>null</code>
39       */
40      public void setVeto(Pattern veto) {
41          this.veto = veto;
42      }
43  
44      public Pattern getAccept() {
45          return accept;
46      }
47  
48      /**
49       * If the survives the veto, and this pattern pattern is found, it will be
50       * displayed. The pattern is ignored if
51       * <code>null</code>.
52       */
53      public void setAccept(Pattern accept) {
54          this.accept = accept;
55      }
56  }