1
|
package eu.dnetlib.validator.service.impls.rules.xml;
|
2
|
|
3
|
import java.util.Properties;
|
4
|
|
5
|
import org.w3c.dom.NodeList;
|
6
|
|
7
|
import eu.dnetlib.validator.engine.data.DataException;
|
8
|
import eu.dnetlib.validator.engine.data.Rule;
|
9
|
import eu.dnetlib.validator.engine.data.RuleException;
|
10
|
import eu.dnetlib.validator.engine.execution.ValidationObject;
|
11
|
import eu.dnetlib.validator.service.impls.valobjs.XMLTextValidationObject;
|
12
|
|
13
|
public class XMLFieldExistsRule extends Rule implements XMLRule {
|
14
|
|
15
|
private static final long serialVersionUID = -1532674779961679673L;
|
16
|
|
17
|
public XMLFieldExistsRule(Properties pros, int id) {
|
18
|
super(pros, id);
|
19
|
}
|
20
|
|
21
|
@Override
|
22
|
public boolean apply(ValidationObject obj) throws RuleException {
|
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
|
|
32
|
int success = 0, all = nodes.getLength();
|
33
|
if(nodes.getLength() == 0)
|
34
|
return false;
|
35
|
for(int i=0; i<nodes.getLength(); i++)
|
36
|
if(!nodes.item(i).getNodeValue().trim().equals(""))
|
37
|
success++;
|
38
|
|
39
|
String successConditions = this.pros.getProperty(SUCCESS);
|
40
|
return Utils.success(successConditions, success, all);
|
41
|
}
|
42
|
}
|