Skip to content

Commit ddf7c05

Browse files
committed
Add support for hyperlinks in view templates.
1 parent a1263bb commit ddf7c05

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/main/java/eu/europa/ted/efx/sdk2/EfxTemplateTranslatorV2.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,20 +414,41 @@ public void exitTextTemplate(TextTemplateContext ctx) {
414414
this.stack.push(this.markup.renderFreeText(this.markup.escapeSpecialCharacters(text), this.translatorContext).join(template));
415415
}
416416

417+
@Override
418+
public void exitLinkedTextTemplate(LinkedTextTemplateContext ctx) {
419+
Markup template = ctx.templateFragment() != null ? this.stack.pop(Markup.class) : Markup.empty();
420+
Markup text = this.stack.pop(Markup.class);
421+
this.stack.push(text.join(template));
422+
}
423+
417424
@Override
418425
public void exitLabelTemplate(LabelTemplateContext ctx) {
419426
Markup template = ctx.templateFragment() != null ? this.stack.pop(Markup.class) : Markup.empty();
420427
Markup label = ctx.labelBlock() != null ? this.stack.pop(Markup.class) : Markup.empty();
421428
this.stack.push(label.join(template));
422429
}
423430

431+
@Override
432+
public void exitLinkedLabelTemplate(LinkedLabelTemplateContext ctx) {
433+
Markup template = ctx.templateFragment() != null ? this.stack.pop(Markup.class) : Markup.empty();
434+
Markup label = this.stack.pop(Markup.class);
435+
this.stack.push(label.join(template));
436+
}
437+
424438
@Override
425439
public void exitExpressionTemplate(ExpressionTemplateContext ctx) {
426440
Markup template = ctx.templateFragment() != null ? this.stack.pop(Markup.class) : Markup.empty();
427441
Expression expression = this.stack.pop(Expression.class);
428442
this.stack.push(this.markup.renderVariableExpression(expression, this.translatorContext).join(template));
429443
}
430444

445+
@Override
446+
public void exitLinkedExpressionTemplate(LinkedExpressionTemplateContext ctx) {
447+
Markup template = ctx.templateFragment() != null ? this.stack.pop(Markup.class) : Markup.empty();
448+
Markup link = this.stack.pop(Markup.class);
449+
this.stack.push(link.join(template));
450+
}
451+
431452
// #region New in EFX-2: Secondary templates --------------------------------
432453

433454
@Override
@@ -698,6 +719,7 @@ public void exitComputedLabelReference(ComputedLabelReferenceContext ctx) {
698719
this.stack.push(this.markup.renderLabelFromExpression(expression, quantity, this.translatorContext));
699720
}
700721

722+
701723
@Override
702724
public void exitDictionaryDeclaration(DictionaryDeclarationContext ctx) {
703725
String name = ctx.dictionaryName.getText();
@@ -980,6 +1002,31 @@ public void exitTemplateVariableDeclaration(TemplateVariableDeclarationContext a
9801002

9811003
// #endregion Variable Initializers -----------------------------------------
9821004

1005+
// #region Hyperlinks -------------------------------------------------------
1006+
1007+
@Override
1008+
public void exitLinkedTextBlock(LinkedTextBlockContext ctx) {
1009+
var url = this.stack.pop(StringExpression.class);
1010+
var text = this.markup.renderFreeText(ctx.textBlock().getText(), this.translatorContext);
1011+
this.stack.push(this.markup.renderHyperlink(text, url, this.translatorContext));
1012+
}
1013+
1014+
@Override
1015+
public void exitLinkedLabelBlock(LinkedLabelBlockContext ctx) {
1016+
var url = this.stack.pop(StringExpression.class);
1017+
var text = this.stack.pop(Markup.class);
1018+
this.stack.push(this.markup.renderHyperlink(text, url, this.translatorContext));
1019+
}
1020+
1021+
@Override
1022+
public void exitLinkedExpressionBlock(LinkedExpressionBlockContext ctx) {
1023+
var url = this.stack.pop(StringExpression.class);
1024+
var text = this.markup.renderVariableExpression(this.stack.pop(Expression.class), this.translatorContext);
1025+
this.stack.push(this.markup.renderHyperlink(text, url, this.translatorContext));
1026+
}
1027+
1028+
// #endregion Hyperlinks ----------------------------------------------------
1029+
9831030
// #endregion New in EFX-2 --------------------------------------------------
9841031

9851032
@Override

0 commit comments

Comments
 (0)