de.caff.util

## Class TextTemplateHandler<T>

- java.lang.Object
- - de.caff.util.TextTemplateHandler<T>

- Direct Known Subclasses:
    TextTemplateHandler.WithoutContext

      public class TextTemplateHandler<T>
      extends java.lang.Object

  Simple template handler allowing to expand special strings in texts.
  Since:
    August 12, 2019
  Author:
    Rammi

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `TextTemplateHandler.CtxExpander<T>` Expander which uses a context.
    `static interface` | `TextTemplateHandler.Expander` Context-less expander.
    `static class` | `TextTemplateHandler.WithoutContext` Helper class.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TextTemplateHandler()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `expand(java.lang.String text, T context)` Expand a string with the given context.
    `void` | `register(java.util.regex.Pattern pattern, TextTemplateHandler.CtxExpander<T> expander)` Register an expander for a regular expression pattern.
    `void` | `register(java.lang.String sequence, TextTemplateHandler.CtxExpander<T> expander)` Register an expander for a simple string pattern.
    `static TextTemplateHandler.WithoutContext` | `withoutContext()` Factory method for a text template handler which does not use a context.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TextTemplateHandler

          public TextTemplateHandler()

  - ### Method Detail

    - #### register

          public void register(@NotNull
                               java.util.regex.Pattern pattern,
                               @NotNull
                               TextTemplateHandler.CtxExpander<T> expander)

      Register an expander for a regular expression pattern.
      Parameters:
        `pattern` - pattern to look for
        `expander` - expander to be called if pattern is found

    - #### register

          public void register(@NotNull
                               java.lang.String sequence,
                               @NotNull
                               TextTemplateHandler.CtxExpander<T> expander)

      Register an expander for a simple string pattern.
      Parameters:
        `sequence` - string sequence to look for
        `expander` - expander to be called if sequence is found

    - #### expand

          @NotNull
          public java.lang.String expand(@NotNull
                                                  java.lang.String text,
                                                  @NotNull
                                                  T context)
                                           throws java.io.IOException

      Expand a string with the given context.
      Parameters:
        `text` - text string
        `context` - context to use for expansion
      Returns:
        expanded string
      Throws:
        `java.io.IOException` - on expansion errors

    - #### withoutContext

          @NotNull
          public static TextTemplateHandler.WithoutContext withoutContext()

      Factory method for a text template handler which does not use a context.
      Returns:
        context-less handler