1
|
package eu.dnetlib.validator.service.impls.rules.xml;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.List;
|
5
|
import java.util.Properties;
|
6
|
|
7
|
import org.w3c.dom.NodeList;
|
8
|
|
9
|
import eu.dnetlib.validator.engine.data.DataException;
|
10
|
import eu.dnetlib.validator.engine.data.Rule;
|
11
|
import eu.dnetlib.validator.engine.data.RuleException;
|
12
|
import eu.dnetlib.validator.engine.execution.ValidationObject;
|
13
|
import eu.dnetlib.validator.service.impls.valobjs.XMLTextValidationObject;
|
14
|
|
15
|
/**
|
16
|
* Checks that the XML fields specified by {@link XMLNotConfusedFieldsRule#FIELDS} have no intersecting values.
|
17
|
* @author Manos Karvounis
|
18
|
*/
|
19
|
public class XMLNotConfusedFieldsRule extends Rule implements XMLRule {
|
20
|
|
21
|
private static final long serialVersionUID = -6253009649310760559L;
|
22
|
|
23
|
// comma seperated xpaths
|
24
|
public static final String FIELDS = "fields";
|
25
|
|
26
|
public XMLNotConfusedFieldsRule(Properties pros, int id) {
|
27
|
super(pros, id);
|
28
|
}
|
29
|
|
30
|
@Override
|
31
|
public boolean apply(ValidationObject obj) throws RuleException {
|
32
|
|
33
|
XMLTextValidationObject tobj = (XMLTextValidationObject) obj;
|
34
|
List<NodeList> lnodelist = new ArrayList<NodeList>();
|
35
|
try {
|
36
|
String[] xpaths = this.pros.getProperty(FIELDS).split(",");
|
37
|
for (String xpath : xpaths) {
|
38
|
lnodelist.add(tobj.getNodes(xpath.trim()));
|
39
|
}
|
40
|
} catch (DataException e) {
|
41
|
log.error("", e);
|
42
|
return false;
|
43
|
}
|
44
|
|
45
|
for (int i = 0; i < lnodelist.size(); i++) {
|
46
|
for (int k = 0; k < lnodelist.get(i).getLength(); k++) {
|
47
|
String val1 = lnodelist.get(i).item(k).getNodeValue();
|
48
|
log.debug("XML Not Confused Fields Rule. Val1: "+val1);
|
49
|
for (int j = i + 1; j < lnodelist.size(); j++) {
|
50
|
for (int l = 0; l < lnodelist.get(j).getLength(); l++) {
|
51
|
String val2 = lnodelist.get(j).item(l).getNodeValue();
|
52
|
log.debug("XML Not Confused Fields Rule. Val1: "+val2);
|
53
|
if(val1.trim().equalsIgnoreCase(val2.trim()))
|
54
|
return false;
|
55
|
}
|
56
|
}
|
57
|
}
|
58
|
}
|
59
|
|
60
|
return true;
|
61
|
}
|
62
|
|
63
|
}
|