Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<!-- Versions - eForms -->
<version.eforms-sdk-1>1.13.0</version.eforms-sdk-1>
<version.eforms-sdk-2>2.0.0-SNAPSHOT</version.eforms-sdk-2>
<version.eforms-core>1.5.0-SNAPSHOT</version.eforms-core>
<version.eforms-core>1.5.0</version.eforms-core>

<!-- Versions - Third-party libraries -->
<version.antlr4>4.13.1</version.antlr4>
Expand Down Expand Up @@ -221,6 +221,15 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${version.javadoc.plugin}</version>
<configuration>
<doclint>all,-missing</doclint>
<sourceFileExcludes>
<exclude>**/EfxLexer.java</exclude>
<exclude>**/EfxParser.java</exclude>
<exclude>**/EfxListener.java</exclude>
<exclude>**/EfxBaseListener.java</exclude>
</sourceFileExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
189 changes: 142 additions & 47 deletions src/main/java/eu/europa/ted/efx/interfaces/MarkupGenerator.java

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/main/java/eu/europa/ted/efx/interfaces/TemplateSection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package eu.europa.ted.efx.interfaces;

/**
* Enum representing different sections of a template.
*
* Used in the {@link TranslatorContext} to communicate the section of the template
* being processed to the {@link MarkupGenerator}.
*/
public enum TemplateSection {
DEFAULT,
SUMMARY,
NAVIGATION
}
36 changes: 36 additions & 0 deletions src/main/java/eu/europa/ted/efx/interfaces/TranslatorContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package eu.europa.ted.efx.interfaces;

/**
* Used to pass context information from the translator to the {@link MarkupGenerator}.
*/
public class TranslatorContext {

TemplateSection currentSection;

/**
* Gets the current section of the template being processed.
*
* @return the current section
*/
public TemplateSection getCurrentSection() {
return currentSection;
}

public void setCurrentSection(TemplateSection currentSection) {
this.currentSection = currentSection;
}

/**
* Default instance of {@link TranslatorContext} with the section set to {@link TemplateSection#DEFAULT}.
* This is used throughout the code for EFX-1 processing where only the default section is relevant.
*/
public static final TranslatorContext DEFAULT = new TranslatorContext();

public TranslatorContext() {
this(TemplateSection.DEFAULT);
}

public TranslatorContext(TemplateSection currentSection) {
this.currentSection = currentSection;
}
}
4 changes: 4 additions & 0 deletions src/main/java/eu/europa/ted/efx/model/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public NodeContext(final String nodeId, final PathExpression absolutePath,
super(nodeId, absolutePath, relativePath);
}

public NodeContext(final String nodeId, final PathExpression absolutePath, final Variable variable) {
super(nodeId, absolutePath, variable);
}

public NodeContext(final String nodeId, final PathExpression absolutePath) {
super(nodeId, absolutePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public class NodePathExpression extends PathExpression.Impl<EfxDataType.Node> {
public NodePathExpression(final String script) {
super(script, EfxDataType.Node.class);
}

public static NodePathExpression empty() {
return new NodePathExpression("");
}
}
23 changes: 12 additions & 11 deletions src/main/java/eu/europa/ted/efx/model/templates/ContentBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import eu.europa.ted.efx.interfaces.Argument;
import eu.europa.ted.efx.interfaces.MarkupGenerator;
import eu.europa.ted.efx.interfaces.Parameter;
import eu.europa.ted.efx.interfaces.TranslatorContext;
import eu.europa.ted.efx.model.Context;
import eu.europa.ted.efx.model.variables.ParsedArgument;
import eu.europa.ted.efx.model.variables.ParsedArguments;
Expand All @@ -34,9 +35,9 @@ public class ContentBlock {
protected final ParsedParameters parameters;
protected final ParsedArguments arguments;

private ContentBlock() {
private ContentBlock(String id) {
this.parent = null;
this.id = "block";
this.id = id;
this.indentationLevel = -1;
this.conditionals = new Conditionals();
this.content = new Markup("");
Expand Down Expand Up @@ -66,8 +67,8 @@ public ContentBlock(final ContentBlock parent, final String id, final int number
new ParsedArguments(variables));
}

public static ContentBlock newRootBlock() {
return new ContentBlock();
public static ContentBlock newRootBlock(String id) {
return new ContentBlock(id);
}

// #region Add Children
Expand Down Expand Up @@ -233,29 +234,29 @@ protected Set<ParsedArgument> getAllArguments() {

// #region Render -----------------------------------------------------------

public Markup renderChildren(MarkupGenerator markupGenerator) {
public Markup renderChildren(MarkupGenerator markupGenerator, TranslatorContext translatorContext) {
StringBuilder stringBuilder = new StringBuilder();
for (ContentBlock child : this.children) {
stringBuilder.append('\n').append(child.renderInvocation(markupGenerator).script);
stringBuilder.append('\n').append(child.renderInvocation(markupGenerator, translatorContext).script);
}
return new Markup(stringBuilder.toString());
}

public List<Markup> renderDefinition(MarkupGenerator markupGenerator) {
public List<Markup> renderDefinition(MarkupGenerator markupGenerator, TranslatorContext translatorContext) {
Set<Parameter> params = this.getAllParameters().stream()
.map(param -> new Parameter.Impl(param.name, markupGenerator.getEfxDataTypeEquivalent(param.dataType)))
.collect(Collectors.toCollection(LinkedHashSet::new));
List<Markup> templates = new ArrayList<>();
templates.add(markupGenerator.composeFragmentDefinition(this.id, this.getOutlineNumber(),
this.conditionals.stream().collect(Collectors.toCollection(LinkedHashSet::new)),
this.content, this.renderChildren(markupGenerator), params));
this.content, this.renderChildren(markupGenerator, translatorContext), params, translatorContext));
for (ContentBlock child : this.children) {
templates.addAll(child.renderDefinition(markupGenerator));
templates.addAll(child.renderDefinition(markupGenerator, translatorContext));
}
return templates;
}

public Markup renderInvocation(MarkupGenerator markupGenerator) {
public Markup renderInvocation(MarkupGenerator markupGenerator, TranslatorContext translatorContext) {
Set<Argument> args = new LinkedHashSet<>();
if (this.parent != null) {
args.addAll(parent.getAllArguments().stream()
Expand All @@ -264,7 +265,7 @@ public Markup renderInvocation(MarkupGenerator markupGenerator) {
}
args.addAll(this.getOwnArguments().stream().map(a -> new Argument.Impl(a.name, markupGenerator.getEfxDataTypeEquivalent(a.dataType), a.value))
.collect(Collectors.toCollection(LinkedHashSet::new)));
var invocation = markupGenerator.renderFragmentInvocation(this.id, args);
var invocation = markupGenerator.renderFragmentInvocation(this.id, args, translatorContext);
return markupGenerator.renderContextLoop(this.context.relativePath(), invocation, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import eu.europa.ted.efx.interfaces.Argument;
import eu.europa.ted.efx.interfaces.MarkupGenerator;
import eu.europa.ted.efx.interfaces.TranslatorContext;
import eu.europa.ted.efx.model.Context;
import eu.europa.ted.efx.model.variables.Variables;

Expand All @@ -26,7 +27,7 @@ public TemplateInvocation(final ContentBlock parent, final TemplateDefinition te
* Template invocations do not have own content or child content to render.
*/
@Override
public List<Markup> renderDefinition(MarkupGenerator markupGenerator) {
public List<Markup> renderDefinition(MarkupGenerator markupGenerator, TranslatorContext translatorContext) {
return new ArrayList<Markup>() {
};
}
Expand All @@ -36,10 +37,10 @@ public List<Markup> renderDefinition(MarkupGenerator markupGenerator) {
* should net have access to local variables.
*/
@Override
public Markup renderInvocation(MarkupGenerator markupGenerator) {
public Markup renderInvocation(MarkupGenerator markupGenerator, TranslatorContext translatorContext) {
Set<Argument> arguments = this.getOwnArguments().stream().map(a -> new Argument.Impl(a.name, markupGenerator.getEfxDataTypeEquivalent(a.dataType), a.value))
.collect(Collectors.toCollection(LinkedHashSet::new));
var content = markupGenerator.renderFragmentInvocation(this.id, arguments);
var content = markupGenerator.renderFragmentInvocation(this.id, arguments, translatorContext);
return markupGenerator.renderContextLoop(this.context.relativePath(), content, arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.antlr.v4.runtime.tree.TerminalNode;
Expand Down Expand Up @@ -190,10 +190,6 @@ protected static String getFieldId(FieldReferenceContext ctx) {
return getFieldId(ctx.absoluteFieldReference());
}

if (ctx.fieldReferenceWithFieldContextOverride() != null) {
return getFieldId(ctx.fieldReferenceWithFieldContextOverride().fieldReferenceWithPredicate());
}

if (ctx.fieldReferenceInOtherNotice() != null) {
return getFieldId(ctx.fieldReferenceInOtherNotice());
}
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/eu/europa/ted/efx/sdk1/EfxTemplateTranslatorV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import eu.europa.ted.efx.interfaces.MarkupGenerator;
import eu.europa.ted.efx.interfaces.ScriptGenerator;
import eu.europa.ted.efx.interfaces.SymbolResolver;
import eu.europa.ted.efx.interfaces.TranslatorContext;
import eu.europa.ted.efx.model.Context;
import eu.europa.ted.efx.model.Context.FieldContext;
import eu.europa.ted.efx.model.Context.NodeContext;
Expand Down Expand Up @@ -97,7 +98,7 @@ private enum Indent {
*/
MarkupGenerator markup;

final ContentBlock rootBlock = ContentBlock.newRootBlock();
final ContentBlock rootBlock = ContentBlock.newRootBlock("block");

/**
* The block stack is used to keep track of the indentation of template lines and adjust the EFX
Expand Down Expand Up @@ -201,8 +202,8 @@ public void exitTemplateFile(TemplateFileContext ctx) {
List<Markup> templateCalls = new ArrayList<>();
List<Markup> templates = new ArrayList<>();
for (ContentBlock block : this.rootBlock.getChildren()) {
templateCalls.add(block.renderInvocation(markup));
templates.addAll(block.renderDefinition(markup));
templateCalls.add(block.renderInvocation(markup, TranslatorContext.DEFAULT));
templates.addAll(block.renderDefinition(markup, TranslatorContext.DEFAULT));
}
Markup file = this.markup.composeOutputFile(templateCalls, templates);
this.stack.push(file);
Expand All @@ -217,7 +218,7 @@ public void exitTextTemplate(TextTemplateContext ctx) {
Markup template =
ctx.templateFragment() != null ? this.stack.pop(Markup.class) : Markup.empty();
String text = ctx.textBlock() != null ? ctx.textBlock().getText() : "";
this.stack.push(this.markup.renderFreeText(this.markup.escapeSpecialCharacters(text)).join(template));
this.stack.push(this.markup.renderFreeText(this.markup.escapeSpecialCharacters(text), TranslatorContext.DEFAULT).join(template));
}

@Override
Expand All @@ -233,7 +234,7 @@ public void exitExpressionTemplate(ExpressionTemplateContext ctx) {
Markup template =
ctx.templateFragment() != null ? this.stack.pop(Markup.class) : Markup.empty();
Expression expression = this.stack.pop(Expression.class);
this.stack.push(this.markup.renderVariableExpression(expression).join(template));
this.stack.push(this.markup.renderVariableExpression(expression, TranslatorContext.DEFAULT).join(template));
}


Expand Down Expand Up @@ -280,7 +281,7 @@ private void exitStandardLabelReference(StandardLabelReferenceContext ctx, Strin

this.stack.push(this.markup.renderLabelFromKey(this.script.composeStringConcatenation(
List.of(assetType, this.script.getStringLiteralFromUnquotedString("|"), labelType,
this.script.getStringLiteralFromUnquotedString("|"), assetId))));
this.script.getStringLiteralFromUnquotedString("|"), assetId)), TranslatorContext.DEFAULT));
}

/**
Expand Down Expand Up @@ -312,7 +313,7 @@ private void exitStandardLabelReference(StandardLabelReferenceContext ctx, Strin
this.script.getStringLiteralFromUnquotedString("|"),
new StringExpression(loopVariable.referenceExpression.getScript()))),
StringSequenceExpression.class),
StringSequenceExpression.class)));
StringSequenceExpression.class), TranslatorContext.DEFAULT));
}


Expand All @@ -324,7 +325,7 @@ public void exitShorthandBtLabelReference(ShorthandBtLabelReferenceContext ctx)
this.stack.push(this.markup.renderLabelFromKey(this.script.composeStringConcatenation(
List.of(this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_BT),
this.script.getStringLiteralFromUnquotedString("|"), labelType,
this.script.getStringLiteralFromUnquotedString("|"), assetId))));
this.script.getStringLiteralFromUnquotedString("|"), assetId)), TranslatorContext.DEFAULT));
}

@Override
Expand All @@ -340,7 +341,7 @@ public void exitShorthandFieldLabelReference(ShorthandFieldLabelReferenceContext
List.of(this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_FIELD),
this.script.getStringLiteralFromUnquotedString("|"), labelType,
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(fieldId)))));
this.script.getStringLiteralFromUnquotedString(fieldId))), TranslatorContext.DEFAULT));
}
}

Expand Down Expand Up @@ -378,7 +379,7 @@ private void shorthandIndirectLabelReference(final String fieldId) {
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(fieldId))),
StringSequenceExpression.class),
StringSequenceExpression.class)));
StringSequenceExpression.class), TranslatorContext.DEFAULT));
break;
case "code":
case "internal-code":
Expand All @@ -398,7 +399,7 @@ private void shorthandIndirectLabelReference(final String fieldId) {
this.script.getStringLiteralFromUnquotedString("."),
new StringExpression(loopVariable.referenceExpression.getScript()))),
StringSequenceExpression.class),
StringSequenceExpression.class)));
StringSequenceExpression.class), TranslatorContext.DEFAULT));
break;
default:
throw InvalidUsageException.shorthandRequiresCodeOrIndicator(fieldId, fieldType);
Expand All @@ -425,15 +426,15 @@ public void exitShorthandLabelReferenceFromContext(ShorthandLabelReferenceFromCo
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(labelType),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(this.efxContext.symbol())))));
this.script.getStringLiteralFromUnquotedString(this.efxContext.symbol()))), TranslatorContext.DEFAULT));
}
} else if (this.efxContext.isNodeContext()) {
this.stack.push(this.markup.renderLabelFromKey(this.script.composeStringConcatenation(
List.of(this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_NODE),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(labelType),
this.script.getStringLiteralFromUnquotedString("|"),
this.script.getStringLiteralFromUnquotedString(this.efxContext.symbol())))));
this.script.getStringLiteralFromUnquotedString(this.efxContext.symbol()))), TranslatorContext.DEFAULT));
}
}

Expand Down
Loading