-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
PreconditionValidator.java
executable file
·83 lines (68 loc) · 2.57 KB
/
PreconditionValidator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2015, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.core.joran.action;
import org.xml.sax.Attributes;
import ch.qos.logback.core.joran.JoranConstants;
import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
import ch.qos.logback.core.spi.ContextAware;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.util.OptionHelper;
public class PreconditionValidator extends ContextAwareBase {
boolean valid = true;
SaxEventInterpretationContext intercon;
Attributes attributes;
String tag;
public PreconditionValidator(ContextAware origin, SaxEventInterpretationContext intercon, String name,
Attributes attributes) {
super(origin);
this.setContext(origin.getContext());
this.intercon = intercon;
this.tag = name;
this.attributes = attributes;
}
public PreconditionValidator validateZeroAttributes() {
if(attributes == null)
return this;
if(attributes.getLength() != 0) {
addError("Element [" + tag + "] should have no attributes, near line "
+ Action.getLineNumber(intercon));
this.valid = false;
}
return this;
}
public PreconditionValidator validateClassAttribute() {
return generic(Action.CLASS_ATTRIBUTE);
}
public PreconditionValidator validateNameAttribute() {
return generic(Action.NAME_ATTRIBUTE);
}
public PreconditionValidator validateValueAttribute() {
return generic(JoranConstants.VALUE_ATTR);
}
public PreconditionValidator validateRefAttribute() {
return generic(JoranConstants.REF_ATTRIBUTE);
}
public PreconditionValidator generic(String attributeName) {
String attributeValue = attributes.getValue(attributeName);
if (OptionHelper.isNullOrEmptyOrAllSpaces(attributeValue)) {
addError("Missing attribute [" + attributeName + "] in element [" + tag + "] near line "
+ Action.getLineNumber(intercon));
this.valid = false;
}
return this;
}
public boolean isValid() {
return valid;
}
}