Skip to content

Commit

Permalink
Adapt to API changes in EFX Toolkit
Browse files Browse the repository at this point in the history
  • Loading branch information
bertrand-lorentz committed Apr 26, 2024
1 parent 7e27ef8 commit 8c2c38f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package eu.europa.ted.eforms.sdk.analysis.efx.mock;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import eu.europa.ted.efx.interfaces.MarkupGenerator;
import eu.europa.ted.efx.model.Expression;
import eu.europa.ted.efx.model.Expression.PathExpression;
import eu.europa.ted.efx.model.Expression.StringExpression;
import eu.europa.ted.efx.model.Markup;
import eu.europa.ted.efx.model.expressions.Expression;
import eu.europa.ted.efx.model.expressions.path.PathExpression;
import eu.europa.ted.efx.model.expressions.scalar.NumericExpression;
import eu.europa.ted.efx.model.expressions.scalar.StringExpression;
import eu.europa.ted.efx.model.templates.Markup;

public class MarkupGeneratorMock implements MarkupGenerator {
@Override
public Markup renderVariableExpression(Expression valueReference) {
return new Markup(String.format("eval(%s)", valueReference.script));
return new Markup(String.format("eval(%s)", valueReference.getScript()));
}

@Override
public Markup renderLabelFromKey(StringExpression key) {
return new Markup(String.format("label(%s)", key.script));
return new Markup(String.format("label(%s)", key.getScript()));
}

@Override
public Markup renderLabelFromExpression(Expression expression) {
return new Markup(String.format("label(%s)", expression.script));
return new Markup(String.format("label(%s)", expression.getScript()));
}

@Override
Expand All @@ -34,10 +34,6 @@ public Markup renderFreeText(String freeText) {
}

@Override
public Markup composeFragmentDefinition(String name, String number, Markup content) {
return this.composeFragmentDefinition(name, number, content, new LinkedHashSet<>());
}

public Markup composeFragmentDefinition(String name, String number, Markup content,
Set<String> parameters) {
if (StringUtils.isBlank(number)) {
Expand All @@ -49,13 +45,9 @@ public Markup composeFragmentDefinition(String name, String number, Markup conte
}

@Override
public Markup renderFragmentInvocation(String name, PathExpression context) {
return this.renderFragmentInvocation(name, context, new LinkedHashSet<>());
}

public Markup renderFragmentInvocation(String name, PathExpression context,
Set<Pair<String, String>> variables) {
return new Markup(String.format("for-each(%s).call(%s(%s))", context.script, name,
return new Markup(String.format("for-each(%s).call(%s(%s))", context.getScript(), name,
variables.stream()
.map(v -> String.format("%s:%s", v.getLeft(), v.getRight()))
.collect(Collectors.joining(", "))));
Expand All @@ -67,4 +59,25 @@ public Markup composeOutputFile(List<Markup> body, List<Markup> templates) {
templates.stream().map(t -> t.script).collect(Collectors.joining("\n")),
body.stream().map(t -> t.script).collect(Collectors.joining("\n"))));
}

@Override
public Markup renderLabelFromKey(StringExpression key, NumericExpression quantity) {
if (quantity.isEmpty()) {
return new Markup(String.format("label(%s)", key.getScript()));
}
return new Markup(String.format("label(%s, %s)", key.getScript(), quantity.getScript()));
}

@Override
public Markup renderLabelFromExpression(Expression expression, NumericExpression quantity) {
if (quantity.isEmpty()) {
return new Markup(String.format("label(%s)", expression.getScript()));
}
return new Markup(String.format("label(%s, %s)", expression.getScript(), quantity.getScript()));
}

@Override
public Markup renderLineBreak() {
return new Markup("<line-break>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import eu.europa.ted.efx.interfaces.ScriptGenerator;
import eu.europa.ted.efx.interfaces.SymbolResolver;
import eu.europa.ted.efx.interfaces.TranslatorDependencyFactory;
import eu.europa.ted.efx.interfaces.TranslatorOptions;

/**
* Validates EFX expressions and templates
Expand Down Expand Up @@ -144,16 +145,18 @@ public SymbolResolver createSymbolResolver(final String sdkVersion) {
}

@Override
public ScriptGenerator createScriptGenerator(final String sdkVersion) {
public ScriptGenerator createScriptGenerator(final String sdkVersion,
final TranslatorOptions options) {
try {
return ComponentFactory.getScriptGenerator(sdkVersion);
return ComponentFactory.getScriptGenerator(sdkVersion, options);
} catch (InstantiationException e) {
throw new RuntimeException(e.getMessage(), e);
}
}

@Override
public MarkupGenerator createMarkupGenerator(final String sdkVersion) {
public MarkupGenerator createMarkupGenerator(final String sdkVersion,
final TranslatorOptions options) {
return new MarkupGeneratorMock();
}

Expand Down

0 comments on commit 8c2c38f

Please sign in to comment.