1
|
package eu.dnetlib.validator.service.impls.rules.xml;
|
2
|
|
3
|
import java.util.Properties;
|
4
|
|
5
|
import org.w3c.dom.Node;
|
6
|
import org.w3c.dom.NodeList;
|
7
|
|
8
|
import eu.dnetlib.validator.engine.data.DataException;
|
9
|
import eu.dnetlib.validator.engine.execution.ValidationObject;
|
10
|
import eu.dnetlib.validator.service.impls.rules.RegularExpressionRule;
|
11
|
import eu.dnetlib.validator.service.impls.valobjs.XMLTextValidationObject;
|
12
|
|
13
|
public class XMLRegularExpressionRule extends RegularExpressionRule implements XMLRule {
|
14
|
|
15
|
private static final long serialVersionUID = -7791692519583028162L;
|
16
|
public XMLRegularExpressionRule(Properties pros, int id) {
|
17
|
super(pros, id);
|
18
|
}
|
19
|
|
20
|
|
21
|
@Override
|
22
|
public boolean apply(ValidationObject obj) {
|
23
|
XMLTextValidationObject tobj = (XMLTextValidationObject) obj;
|
24
|
NodeList nodes;
|
25
|
try {
|
26
|
nodes = tobj.getNodes(this.pros.getProperty(XPATH));
|
27
|
} catch (DataException e) {
|
28
|
log.error("", e);
|
29
|
return false;
|
30
|
}
|
31
|
int success = 0, all = nodes.getLength();
|
32
|
for(int i=0; i<nodes.getLength();i++) {
|
33
|
Node node = nodes.item(i);
|
34
|
log.debug("XML RegExp Rule. Field Value: "+node.getNodeValue());
|
35
|
if(node.getNodeValue().matches(this.pros.getProperty(REGEXP)))
|
36
|
success++;
|
37
|
}
|
38
|
|
39
|
String successConditions = this.pros.getProperty(SUCCESS);
|
40
|
return Utils.success(successConditions, success, all);
|
41
|
}
|
42
|
}
|