Class TemplateUtils
java.lang.Object
be.kuleuven.cs.distrinet.sparta.io.templates.TemplateUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<? super Threat> static final Comparator<? super Threat> By risk, ascending; a threat whose risk was not calculated sorts as risk 0.static final Comparator<Threat> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringreadTemplate(String filename) Read a template resource from the bundle'stemplates/folder.static Stringsubstitute(String template, Map<String, String> replacements) Fill in every$$PLACEHOLDER$$occurrence in a single pass.
-
Field Details
-
BY_NAME
-
BY_RISK
By risk, ascending; a threat whose risk was not calculated sorts as risk 0. -
BY_TYPE_NAME
-
-
Constructor Details
-
TemplateUtils
public TemplateUtils()
-
-
Method Details
-
readTemplate
Read a template resource from the bundle'stemplates/folder.- Parameters:
filename- the template file name, e.g."report.txt"- Returns:
- the template text
- Throws:
UncheckedIOException- if the resource is missing or unreadable, so the failure propagates to the caller instead of silently embedding an error marker in the generated report
-
substitute
Fill in every$$PLACEHOLDER$$occurrence in a single pass. Unlike chainedString.replace(char, char), substituted values are never re-scanned, so a value that itself contains a placeholder-like string (e.g. an element named$$TYPE$$) is not expanded again, and the template text is copied only once. Placeholders without an entry in the map are left as-is.- Parameters:
template- the template textreplacements- placeholder (including the$$delimiters) to replacement value- Returns:
- the instantiated text
-