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 import org.xml.sax.Locator;
15
16 import ch.qos.logback.core.joran.spi.ActionException;
17 import ch.qos.logback.core.joran.spi.InterpretationContext;
18 import ch.qos.logback.core.joran.spi.Interpreter;
19 import ch.qos.logback.core.spi.ContextAwareBase;
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public abstract class Action extends ContextAwareBase {
36
37 public static final String NAME_ATTRIBUTE = "name";
38 public static final String VALUE_ATTRIBUTE = "value";
39 public static final String FILE_ATTRIBUTE = "file";
40 public static final String CLASS_ATTRIBUTE = "class";
41 public static final String PATTERN_ATTRIBUTE = "pattern";
42
43 public static final String ACTION_CLASS_ATTRIBUTE = "actionClass";
44
45
46
47
48
49 public abstract void begin(InterpretationContext ec, String name,
50 Attributes attributes) throws ActionException;
51
52 public void body(InterpretationContext ec, String body)
53 throws ActionException {
54
55 }
56
57
58
59
60
61 public abstract void end(InterpretationContext ec, String name)
62 throws ActionException;
63
64 public String toString() {
65 return this.getClass().getName();
66 }
67
68 protected int getColumnNumber(InterpretationContext ec) {
69 Interpreter jp = ec.getJoranInterpreter();
70 Locator locator = jp.getLocator();
71 if (locator != null) {
72 return locator.getColumnNumber();
73 }
74 return -1;
75 }
76
77 protected int getLineNumber(InterpretationContext ec) {
78 Interpreter jp = ec.getJoranInterpreter();
79 Locator locator = jp.getLocator();
80 if (locator != null) {
81 return locator.getLineNumber();
82 }
83 return -1;
84 }
85
86 protected String getLineColStr(InterpretationContext ec) {
87 String line = "line: " + getLineNumber(ec) + ", column: "
88 + getColumnNumber(ec);
89 return line;
90 }
91 }