Class TemplateUtils

java.lang.Object
be.kuleuven.cs.distrinet.sparta.io.templates.TemplateUtils

public class TemplateUtils extends Object
  • Field Details

    • BY_NAME

      public static final Comparator<? super Threat> BY_NAME
    • BY_RISK

      public static final Comparator<? super Threat> BY_RISK
      By risk, ascending; a threat whose risk was not calculated sorts as risk 0.
    • BY_TYPE_NAME

      public static final Comparator<Threat> BY_TYPE_NAME
  • Constructor Details

    • TemplateUtils

      public TemplateUtils()
  • Method Details

    • readTemplate

      public static String readTemplate(String filename)
      Read a template resource from the bundle's templates/ 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

      public static String substitute(String template, Map<String,String> replacements)
      Fill in every $$PLACEHOLDER$$ occurrence in a single pass. Unlike chained String.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 text
      replacements - placeholder (including the $$ delimiters) to replacement value
      Returns:
      the instantiated text