Skip to content

Commit 1b8053d

Browse files
Merge pull request #27 from OP-TED/release/1.3.0
Merge release/1.3.0 into main
2 parents a1107b7 + 8002b5d commit 1b8053d

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# eForms Core Library 1.2.0 Release Notes
1+
# eForms Core Library 1.3.0 Release Notes
22

33
The eForms Core Library is a collection of utilities that are used by our sample applications as well as the EFX Toolkit for Java Developers.
44

55
## In this release
66

7-
This release adds some XPath processing capabilities, via the new XPathProcessor class. Those capabilities are available in the EFX Toolkit version 1.x, but as they are also useful if you are not using EFX, we are moving them to the eForms Core Library. The corresponding API will be removed from the EFX Toolkit in its next major version (2.0.0).
8-
9-
The SdkResource enum now has a value corresponding to the index file in the `translations` folder, named `translations.json`. This file is added in SDK 1.10.0.
7+
This release improves XPathProcessor contextualisation by fixing an issue that caused unnecessary back-steps to be inserted in the contextualised output when both XPaths contain predicates.
108

119
## Download
1210

pom.xml

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

44
<groupId>eu.europa.ted.eforms</groupId>
55
<artifactId>eforms-core-java</artifactId>
6-
<version>1.2.0</version>
6+
<version>1.3.0</version>
77

88
<name>eForms Core Library</name>
99
<description>API and tools for eForms applications.</description>
@@ -44,7 +44,7 @@
4444
</distributionManagement>
4545

4646
<properties>
47-
<project.build.outputTimestamp>2023-11-17T14:42:39Z</project.build.outputTimestamp>
47+
<project.build.outputTimestamp>2023-11-17T15:30:31Z</project.build.outputTimestamp>
4848
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4949

5050
<sonatype.server.url>s01.oss.sonatype.org</sonatype.server.url>

src/main/java/eu/europa/ted/eforms/xpath/XPathProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ private static String getContextualizedXpath(Queue<XPathStep> contextQueue,
7272
// At this point there are no more matching nodes in the two queues.
7373

7474
// We look at the first of the remaining steps in both queues and look if
75-
// the context is more restrictive than the path. In this case we want to use a dot step
76-
// with the predicate of the path.
75+
// the context is the same as or less restrictive than the path. In this case
76+
// we want to use a dot step with the predicate of the path.
7777
if (!contextQueue.isEmpty() && !pathQueue.isEmpty()
78-
&& pathQueue.peek().isSimilarTo(contextQueue.peek())) {
78+
&& pathQueue.peek().isSameAsOrNarrowerThan(contextQueue.peek())) {
7979
contextQueue.poll(); // consume the same step from the contextQueue
8080
if (contextQueue.isEmpty()) {
8181
// Since there are no more steps in the contextQueue, the relative xpath should

src/main/java/eu/europa/ted/eforms/xpath/XPathStep.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,20 @@ public boolean isTheSameAs(final XPathStep other) {
116116
return pathPredicates.equals(contextPredicates);
117117
}
118118

119+
/*
120+
* @deprecated Use {@link #isSameAsOrNarrowerThan(XPathStep)} instead.
121+
*
122+
* This method was renamed for clarity. It is marked as deprecated so that the
123+
* library interface does not change. It will be removed in the next major
124+
* version of the library.
125+
*
126+
*/
127+
@Deprecated(since = "1.3.0", forRemoval = true)
119128
public boolean isSimilarTo(final XPathStep other) {
129+
return isSameAsOrNarrowerThan(other);
130+
}
131+
132+
public boolean isSameAsOrNarrowerThan(final XPathStep other) {
120133

121134
// First check the step texts are different.
122135
if (!Objects.equals(other.stepText, this.stepText)) {
@@ -125,13 +138,15 @@ public boolean isSimilarTo(final XPathStep other) {
125138

126139
// If one of the two steps has more predicates that the other,
127140
if (this.predicates.size() != other.predicates.size()) {
128-
// then the steps are similar if either of them has no predicates
129-
// or all the predicates of this step are also found in the specific step.
130-
return this.predicates.isEmpty() || other.predicates.isEmpty()
131-
|| other.predicates.containsAll(this.predicates);
141+
// then this step is same as or narrower that the other, if either of them has
142+
// no predicates or all the predicates of the other step are also found in this
143+
// step. In this case this step has the same predicates as the other one, plus
144+
// some more, which means it selects a subset of the nodes selected by the other
145+
// step and therefore it is "narrower".
146+
return other.predicates.isEmpty() || this.predicates.containsAll(other.predicates);
132147
}
133148

134-
assert !this.isTheSameAs(other) : "You should not be calling isSimilarTo() without first checking isTheSameAs()";
149+
assert !this.isTheSameAs(other) : "You should not be calling isSameAsOrNarrowerThan() without first checking isTheSameAs()";
135150
return false;
136151
}
137152

src/test/java/eu/europa/ted/eforms/xpath/XPathProcessorTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ void testIdentical() {
6363
assertEquals(".", contextualize("/a/b/c", "/a/b/c"));
6464
}
6565

66+
@Test
67+
void testIdentical_WithPredicates() {
68+
assertEquals(".[d = e][f = g]", contextualize("/a/b/c[d = e]", "/a/b/c[d = e][f = g]"));
69+
}
70+
6671
@Test
6772
void testContextEmpty() {
6873
assertEquals("/a/b/c", contextualize("", "/a/b/c"));
@@ -176,7 +181,7 @@ void testPredicateDifferent() {
176181

177182
@Test
178183
void testPredicateMoreInXpath() {
179-
assertEquals("../../b[e][f]/c/d", contextualize("/a/b[e]/c", "/a/b[e][f]/c/d"));
184+
assertEquals("..[e][f]/c/d", contextualize("/a/b[e]/c", "/a/b[e][f]/c/d"));
180185
}
181186

182187
@Test

src/test/java/eu/europa/ted/eforms/xpath/XPathStepTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void testComparison_DifferentElement() {
3333

3434
assertFalse(a.isTheSameAs(b));
3535

36-
assertFalse(a.isSimilarTo(b));
36+
assertFalse(a.isSameAsOrNarrowerThan(b));
3737
}
3838

3939
@Test
@@ -43,7 +43,7 @@ void testComparison_MorePredicates() {
4343

4444
assertTrue(a.isTheSameAs(b));
4545

46-
assertTrue(a.isSimilarTo(b));
46+
assertTrue(b.isSameAsOrNarrowerThan(a));
4747
}
4848

4949
@Test
@@ -53,7 +53,7 @@ void testComparison_LessPredicates() {
5353

5454
assertFalse(a.isTheSameAs(b));
5555

56-
assertFalse(a.isSimilarTo(b));
56+
assertFalse(b.isSameAsOrNarrowerThan(a));
5757
}
5858

5959
@Test
@@ -63,7 +63,7 @@ void testComparison_DifferentPredicate() {
6363

6464
assertFalse(a.isTheSameAs(b));
6565

66-
assertFalse(a.isSimilarTo(b));
66+
assertFalse(a.isSameAsOrNarrowerThan(b));
6767
}
6868

6969
@Test
@@ -73,7 +73,7 @@ void testComparison_NoPredicates() {
7373

7474
assertFalse(a.isTheSameAs(b));
7575

76-
assertTrue(a.isSimilarTo(b));
76+
assertTrue(a.isSameAsOrNarrowerThan(b));
7777
}
7878

7979
@Test
@@ -83,7 +83,7 @@ void testComparison_AddPredicates() {
8383

8484
assertTrue(a.isTheSameAs(b));
8585

86-
assertTrue(a.isSimilarTo(b));
86+
assertTrue(b.isSameAsOrNarrowerThan(a));
8787
}
8888

8989
private XPathStep buildStep(String elt, String... predicates) {

0 commit comments

Comments
 (0)