1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.joran.action;
15
16 import org.xml.sax.Attributes;
17
18 import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
19 import ch.qos.logback.core.joran.spi.ElementSelector;
20 import ch.qos.logback.core.util.OptionHelper;
21
22 public class NewRuleAction extends Action {
23 boolean inError = false;
24
25
26
27
28 public void begin(SaxEventInterpretationContext ec, String localName, Attributes attributes) {
29
30 inError = false;
31 String errorMsg;
32 String pattern = attributes.getValue(Action.PATTERN_ATTRIBUTE);
33 String actionClass = attributes.getValue(Action.ACTION_CLASS_ATTRIBUTE);
34
35 if (OptionHelper.isNullOrEmptyOrAllSpaces(pattern)) {
36 inError = true;
37 errorMsg = "No 'pattern' attribute in <newRule>";
38 addError(errorMsg);
39 return;
40 }
41
42 if (OptionHelper.isNullOrEmptyOrAllSpaces(actionClass)) {
43 inError = true;
44 errorMsg = "No 'actionClass' attribute in <newRule>";
45 addError(errorMsg);
46 return;
47 }
48
49 try {
50 addInfo("About to add new Joran parsing rule [" + pattern + "," + actionClass + "].");
51 ec.getSaxEventInterpreter().getRuleStore().addRule(new ElementSelector(pattern), actionClass);
52 } catch (Exception oops) {
53 inError = true;
54 errorMsg = "Could not add new Joran parsing rule [" + pattern + "," + actionClass + "]";
55 addError(errorMsg);
56 }
57 }
58
59
60
61
62
63 public void end(SaxEventInterpretationContext ec, String n) {
64 }
65
66 public void finish(SaxEventInterpretationContext ec) {
67 }
68 }