Skip to content

Commit a0b47bd

Browse files
authored
Merge pull request #54 from OP-TED/bugfix/TEDEFO-1451-labels-from-sequence
Added support for rendering multiple labels from sequences in shortha…
2 parents bfc0978 + ccb7a3b commit a0b47bd

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

src/main/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1.java

+30-17
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import eu.europa.ted.efx.model.Expression;
2929
import eu.europa.ted.efx.model.Expression.PathExpression;
3030
import eu.europa.ted.efx.model.Expression.StringExpression;
31+
import eu.europa.ted.efx.model.Expression.StringListExpression;
3132
import eu.europa.ted.efx.model.Markup;
3233
import eu.europa.ted.efx.sdk1.EfxParser.*;
3334
import eu.europa.ted.efx.xpath.XPathAttributeLocator;
@@ -276,33 +277,45 @@ private void shorthandIndirectLabelReference(final String fieldId) {
276277
final Context currentContext = this.efxContext.peek();
277278
final String fieldType = this.symbols.getTypeOfField(fieldId);
278279
final XPathAttributeLocator parsedPath = XPathAttributeLocator.findAttribute(symbols.getAbsolutePathOfField(fieldId));
279-
final StringExpression valueReference = parsedPath.hasAttribute()
280-
? this.script.composeFieldAttributeReference(symbols.getRelativePath(parsedPath.getPath(), currentContext.absolutePath()) ,
281-
parsedPath.getAttribute(), StringExpression.class)
282-
: this.script.composeFieldValueReference(symbols.getRelativePathOfField(fieldId, currentContext.absolutePath()), StringExpression.class);
280+
final PathExpression valueReference = parsedPath.hasAttribute()
281+
? this.script.composeFieldAttributeReference(
282+
symbols.getRelativePath(parsedPath.getPath(), currentContext.absolutePath()),
283+
parsedPath.getAttribute(), PathExpression.class)
284+
: this.script.composeFieldValueReference(
285+
symbols.getRelativePathOfField(fieldId, currentContext.absolutePath()),
286+
PathExpression.class);
287+
final String loopVariableName = "$item";
283288

284289
switch (fieldType) {
285290
case "indicator":
286-
this.stack
287-
.push(this.markup.renderLabelFromExpression(this.script.composeStringConcatenation(
291+
this.stack.push(this.markup.renderLabelFromExpression(this.script.composeForExpression(
292+
this.script.composeIteratorList(
293+
List.of(this.script.composeIteratorExpression(loopVariableName, valueReference))),
294+
this.script.composeStringConcatenation(
288295
List.of(this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_INDICATOR),
289296
this.script.getStringLiteralFromUnquotedString("|"),
290297
this.script.getStringLiteralFromUnquotedString(LABEL_TYPE_WHEN),
291-
this.script.getStringLiteralFromUnquotedString("-"), valueReference,
298+
this.script.getStringLiteralFromUnquotedString("-"),
299+
this.script.composeVariableReference(loopVariableName, StringExpression.class),
292300
this.script.getStringLiteralFromUnquotedString("|"),
293-
this.script.getStringLiteralFromUnquotedString(fieldId)))));
301+
this.script.getStringLiteralFromUnquotedString(fieldId))),
302+
StringListExpression.class)));
294303
break;
295304
case "code":
296305
case "internal-code":
297-
this.stack
298-
.push(this.markup.renderLabelFromExpression(this.script.composeStringConcatenation(
299-
List.of(this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_CODE),
300-
this.script.getStringLiteralFromUnquotedString("|"),
301-
this.script.getStringLiteralFromUnquotedString(LABEL_TYPE_NAME),
302-
this.script.getStringLiteralFromUnquotedString("|"),
303-
this.script.getStringLiteralFromUnquotedString(
304-
this.symbols.getRootCodelistOfField(fieldId)),
305-
this.script.getStringLiteralFromUnquotedString("."), valueReference))));
306+
this.stack.push(this.markup.renderLabelFromExpression(this.script.composeForExpression(
307+
this.script.composeIteratorList(
308+
List.of(this.script.composeIteratorExpression(loopVariableName, valueReference))),
309+
this.script.composeStringConcatenation(List.of(
310+
this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_CODE),
311+
this.script.getStringLiteralFromUnquotedString("|"),
312+
this.script.getStringLiteralFromUnquotedString(LABEL_TYPE_NAME),
313+
this.script.getStringLiteralFromUnquotedString("|"),
314+
this.script.getStringLiteralFromUnquotedString(
315+
this.symbols.getRootCodelistOfField(fieldId)),
316+
this.script.getStringLiteralFromUnquotedString("."),
317+
this.script.composeVariableReference(loopVariableName, StringExpression.class))),
318+
StringListExpression.class)));
306319
break;
307320
default:
308321
throw new ParseCancellationException(String.format(

0 commit comments

Comments
 (0)