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