public class SimpleTemplateParser
extends java.lang.Object
It understands a few simple substitutions:
{tag} will be substituted by the resolved value of tag.{[tag<deco>}<template>{]tag} will be substituted by a multiple insertion of the inner part.
Repeating the tag in the closing marker is optional but recommended, as it allows
to detect incorrect nesting.
The decoration <deco> contains three optional parts:
prefix (marked with '^') which will be inserted
at the beginning if at least one multiple insertion is performed.
It has the format ^<m><template><m>. <m> is a character used to enclose the template.
It can be freely chosen, with the only limitation that it must not appear in the template text itself.
separator (marked with '|') which will be inserted between
multiple insertions.
It has the format |<m><template><m>. <m> is a character used to enclose the template.
It can be freely chosen, with the only limitation that it must not appear in the template text itself.
suffix (marked with '$') which will be inserted at the end
if at least one multiple insertion was performed.
It has the format $<m><template><m>. <m> is a character used to enclose the template.
It can be freely chosen, with the only limitation that it must not appear in the template text itself.
{@mark} will be substituted by anything the given partial template provider returns.
It is most useful for inserting templates created from other files, or for inserting the same
template more than once, if the given SubTemplateProvider returns the same template
for the same mark (easily done with SubTemplateProvider.withCache()).
| Modifier and Type | Class and Description |
|---|---|
static interface |
SimpleTemplateParser.CharStepper |
| Modifier and Type | Field and Description |
|---|---|
static IntPredicate1 |
DEFAULT_ALLOWED_KEYS
The default allowed characters for names.
|
| Constructor and Description |
|---|
SimpleTemplateParser(SubTemplateProvider subTemplateProvider) |
SimpleTemplateParser(SubTemplateProvider subTemplateProvider,
java.util.function.IntPredicate allowedKeys) |
| Modifier and Type | Method and Description |
|---|---|
static void |
main(java.lang.String[] args)
Test code.
|
static Template |
parse(java.io.File file,
SubTemplateProvider subTemplateProvider) |
Template |
parse(java.io.Reader reader) |
static Template |
parse(java.io.Reader reader,
SubTemplateProvider subTemplateProvider) |
Template |
parse(SimpleTemplateParser.CharStepper stepper) |
Template |
parse(java.lang.String text) |
static Template |
parse(java.lang.String text,
SubTemplateProvider subTemplateProvider) |
public static final IntPredicate1 DEFAULT_ALLOWED_KEYS
All alphabetic characters.All digits.'-'.'_'.public SimpleTemplateParser(@NotNull SubTemplateProvider subTemplateProvider)
public SimpleTemplateParser(@NotNull SubTemplateProvider subTemplateProvider, @NotNull java.util.function.IntPredicate allowedKeys)
@NotNull public Template parse(@NotNull java.io.Reader reader) throws java.io.IOException
java.io.IOException@NotNull public Template parse(@NotNull java.lang.String text) throws java.io.IOException
java.io.IOException@NotNull public Template parse(@NotNull SimpleTemplateParser.CharStepper stepper) throws java.io.IOException
java.io.IOException@NotNull public static Template parse(@NotNull java.io.Reader reader, @NotNull SubTemplateProvider subTemplateProvider) throws java.io.IOException
java.io.IOException@NotNull public static Template parse(@NotNull java.lang.String text, @NotNull SubTemplateProvider subTemplateProvider) throws java.io.IOException
java.io.IOException@NotNull public static Template parse(@NotNull java.io.File file, @NotNull SubTemplateProvider subTemplateProvider) throws java.io.IOException
java.io.IOExceptionpublic static void main(java.lang.String[] args)
throws java.io.IOException
java.io.IOException