Skip to content

Commit 02c7eab

Browse files
Merge pull request #92 from OP-TED/release/2.0.0-alpha.1
Release 2.0.0-alpha.1
2 parents eafaa82 + ebac474 commit 02c7eab

105 files changed

Lines changed: 10828 additions & 6898 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,54 @@
1-
# EFX Toolkit 1.3.0 Release Notes
1+
# EFX Toolkit 2.0.0-alpha.1 Release Notes
22

33
_The EFX Toolkit for Java developers is a library that enables the transpilation of [EFX](https://docs.ted.europa.eu/eforms/latest/efx) expressions and templates to different target languages. It also includes an implementation of an EFX-to-XPath transpiler._
44

55
---
6-
## In this release:
76

8-
- Updated the XPath 2.0 parser, XPathContextualizer and XPathScriptGenerator to correctly translate sequences.
9-
- Improved numeric formatting. The EfxTranslator API now includes overloaded methods that permit control of numeric formatting. The existing API has been preserved.
10-
- Improved handling of multilingual text fields by adding automatic selection of the visualisation language.
7+
## In this release
8+
9+
This release:
10+
11+
- Improves translation of EFX-1.
12+
- Adds support for translating EFX-2 expressions and templates.
13+
- Removes support of the obsolete EFX versions included in pre-release versions of the SDK (SDK 0.x.x).
14+
- Introduces some breaking changes in the interfaces that need to be implemented by new translators (SymbolResolver, ScriptGenerator, MarkupGenerator).
15+
16+
## EFX-1 Support
17+
18+
Although this is a pre-release version of the EFX Toolkit, it provides production-level support for EFX-1 transpilation.
19+
EFX-1 is the current version of EFX released with SDK 1. Transpilation of EFX-1 to XPath is on par with the EFX Toolkit 1.3.0.
20+
21+
## EFX-2 Support
22+
23+
The new version of EFX is still under development and will be released with SDK 2.0.0. For more information of EFX-2 see the release notes of the eForms SDK 2.0.0-alpha.1.
24+
25+
## Breaking changes
26+
27+
For users of the Toolkit that have implemented custom transpilers, this release contains a few breaking changes.
28+
More specifically:
29+
30+
- Some additional methods have been added to the SymbolResolver, ScriptGenerator and MarkupGenerator API. As a guide for your implementations please look a the implementations included in the EFX Toolkit for use by the EFX-to-XPath transpilation.
31+
- Some deprecated methods were removed.
32+
- An extensive refactoring in the type management system has rearranged the package structure. As a result some import statements in your code will need to be updated.
33+
34+
Users of the Toolkit that only use the included EFX-to-XPath transpiler will not be affected by the above changes.
35+
36+
## Future development
37+
38+
Further alpha and beta releases of SDK 2 and EFX Toolkit 2 will be issued. While in "alpha" development stage, further braking changes may be introduced. SDK 2 and EFX 2 are expected to continue to be under development util late 2023.
1139

1240
---
1341

1442
You can download the latest EFX Toolkit from Maven Central.
1543
[![Maven Central](https://img.shields.io/maven-central/v/eu.europa.ted.eforms/efx-toolkit-java?label=Download%20&style=flat-square)](https://central.sonatype.com/artifact/eu.europa.ted.eforms/efx-toolkit-java)
1644

17-
Documentation for the EFX Toolkit is available at: https://docs.ted.europa.eu/eforms/latest/efx-toolkit
45+
Documentation for the EFX Toolkit is available at: <https://docs.ted.europa.eu/eforms/latest/efx-toolkit>
1846

1947
---
2048

2149
This version of the EFX Toolkit has a compile-time dependency on the following versions of eForms SDK versions and uses the EFX grammar that each version provides:
22-
- eForms SDK 0.6.x
23-
- eForms SDK 0.7.x
50+
2451
- eForms SDK 1.x.x
52+
- eForms SDK 2.0.0-alpha.1
2553

2654
It also depends on the [eForms Core Java library](https://github.com/OP-TED/eforms-core-java) version 1.0.5.

pom.xml

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

44
<groupId>eu.europa.ted.eforms</groupId>
55
<artifactId>efx-toolkit-java</artifactId>
6-
<version>1.3.0</version>
6+
<version>2.0.0-alpha.1</version>
77
<packaging>jar</packaging>
88

99
<name>EFX Toolkit for Java</name>
@@ -67,7 +67,7 @@
6767
<version.logback>1.2.11</version.logback>
6868
<version.jackson>2.13.4</version.jackson>
6969
<version.jackson-databind>2.13.4.2</version.jackson-databind>
70-
<version.junit-jupiter-api>5.7.2</version.junit-jupiter-api>
70+
<version.junit-jupiter>5.7.2</version.junit-jupiter>
7171
<version.slf4j>1.7.36</version.slf4j>
7272

7373
<!-- Versions - Plugins -->
@@ -120,7 +120,12 @@
120120
<dependency>
121121
<groupId>org.junit.jupiter</groupId>
122122
<artifactId>junit-jupiter-api</artifactId>
123-
<version>${version.junit-jupiter-api}</version>
123+
<version>${version.junit-jupiter}</version>
124+
</dependency>
125+
<dependency>
126+
<groupId>org.junit.jupiter</groupId>
127+
<artifactId>junit-jupiter-params</artifactId>
128+
<version>${version.junit-jupiter}</version>
124129
</dependency>
125130
<dependency>
126131
<groupId>org.antlr</groupId>
@@ -142,6 +147,11 @@
142147
<artifactId>junit-jupiter-api</artifactId>
143148
<scope>test</scope>
144149
</dependency>
150+
<dependency>
151+
<groupId>org.junit.jupiter</groupId>
152+
<artifactId>junit-jupiter-params</artifactId>
153+
<scope>test</scope>
154+
</dependency>
145155
<dependency>
146156
<groupId>org.antlr</groupId>
147157
<artifactId>antlr4-runtime</artifactId>
@@ -246,10 +256,10 @@
246256
<artifactItem>
247257
<groupId>eu.europa.ted.eforms</groupId>
248258
<artifactId>eforms-sdk</artifactId>
249-
<version>1.7.0</version>
259+
<version>2.0.0-alpha.1</version>
250260
<type>jar</type>
251261
<includes>eforms-sdk/efx-grammar/**/*.g4</includes>
252-
<outputDirectory>${sdk.antlr4.dir}/eu/europa/ted/efx/sdk1</outputDirectory>
262+
<outputDirectory>${sdk.antlr4.dir}/eu/europa/ted/efx/sdk2</outputDirectory>
253263
<fileMappers>
254264
<!-- Remove the folder prefix from filenames -->
255265
<org.codehaus.plexus.components.io.filemappers.FlattenFileMapper />
@@ -258,22 +268,10 @@
258268
<artifactItem>
259269
<groupId>eu.europa.ted.eforms</groupId>
260270
<artifactId>eforms-sdk</artifactId>
261-
<version>0.7.0</version>
271+
<version>1.6.0</version>
262272
<type>jar</type>
263273
<includes>eforms-sdk/efx-grammar/**/*.g4</includes>
264-
<outputDirectory>${sdk.antlr4.dir}/eu/europa/ted/efx/sdk0/v7</outputDirectory>
265-
<fileMappers>
266-
<!-- Remove the folder prefix from filenames -->
267-
<org.codehaus.plexus.components.io.filemappers.FlattenFileMapper />
268-
</fileMappers>
269-
</artifactItem>
270-
<artifactItem>
271-
<groupId>eu.europa.ted.eforms</groupId>
272-
<artifactId>eforms-sdk</artifactId>
273-
<version>0.6.2</version>
274-
<type>jar</type>
275-
<includes>eforms-sdk/efx-grammar/**/*.g4</includes>
276-
<outputDirectory>${sdk.antlr4.dir}/eu/europa/ted/efx/sdk0/v6</outputDirectory>
274+
<outputDirectory>${sdk.antlr4.dir}/eu/europa/ted/efx/sdk1</outputDirectory>
277275
<fileMappers>
278276
<!-- Remove the folder prefix from filenames -->
279277
<org.codehaus.plexus.components.io.filemappers.FlattenFileMapper />

src/main/java/eu/europa/ted/eforms/sdk/ComponentFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ private ComponentFactory() {
3030
* Gets the single instance containing the symbols defined in the given version of the eForms SDK.
3131
*
3232
* @param sdkVersion Version of the SDK
33+
* @param sdkRootPath Path to the root of the SDK
34+
* @return The single instance containing the symbols defined in the given version of the eForms
35+
* SDK.
36+
* @throws InstantiationException If the SDK version is not supported.
3337
*/
3438
public static SymbolResolver getSymbolResolver(final String sdkVersion, final Path sdkRootPath)
3539
throws InstantiationException {

src/main/java/eu/europa/ted/eforms/sdk/SdkSymbolResolver.java

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package eu.europa.ted.eforms.sdk;
22

33
import java.nio.file.Path;
4+
import java.util.HashMap;
45
import java.util.List;
56
import java.util.Map;
67

@@ -16,11 +17,13 @@
1617
import eu.europa.ted.eforms.sdk.repository.SdkNodeRepository;
1718
import eu.europa.ted.eforms.sdk.resource.SdkResourceLoader;
1819
import eu.europa.ted.efx.interfaces.SymbolResolver;
19-
import eu.europa.ted.efx.model.Expression.PathExpression;
20+
import eu.europa.ted.efx.model.expressions.path.NodePathExpression;
21+
import eu.europa.ted.efx.model.expressions.path.PathExpression;
22+
import eu.europa.ted.efx.model.types.FieldTypes;
23+
import eu.europa.ted.efx.xpath.XPathAttributeLocator;
2024
import eu.europa.ted.efx.xpath.XPathContextualizer;
2125

22-
@SdkComponent(versions = {"0.6", "0.7", "1"},
23-
componentType = SdkComponentType.SYMBOL_RESOLVER)
26+
@SdkComponent(versions = { "1", "2" }, componentType = SdkComponentType.SYMBOL_RESOLVER)
2427
public class SdkSymbolResolver implements SymbolResolver {
2528
protected Map<String, SdkField> fieldById;
2629

@@ -29,11 +32,13 @@ public class SdkSymbolResolver implements SymbolResolver {
2932
protected Map<String, SdkCodelist> codelistById;
3033

3134
/**
32-
* Builds EFX list from the passed codelist reference. This will lazily compute and cache the
35+
* Builds EFX list from the passed codelist reference. This will lazily compute
36+
* and cache the
3337
* result for reuse as the operation can be costly on some large lists.
3438
*
3539
* @param codelistId A reference to an SDK codelist.
36-
* @return The EFX string representation of the list of all the codes of the referenced codelist.
40+
* @return The EFX string representation of the list of all the codes of the
41+
* referenced codelist.
3742
*/
3843
@Override
3944
public final List<String> expandCodelist(final String codelistId) {
@@ -47,8 +52,9 @@ public final List<String> expandCodelist(final String codelistId) {
4752
/**
4853
* Private, use getInstance method instead.
4954
*
50-
* @param sdkVersion The version of the SDK.
51-
* @throws InstantiationException
55+
* @param sdkVersion The version of the SDK.
56+
* @param sdkRootPath The path to the root of the SDK.
57+
* @throws InstantiationException If the SDK version is not supported.
5258
*/
5359
public SdkSymbolResolver(final String sdkVersion, final Path sdkRootPath)
5460
throws InstantiationException {
@@ -93,7 +99,7 @@ public PathExpression getAbsolutePathOfField(final String fieldId) {
9399
throw new ParseCancellationException(
94100
String.format("Unknown field identifier '%s'.", fieldId));
95101
}
96-
return new PathExpression(sdkField.getXpathAbsolute());
102+
return PathExpression.instantiate(sdkField.getXpathAbsolute(), FieldTypes.fromString(sdkField.getType()));
97103
}
98104

99105
/**
@@ -106,13 +112,14 @@ public PathExpression getAbsolutePathOfNode(final String nodeId) {
106112
if (sdkNode == null) {
107113
throw new ParseCancellationException(String.format("Unknown node identifier '%s'.", nodeId));
108114
}
109-
return new PathExpression(sdkNode.getXpathAbsolute());
115+
return new NodePathExpression(sdkNode.getXpathAbsolute());
110116
}
111117

112118
/**
113119
* Gets the xPath of the given field relative to the given context.
114120
*
115-
* @param fieldId The id of the field for which we want to find the relative xPath.
121+
* @param fieldId The id of the field for which we want to find the relative
122+
* xPath.
116123
* @param contextPath xPath indicating the context.
117124
* @return The xPath of the given field relative to the given context.
118125
*/
@@ -125,7 +132,8 @@ public PathExpression getRelativePathOfField(String fieldId, PathExpression cont
125132
/**
126133
* Gets the xPath of the given node relative to the given context.
127134
*
128-
* @param nodeId The id of the node for which we want to find the relative xPath.
135+
* @param nodeId The id of the node for which we want to find the relative
136+
* xPath.
129137
* @param contextPath XPath indicating the context.
130138
* @return The XPath of the given node relative to the given context.
131139
*/
@@ -167,4 +175,62 @@ public String getRootCodelistOfField(final String fieldId) {
167175

168176
return sdkCodelist.getRootCodelistId();
169177
}
178+
179+
@Override
180+
public boolean isAttributeField(final String fieldId) {
181+
if (!additionalFieldInfoMap.containsKey(fieldId)) {
182+
this.cacheAdditionalFieldInfo(fieldId);
183+
}
184+
return additionalFieldInfoMap.get(fieldId).isAttribute;
185+
}
186+
187+
@Override
188+
public String getAttributeNameFromAttributeField(final String fieldId) {
189+
if (!additionalFieldInfoMap.containsKey(fieldId)) {
190+
this.cacheAdditionalFieldInfo(fieldId);
191+
}
192+
return additionalFieldInfoMap.get(fieldId).attributeName;
193+
}
194+
195+
@Override
196+
public PathExpression getAbsolutePathOfFieldWithoutTheAttribute(final String fieldId) {
197+
if (!additionalFieldInfoMap.containsKey(fieldId)) {
198+
this.cacheAdditionalFieldInfo(fieldId);
199+
}
200+
return additionalFieldInfoMap.get(fieldId).pathWithoutAttribute;
201+
}
202+
203+
// #region Temporary helpers ------------------------------------------------
204+
205+
/**
206+
* Temporary workaround to store additional info about fields.
207+
*
208+
* TODO: Move this additional info to SdkField class, and move the XPathAttributeLocator to the eforms-core-library.
209+
*/
210+
class AdditionalFieldInfo {
211+
public boolean isAttribute;
212+
public String attributeName;
213+
public PathExpression pathWithoutAttribute;
214+
}
215+
216+
/**
217+
* Caches the results of xpath parsing to mitigate performance impact.
218+
* This is a temporary solution until we move the additional info to the SdkField class.
219+
*/
220+
Map<String, AdditionalFieldInfo> additionalFieldInfoMap = new HashMap<>();
221+
222+
private void cacheAdditionalFieldInfo(final String fieldId) {
223+
if (additionalFieldInfoMap.containsKey(fieldId)) {
224+
return;
225+
}
226+
var parsedPath = XPathAttributeLocator.findAttribute(this.getAbsolutePathOfField(fieldId));
227+
var info = new AdditionalFieldInfo();
228+
info.isAttribute = parsedPath.hasAttribute();
229+
info.attributeName = parsedPath.getAttributeName();
230+
info.pathWithoutAttribute = parsedPath.getElementPath();
231+
additionalFieldInfoMap.put(fieldId, info);
232+
}
233+
234+
// #endregion Temporary helpers ------------------------------------------------
235+
170236
}

src/main/java/eu/europa/ted/efx/EfxTranslator.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ public class EfxTranslator {
3737
* expression to be translated.
3838
* @param expression The EFX expression to translate.
3939
* @param expressionParameters The values of any parameters that the EFX expression requires.
40+
* @param options The options to be used by the EFX expression translator.
4041
* @return The translated expression in the target script language supported by the given
4142
* {@link TranslatorDependencyFactory}.
42-
* @throws InstantiationException
43+
* @throws InstantiationException If the EFX expression translator cannot be instantiated.
4344
*/
4445
public static String translateExpression(final TranslatorDependencyFactory dependencyFactory, final String sdkVersion,
4546
final String expression, TranslatorOptions options, final String... expressionParameters)
@@ -64,8 +65,9 @@ public static String translateExpression(final TranslatorDependencyFactory depen
6465
* @param pathname The path to the file containing the EFX template to translate.
6566
* @return The translated template in the target markup language supported by the given
6667
* {@link TranslatorDependencyFactory}.
67-
* @throws IOException
68-
* @throws InstantiationException
68+
* @param options The options to be used by the EFX template translator.
69+
* @throws IOException If the file cannot be read.
70+
* @throws InstantiationException If the EFX template translator cannot be instantiated.
6971
*/
7072
public static String translateTemplate(final TranslatorDependencyFactory dependencyFactory, final String sdkVersion,
7173
final Path pathname, TranslatorOptions options)
@@ -90,7 +92,8 @@ public static String translateTemplate(final TranslatorDependencyFactory depende
9092
* @param template A string containing the EFX template to translate.
9193
* @return The translated template in the target markup language supported by the given
9294
* {@link TranslatorDependencyFactory}.
93-
* @throws InstantiationException
95+
* @param options The options to be used by the EFX template translator.
96+
* @throws InstantiationException If the EFX template translator cannot be instantiated.
9497
*/
9598
public static String translateTemplate(final TranslatorDependencyFactory dependencyFactory, final String sdkVersion,
9699
final String template, TranslatorOptions options)
@@ -116,8 +119,9 @@ public static String translateTemplate(final TranslatorDependencyFactory depende
116119
* @param stream An InputStream containing the EFX template to be translated.
117120
* @return The translated template in the target markup language supported by the given
118121
* {@link TranslatorDependencyFactory}.
119-
* @throws IOException
120-
* @throws InstantiationException
122+
* @param options The options to be used by the EFX template translator.
123+
* @throws IOException If the InputStream cannot be read.
124+
* @throws InstantiationException If the EFX template translator cannot be instantiated.
121125
*/
122126
public static String translateTemplate(final TranslatorDependencyFactory dependencyFactory, final String sdkVersion,
123127
final InputStream stream, TranslatorOptions options)

src/main/java/eu/europa/ted/efx/interfaces/EfxExpressionTranslator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public interface EfxExpressionTranslator {
2727
*
2828
* @param expression A string containing the EFX expression to be translated.
2929
* @param expressionParameters The values of any parameters that the given expression expects.
30-
* @return
30+
* @return The translated expression in the target script language.
3131
*/
3232
String translateExpression(final String expression, final String... expressionParameters);
3333
}

src/main/java/eu/europa/ted/efx/interfaces/EfxTemplateTranslator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface EfxTemplateTranslator extends EfxExpressionTranslator {
3030
*
3131
* @param pathname The path and filename of the EFX template file to translate.
3232
* @return A string containing the translated template.
33-
* @throws IOException
33+
* @throws IOException If the file cannot be read.
3434
*/
3535
String renderTemplate(Path pathname) throws IOException;
3636

@@ -47,7 +47,7 @@ public interface EfxTemplateTranslator extends EfxExpressionTranslator {
4747
*
4848
* @param stream An InputStream with the EFX template to be translated.
4949
* @return A string containing the translated template.
50-
* @throws IOException
50+
* @throws IOException If the InputStream cannot be read.
5151
*/
5252
String renderTemplate(InputStream stream) throws IOException;
5353
}

0 commit comments

Comments
 (0)