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