Skip to content

Commit a86b15b

Browse files
authored
Merge pull request #127 from OP-TED/TEDEFO-4546-4547-add-summary-and-navigation-sections
TEDEFO-4546-4547-add-summary-and-navigation-sections
2 parents 3fa5adf + acf8f0a commit a86b15b

File tree

14 files changed

+1077
-371
lines changed

14 files changed

+1077
-371
lines changed

pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<!-- Versions - eForms -->
4949
<version.eforms-sdk-1>1.13.0</version.eforms-sdk-1>
5050
<version.eforms-sdk-2>2.0.0-SNAPSHOT</version.eforms-sdk-2>
51-
<version.eforms-core>1.5.0-SNAPSHOT</version.eforms-core>
51+
<version.eforms-core>1.5.0</version.eforms-core>
5252

5353
<!-- Versions - Third-party libraries -->
5454
<version.antlr4>4.13.1</version.antlr4>
@@ -221,6 +221,15 @@
221221
<groupId>org.apache.maven.plugins</groupId>
222222
<artifactId>maven-javadoc-plugin</artifactId>
223223
<version>${version.javadoc.plugin}</version>
224+
<configuration>
225+
<doclint>all,-missing</doclint>
226+
<sourceFileExcludes>
227+
<exclude>**/EfxLexer.java</exclude>
228+
<exclude>**/EfxParser.java</exclude>
229+
<exclude>**/EfxListener.java</exclude>
230+
<exclude>**/EfxBaseListener.java</exclude>
231+
</sourceFileExcludes>
232+
</configuration>
224233
</plugin>
225234
<plugin>
226235
<groupId>org.apache.maven.plugins</groupId>

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

Lines changed: 142 additions & 47 deletions
Large diffs are not rendered by default.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package eu.europa.ted.efx.interfaces;
2+
3+
/**
4+
* Enum representing different sections of a template.
5+
*
6+
* Used in the {@link TranslatorContext} to communicate the section of the template
7+
* being processed to the {@link MarkupGenerator}.
8+
*/
9+
public enum TemplateSection {
10+
DEFAULT,
11+
SUMMARY,
12+
NAVIGATION
13+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package eu.europa.ted.efx.interfaces;
2+
3+
/**
4+
* Used to pass context information from the translator to the {@link MarkupGenerator}.
5+
*/
6+
public class TranslatorContext {
7+
8+
TemplateSection currentSection;
9+
10+
/**
11+
* Gets the current section of the template being processed.
12+
*
13+
* @return the current section
14+
*/
15+
public TemplateSection getCurrentSection() {
16+
return currentSection;
17+
}
18+
19+
public void setCurrentSection(TemplateSection currentSection) {
20+
this.currentSection = currentSection;
21+
}
22+
23+
/**
24+
* Default instance of {@link TranslatorContext} with the section set to {@link TemplateSection#DEFAULT}.
25+
* This is used throughout the code for EFX-1 processing where only the default section is relevant.
26+
*/
27+
public static final TranslatorContext DEFAULT = new TranslatorContext();
28+
29+
public TranslatorContext() {
30+
this(TemplateSection.DEFAULT);
31+
}
32+
33+
public TranslatorContext(TemplateSection currentSection) {
34+
this.currentSection = currentSection;
35+
}
36+
}

src/main/java/eu/europa/ted/efx/model/Context.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public NodeContext(final String nodeId, final PathExpression absolutePath,
5050
super(nodeId, absolutePath, relativePath);
5151
}
5252

53+
public NodeContext(final String nodeId, final PathExpression absolutePath, final Variable variable) {
54+
super(nodeId, absolutePath, variable);
55+
}
56+
5357
public NodeContext(final String nodeId, final PathExpression absolutePath) {
5458
super(nodeId, absolutePath);
5559
}

src/main/java/eu/europa/ted/efx/model/expressions/path/NodePathExpression.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ public class NodePathExpression extends PathExpression.Impl<EfxDataType.Node> {
99
public NodePathExpression(final String script) {
1010
super(script, EfxDataType.Node.class);
1111
}
12+
13+
public static NodePathExpression empty() {
14+
return new NodePathExpression("");
15+
}
1216
}

src/main/java/eu/europa/ted/efx/model/templates/ContentBlock.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import eu.europa.ted.efx.interfaces.Argument;
1515
import eu.europa.ted.efx.interfaces.MarkupGenerator;
1616
import eu.europa.ted.efx.interfaces.Parameter;
17+
import eu.europa.ted.efx.interfaces.TranslatorContext;
1718
import eu.europa.ted.efx.model.Context;
1819
import eu.europa.ted.efx.model.variables.ParsedArgument;
1920
import eu.europa.ted.efx.model.variables.ParsedArguments;
@@ -34,9 +35,9 @@ public class ContentBlock {
3435
protected final ParsedParameters parameters;
3536
protected final ParsedArguments arguments;
3637

37-
private ContentBlock() {
38+
private ContentBlock(String id) {
3839
this.parent = null;
39-
this.id = "block";
40+
this.id = id;
4041
this.indentationLevel = -1;
4142
this.conditionals = new Conditionals();
4243
this.content = new Markup("");
@@ -66,8 +67,8 @@ public ContentBlock(final ContentBlock parent, final String id, final int number
6667
new ParsedArguments(variables));
6768
}
6869

69-
public static ContentBlock newRootBlock() {
70-
return new ContentBlock();
70+
public static ContentBlock newRootBlock(String id) {
71+
return new ContentBlock(id);
7172
}
7273

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

234235
// #region Render -----------------------------------------------------------
235236

236-
public Markup renderChildren(MarkupGenerator markupGenerator) {
237+
public Markup renderChildren(MarkupGenerator markupGenerator, TranslatorContext translatorContext) {
237238
StringBuilder stringBuilder = new StringBuilder();
238239
for (ContentBlock child : this.children) {
239-
stringBuilder.append('\n').append(child.renderInvocation(markupGenerator).script);
240+
stringBuilder.append('\n').append(child.renderInvocation(markupGenerator, translatorContext).script);
240241
}
241242
return new Markup(stringBuilder.toString());
242243
}
243244

244-
public List<Markup> renderDefinition(MarkupGenerator markupGenerator) {
245+
public List<Markup> renderDefinition(MarkupGenerator markupGenerator, TranslatorContext translatorContext) {
245246
Set<Parameter> params = this.getAllParameters().stream()
246247
.map(param -> new Parameter.Impl(param.name, markupGenerator.getEfxDataTypeEquivalent(param.dataType)))
247248
.collect(Collectors.toCollection(LinkedHashSet::new));
248249
List<Markup> templates = new ArrayList<>();
249250
templates.add(markupGenerator.composeFragmentDefinition(this.id, this.getOutlineNumber(),
250251
this.conditionals.stream().collect(Collectors.toCollection(LinkedHashSet::new)),
251-
this.content, this.renderChildren(markupGenerator), params));
252+
this.content, this.renderChildren(markupGenerator, translatorContext), params, translatorContext));
252253
for (ContentBlock child : this.children) {
253-
templates.addAll(child.renderDefinition(markupGenerator));
254+
templates.addAll(child.renderDefinition(markupGenerator, translatorContext));
254255
}
255256
return templates;
256257
}
257258

258-
public Markup renderInvocation(MarkupGenerator markupGenerator) {
259+
public Markup renderInvocation(MarkupGenerator markupGenerator, TranslatorContext translatorContext) {
259260
Set<Argument> args = new LinkedHashSet<>();
260261
if (this.parent != null) {
261262
args.addAll(parent.getAllArguments().stream()
@@ -264,7 +265,7 @@ public Markup renderInvocation(MarkupGenerator markupGenerator) {
264265
}
265266
args.addAll(this.getOwnArguments().stream().map(a -> new Argument.Impl(a.name, markupGenerator.getEfxDataTypeEquivalent(a.dataType), a.value))
266267
.collect(Collectors.toCollection(LinkedHashSet::new)));
267-
var invocation = markupGenerator.renderFragmentInvocation(this.id, args);
268+
var invocation = markupGenerator.renderFragmentInvocation(this.id, args, translatorContext);
268269
return markupGenerator.renderContextLoop(this.context.relativePath(), invocation, args);
269270
}
270271

src/main/java/eu/europa/ted/efx/model/templates/TemplateInvocation.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import eu.europa.ted.efx.interfaces.Argument;
1010
import eu.europa.ted.efx.interfaces.MarkupGenerator;
11+
import eu.europa.ted.efx.interfaces.TranslatorContext;
1112
import eu.europa.ted.efx.model.Context;
1213
import eu.europa.ted.efx.model.variables.Variables;
1314

@@ -26,7 +27,7 @@ public TemplateInvocation(final ContentBlock parent, final TemplateDefinition te
2627
* Template invocations do not have own content or child content to render.
2728
*/
2829
@Override
29-
public List<Markup> renderDefinition(MarkupGenerator markupGenerator) {
30+
public List<Markup> renderDefinition(MarkupGenerator markupGenerator, TranslatorContext translatorContext) {
3031
return new ArrayList<Markup>() {
3132
};
3233
}
@@ -36,10 +37,10 @@ public List<Markup> renderDefinition(MarkupGenerator markupGenerator) {
3637
* should net have access to local variables.
3738
*/
3839
@Override
39-
public Markup renderInvocation(MarkupGenerator markupGenerator) {
40+
public Markup renderInvocation(MarkupGenerator markupGenerator, TranslatorContext translatorContext) {
4041
Set<Argument> arguments = this.getOwnArguments().stream().map(a -> new Argument.Impl(a.name, markupGenerator.getEfxDataTypeEquivalent(a.dataType), a.value))
4142
.collect(Collectors.toCollection(LinkedHashSet::new));
42-
var content = markupGenerator.renderFragmentInvocation(this.id, arguments);
43+
var content = markupGenerator.renderFragmentInvocation(this.id, arguments, translatorContext);
4344
return markupGenerator.renderContextLoop(this.context.relativePath(), content, arguments);
4445
}
4546
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import org.antlr.v4.runtime.BaseErrorListener;
1111
import org.antlr.v4.runtime.CharStreams;
1212
import org.antlr.v4.runtime.CommonTokenStream;
13-
import org.antlr.v4.runtime.ParserRuleContext;
1413
import org.antlr.v4.runtime.Token;
14+
import org.antlr.v4.runtime.misc.ParseCancellationException;
1515
import org.antlr.v4.runtime.tree.ParseTree;
1616
import org.antlr.v4.runtime.tree.ParseTreeWalker;
1717
import org.antlr.v4.runtime.tree.TerminalNode;
@@ -190,10 +190,6 @@ protected static String getFieldId(FieldReferenceContext ctx) {
190190
return getFieldId(ctx.absoluteFieldReference());
191191
}
192192

193-
if (ctx.fieldReferenceWithFieldContextOverride() != null) {
194-
return getFieldId(ctx.fieldReferenceWithFieldContextOverride().fieldReferenceWithPredicate());
195-
}
196-
197193
if (ctx.fieldReferenceInOtherNotice() != null) {
198194
return getFieldId(ctx.fieldReferenceInOtherNotice());
199195
}

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import eu.europa.ted.efx.interfaces.MarkupGenerator;
2323
import eu.europa.ted.efx.interfaces.ScriptGenerator;
2424
import eu.europa.ted.efx.interfaces.SymbolResolver;
25+
import eu.europa.ted.efx.interfaces.TranslatorContext;
2526
import eu.europa.ted.efx.model.Context;
2627
import eu.europa.ted.efx.model.Context.FieldContext;
2728
import eu.europa.ted.efx.model.Context.NodeContext;
@@ -97,7 +98,7 @@ private enum Indent {
9798
*/
9899
MarkupGenerator markup;
99100

100-
final ContentBlock rootBlock = ContentBlock.newRootBlock();
101+
final ContentBlock rootBlock = ContentBlock.newRootBlock("block");
101102

102103
/**
103104
* The block stack is used to keep track of the indentation of template lines and adjust the EFX
@@ -201,8 +202,8 @@ public void exitTemplateFile(TemplateFileContext ctx) {
201202
List<Markup> templateCalls = new ArrayList<>();
202203
List<Markup> templates = new ArrayList<>();
203204
for (ContentBlock block : this.rootBlock.getChildren()) {
204-
templateCalls.add(block.renderInvocation(markup));
205-
templates.addAll(block.renderDefinition(markup));
205+
templateCalls.add(block.renderInvocation(markup, TranslatorContext.DEFAULT));
206+
templates.addAll(block.renderDefinition(markup, TranslatorContext.DEFAULT));
206207
}
207208
Markup file = this.markup.composeOutputFile(templateCalls, templates);
208209
this.stack.push(file);
@@ -217,7 +218,7 @@ public void exitTextTemplate(TextTemplateContext ctx) {
217218
Markup template =
218219
ctx.templateFragment() != null ? this.stack.pop(Markup.class) : Markup.empty();
219220
String text = ctx.textBlock() != null ? ctx.textBlock().getText() : "";
220-
this.stack.push(this.markup.renderFreeText(this.markup.escapeSpecialCharacters(text)).join(template));
221+
this.stack.push(this.markup.renderFreeText(this.markup.escapeSpecialCharacters(text), TranslatorContext.DEFAULT).join(template));
221222
}
222223

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

239240

@@ -280,7 +281,7 @@ private void exitStandardLabelReference(StandardLabelReferenceContext ctx, Strin
280281

281282
this.stack.push(this.markup.renderLabelFromKey(this.script.composeStringConcatenation(
282283
List.of(assetType, this.script.getStringLiteralFromUnquotedString("|"), labelType,
283-
this.script.getStringLiteralFromUnquotedString("|"), assetId))));
284+
this.script.getStringLiteralFromUnquotedString("|"), assetId)), TranslatorContext.DEFAULT));
284285
}
285286

286287
/**
@@ -312,7 +313,7 @@ private void exitStandardLabelReference(StandardLabelReferenceContext ctx, Strin
312313
this.script.getStringLiteralFromUnquotedString("|"),
313314
new StringExpression(loopVariable.referenceExpression.getScript()))),
314315
StringSequenceExpression.class),
315-
StringSequenceExpression.class)));
316+
StringSequenceExpression.class), TranslatorContext.DEFAULT));
316317
}
317318

318319

@@ -324,7 +325,7 @@ public void exitShorthandBtLabelReference(ShorthandBtLabelReferenceContext ctx)
324325
this.stack.push(this.markup.renderLabelFromKey(this.script.composeStringConcatenation(
325326
List.of(this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_BT),
326327
this.script.getStringLiteralFromUnquotedString("|"), labelType,
327-
this.script.getStringLiteralFromUnquotedString("|"), assetId))));
328+
this.script.getStringLiteralFromUnquotedString("|"), assetId)), TranslatorContext.DEFAULT));
328329
}
329330

330331
@Override
@@ -340,7 +341,7 @@ public void exitShorthandFieldLabelReference(ShorthandFieldLabelReferenceContext
340341
List.of(this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_FIELD),
341342
this.script.getStringLiteralFromUnquotedString("|"), labelType,
342343
this.script.getStringLiteralFromUnquotedString("|"),
343-
this.script.getStringLiteralFromUnquotedString(fieldId)))));
344+
this.script.getStringLiteralFromUnquotedString(fieldId))), TranslatorContext.DEFAULT));
344345
}
345346
}
346347

@@ -378,7 +379,7 @@ private void shorthandIndirectLabelReference(final String fieldId) {
378379
this.script.getStringLiteralFromUnquotedString("|"),
379380
this.script.getStringLiteralFromUnquotedString(fieldId))),
380381
StringSequenceExpression.class),
381-
StringSequenceExpression.class)));
382+
StringSequenceExpression.class), TranslatorContext.DEFAULT));
382383
break;
383384
case "code":
384385
case "internal-code":
@@ -398,7 +399,7 @@ private void shorthandIndirectLabelReference(final String fieldId) {
398399
this.script.getStringLiteralFromUnquotedString("."),
399400
new StringExpression(loopVariable.referenceExpression.getScript()))),
400401
StringSequenceExpression.class),
401-
StringSequenceExpression.class)));
402+
StringSequenceExpression.class), TranslatorContext.DEFAULT));
402403
break;
403404
default:
404405
throw InvalidUsageException.shorthandRequiresCodeOrIndicator(fieldId, fieldType);
@@ -425,15 +426,15 @@ public void exitShorthandLabelReferenceFromContext(ShorthandLabelReferenceFromCo
425426
this.script.getStringLiteralFromUnquotedString("|"),
426427
this.script.getStringLiteralFromUnquotedString(labelType),
427428
this.script.getStringLiteralFromUnquotedString("|"),
428-
this.script.getStringLiteralFromUnquotedString(this.efxContext.symbol())))));
429+
this.script.getStringLiteralFromUnquotedString(this.efxContext.symbol()))), TranslatorContext.DEFAULT));
429430
}
430431
} else if (this.efxContext.isNodeContext()) {
431432
this.stack.push(this.markup.renderLabelFromKey(this.script.composeStringConcatenation(
432433
List.of(this.script.getStringLiteralFromUnquotedString(ASSET_TYPE_NODE),
433434
this.script.getStringLiteralFromUnquotedString("|"),
434435
this.script.getStringLiteralFromUnquotedString(labelType),
435436
this.script.getStringLiteralFromUnquotedString("|"),
436-
this.script.getStringLiteralFromUnquotedString(this.efxContext.symbol())))));
437+
this.script.getStringLiteralFromUnquotedString(this.efxContext.symbol()))), TranslatorContext.DEFAULT));
437438
}
438439
}
439440

0 commit comments

Comments
 (0)