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 import org.xml.sax.Locator;
18
19 import ch.qos.logback.core.joran.spi.ActionException;
20 import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
21 import ch.qos.logback.core.joran.spi.SaxEventInterpreter;
22 import ch.qos.logback.core.spi.ContextAwareBase;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public abstract class Action extends ContextAwareBase {
41
42 public static final String NAME_ATTRIBUTE = "name";
43 public static final String KEY_ATTRIBUTE = "key";
44 public static final String VALUE_ATTRIBUTE = "value";
45 public static final String FILE_ATTRIBUTE = "file";
46 public static final String CLASS_ATTRIBUTE = "class";
47 public static final String PATTERN_ATTRIBUTE = "pattern";
48 public static final String SCOPE_ATTRIBUTE = "scope";
49
50 public static final String ACTION_CLASS_ATTRIBUTE = "actionClass";
51
52
53
54
55
56 public abstract void begin(SaxEventInterpretationContext intercon, String name, Attributes attributes)
57 throws ActionException;
58
59
60
61
62
63
64
65
66 public void body(SaxEventInterpretationContext intercon, String body) throws ActionException {
67
68 }
69
70
71
72
73
74 public abstract void end(SaxEventInterpretationContext intercon, String name) throws ActionException;
75
76 public String toString() {
77 return this.getClass().getName();
78 }
79
80 protected int getColumnNumber(SaxEventInterpretationContext intercon) {
81 SaxEventInterpreter interpreter = intercon.getSaxEventInterpreter();
82 if (interpreter == null)
83 return -1;
84
85 Locator locator = interpreter.getLocator();
86 if (locator != null) {
87 return locator.getColumnNumber();
88 }
89 return -1;
90 }
91
92
93 static public int getLineNumber(SaxEventInterpretationContext intercon) {
94 SaxEventInterpreter interpreter = intercon.getSaxEventInterpreter();
95 if (interpreter == null)
96 return -1;
97 Locator locator = interpreter.getLocator();
98 if (locator != null) {
99 return locator.getLineNumber();
100 }
101 return -1;
102 }
103
104 protected String getLineColStr(SaxEventInterpretationContext intercon) {
105 return "line: " + getLineNumber(intercon) + ", column: " + getColumnNumber(intercon);
106 }
107
108 protected String atLine(SaxEventInterpretationContext intercon) {
109 return "At line " + getLineNumber(intercon);
110 }
111
112 protected String nearLine(SaxEventInterpretationContext intercon) {
113 return "Near line " + getLineNumber(intercon);
114 }
115 }