Skip to content

Commit 7e27ef8

Browse files
refactor: Use XPathProcessor from eforms-core
Use XPathProcessor from eforms-core instead of our own XPath parser. Also rename getXpathRelativeStepCount to getXpathRelativeElementCount to make it clearer it only count XPath steps that are elements, and not attributes. (cherry picked from commit ad2136b)
1 parent 356198e commit 7e27ef8

5 files changed

Lines changed: 19 additions & 186 deletions

File tree

src/main/java/eu/europa/ted/eforms/sdk/analysis/fact/FieldFact.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import eu.europa.ted.eforms.sdk.analysis.domain.field.FieldPrivacy;
1616
import eu.europa.ted.eforms.sdk.analysis.domain.field.XmlElementPosition;
1717
import eu.europa.ted.eforms.sdk.analysis.domain.field.XmlStructureNode;
18-
import eu.europa.ted.eforms.sdk.analysis.util.XPathSplitter;
18+
import eu.europa.ted.eforms.xpath.XPathInfo;
19+
import eu.europa.ted.eforms.xpath.XPathProcessor;
1920

2021
public class FieldFact implements SdkComponentFact<String> {
2122
private static final long serialVersionUID = -8325643682910825716L;
@@ -118,9 +119,14 @@ public String getXpathRelative() {
118119
return field.getXpathRelative();
119120
}
120121

121-
public int getXpathRelativeStepCount() {
122+
public int getXpathRelativeElementCount() {
122123
if (stepCount == 0 && getXpathRelative() != null) {
123-
stepCount = XPathSplitter.getStepElementNames(getXpathRelative()).size();
124+
XPathInfo xpathInfo = XPathProcessor.parse(getXpathRelative());
125+
stepCount = xpathInfo.getSteps().size();
126+
if (xpathInfo.isAttribute()) {
127+
// we don't want to count attributes
128+
stepCount--;
129+
}
124130
}
125131
return stepCount;
126132
}

src/main/java/eu/europa/ted/eforms/sdk/analysis/fact/NodeFact.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import eu.europa.ted.eforms.sdk.analysis.domain.field.XmlElementPosition;
77
import eu.europa.ted.eforms.sdk.analysis.domain.field.XmlStructureNode;
8-
import eu.europa.ted.eforms.sdk.analysis.util.XPathSplitter;
8+
import eu.europa.ted.eforms.xpath.XPathProcessor;
99

1010
public class NodeFact implements SdkComponentFact<String> {
1111
private static final long serialVersionUID = -6237630016231337698L;
@@ -78,9 +78,9 @@ public String getXpathRelative() {
7878
return node.getXpathRelative();
7979
}
8080

81-
public int getXpathRelativeStepCount() {
81+
public int getXpathRelativeElementCount() {
8282
if (stepCount == 0 && getXpathRelative() != null) {
83-
stepCount = XPathSplitter.getStepElementNames(getXpathRelative()).size();
83+
stepCount = XPathProcessor.parse(getXpathRelative()).getSteps().size();
8484
}
8585
return stepCount;
8686
}

src/main/java/eu/europa/ted/eforms/sdk/analysis/util/XPathSplitter.java

Lines changed: 0 additions & 173 deletions
This file was deleted.

src/main/java/eu/europa/ted/eforms/sdk/analysis/validator/XmlSchemaValidator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
import eu.europa.ted.eforms.sdk.analysis.enums.ValidationStatusEnum;
3232
import eu.europa.ted.eforms.sdk.analysis.fact.FieldFact;
3333
import eu.europa.ted.eforms.sdk.analysis.fact.NodeFact;
34-
import eu.europa.ted.eforms.sdk.analysis.util.XPathSplitter;
3534
import eu.europa.ted.eforms.sdk.analysis.vo.ValidationResult;
35+
import eu.europa.ted.eforms.xpath.XPathProcessor;
36+
import eu.europa.ted.eforms.xpath.XPathStep;
3637

3738
/**
3839
* Validates the content of the XSD files in the SDK, and their consistency with other files.
@@ -161,17 +162,16 @@ private void checkNodeRepeatability(XmlStructureNode node) {
161162
* removing any predicate.
162163
*/
163164
private String getFirstElementName(String xpath) {
164-
List<String> names = XPathSplitter.getStepElementNames(xpath);
165-
return names.get(0);
165+
return XPathProcessor.parse(xpath).getSteps().get(0).getStepText();
166166
}
167167

168168
/**
169169
* Return the name of the element that is the last step in the given XPath,
170170
* removing any predicate.
171171
*/
172172
private String getLastElementName(String xpath) {
173-
List<String> names = XPathSplitter.getStepElementNames(xpath);
174-
return names.get(names.size() - 1);
173+
List<XPathStep> steps = XPathProcessor.parse(xpath).getSteps();
174+
return steps.get(steps.size() - 1).getStepText();
175175
}
176176

177177
/**

src/main/resources/eu/europa/ted/eforms/sdk/analysis/drools/fieldsAndNodesRules.drl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ end
139139

140140
rule "Every field has XSD sequence order consistent with relative xpath"
141141
when
142-
/fields[ $f: this, xsdSequenceOrderCount != xpathRelativeStepCount ]
142+
/fields[ $f: this, xsdSequenceOrderCount != xpathRelativeElementCount ]
143143
then
144144
results.add(new ValidationResult($f, "Field XSD sequence order is inconsistent with relative XPath.", ValidationStatusEnum.ERROR));
145145
end
146146

147147
rule "Every non-root node has XSD sequence order consistent with relative xpath"
148148
when
149-
/nodes[ $n: this, parentId != null, xsdSequenceOrderCount != xpathRelativeStepCount ]
149+
/nodes[ $n: this, parentId != null, xsdSequenceOrderCount != xpathRelativeElementCount ]
150150
then
151151
results.add(new ValidationResult($n, "Node XSD sequence order is inconsistent with relative XPath.", ValidationStatusEnum.ERROR));
152152
end

0 commit comments

Comments
 (0)