Class Markup

java.lang.Object
ch.tocco.nice2.toolbox.api.markup.Markup

public class Markup extends Object
This utility class provides functionality to replace certain markup pieces in a markup string.

Example with using the Freemarker markup:

  

[@testmacro param="test"/]

[#macro testmacro param=""] param: ${param} [/#macro] is transformed to

[replacement-]

[replacement-] param: [replacement-] [replacement-]
Now the markup can be parsed and modified. For example HTML entities can be encoded and it won't break any freemarker code.

Once all modifications are done, the extracted freemarker tags can be reinserted by calling reinsert(Replaced).

  • Constructor Details

    • Markup

      public Markup(Pattern replacePattern)
  • Method Details

    • freemarker

      public static Markup freemarker()
      Create an instance to replace all freemarker markup. This includes: - all tags like [#if ...], [/#if], [#assign .../], [#macro mymacro...], ... - macro calls like [@mymacro ...] - variable printing like ${myVar}
      Returns:
      an instance of Markup to replace freemarker markup.
    • getReplacePattern

      public Pattern getReplacePattern()
    • replace

      public Markup.Replaced replace(String markup)
      Replace all strings matching the given replacePattern with [replacement-<uuid>].
      Parameters:
      markup - Any markup string.
      Returns:
      an object containing the new markup string and a map with all replacements.
    • reinsert

      public String reinsert(Markup.Replaced replaced)
      Replace all [replacement-] strings with the corresponding extraction.
      Returns:
      the markup string