1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.any23.validator.rule;
18
19 import java.util.List;
20
21 import org.apache.any23.extractor.html.DomUtils;
22 import org.apache.any23.validator.DOMDocument;
23 import org.apache.any23.validator.Rule;
24 import org.apache.any23.validator.RuleContext;
25 import org.apache.any23.validator.ValidationReport;
26 import org.apache.any23.validator.ValidationReportBuilder;
27 import org.w3c.dom.Node;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class MissingItemscopeAttributeValueRule implements Rule {
44
45
46
47
48 public MissingItemscopeAttributeValueRule() {
49
50 }
51
52 @Override
53 public String getHRName() {
54 return "missing-itemscope-value-rule";
55 }
56
57
58
59
60
61 @Override
62 public boolean applyOn(DOMDocument document, @SuppressWarnings("rawtypes") RuleContext context,
63 ValidationReportBuilder validationReportBuilder) {
64 List<Node> itemNodes = document.getNodesWithAttribute("itemscope");
65 boolean foundPrecondition = false;
66 String propertyNode;
67 Node iNode = null;
68 for (Node itemNode : itemNodes) {
69 iNode = itemNode;
70 propertyNode = iNode.getAttributes().getNamedItem("itemscope").getNodeValue();
71 if (propertyNode == null || propertyNode.contentEquals("")) {
72 foundPrecondition = true;
73 break;
74 }
75 }
76 if (foundPrecondition) {
77 validationReportBuilder.reportIssue(ValidationReport.IssueLevel.ERROR,
78 "Located absence of an accompanying value for the the 'itemscope' attribute of element with hashcode: "
79 + iNode.hashCode(),
80 iNode);
81 return true;
82 }
83 return false;
84 }
85
86 }