Class Template
- java.lang.Object
-
- org.forgerock.config.resolvers.template.Template
-
public final class Template extends Object
Represents a templated string.It may contain resolvable properties.
A
Template
is obtained either programmatically using the static factory methods defined in this class (empty()
,textual(String)
,property(Template, Template)
andsequence(Template...)
) or through the parsing of a templated string (seecompile(String)
orTemplateParser.parse(String, boolean)
).- See Also:
TemplateVisitor
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T,C>
Taccept(TemplateVisitor<T,C> visitor, C context)
Apply an operation (the visitor) to this template.static Template
compile(String source)
Build a newTemplate
from the givensource
value.static Template
compile(String source, boolean escaping)
Build a newTemplate
from the givensource
value, instructing the parser to either escape or not special characters with the help of theescaping
parameter.static Template
empty()
Constructs a new empty template.static Template
property(Template name)
Constructs a new property template with the givenname
Template.static Template
property(Template name, Template defaultValue)
Constructs a new property template with the givenname
anddefaultValue
templates.static Template
sequence(List<Template> templates)
Constructs a new sequence template from the giventemplates
list.static Template
sequence(Template... templates)
Constructs a new sequence template from the giventemplates
list.static Template
textual(String text)
Constructs a new textual template with the giventext
.String
toString()
-
-
-
Method Detail
-
compile
public static Template compile(String source)
Build a newTemplate
from the givensource
value.It enables escaping (protection with '\' of special characters as described in
TemplateTokenizer
).- Parameters:
source
- templated string- Returns:
- a new
Template
instance
-
compile
public static Template compile(String source, boolean escaping)
Build a newTemplate
from the givensource
value, instructing the parser to either escape or not special characters with the help of theescaping
parameter.It supports escaping (protection with '\' of special characters as described in
TemplateTokenizer
).- Parameters:
source
- templated stringescaping
- control escaping mode- Returns:
- a new
Template
instance
-
accept
public <T,C> T accept(TemplateVisitor<T,C> visitor, C context)
Apply an operation (the visitor) to this template.- Type Parameters:
T
- the result typeC
- the context type- Parameters:
visitor
- the operation to apply (nevernull
)context
- operation's context (may benull
)- Returns:
- the result of the visitor applied to this template (can be
null
)
-
empty
public static Template empty()
Constructs a new empty template. Can be used for property's default value when not set.- Returns:
- a new empty template
-
textual
public static Template textual(String text)
Constructs a new textual template with the giventext
.- Parameters:
text
- textual value (nevernull
, but can be empty)- Returns:
- a new textual template
-
property
public static Template property(Template name)
Constructs a new property template with the givenname
Template.It's equivalent to use property(Template, Template) with an
empty()
template for the default value.- Parameters:
name
- template for property name (nevernull
)- Returns:
- a new property template with no default value
-
property
public static Template property(Template name, Template defaultValue)
Constructs a new property template with the givenname
anddefaultValue
templates.- Parameters:
name
- template for property name (nevernull
)defaultValue
- template for property default value (nevernull
)- Returns:
- a new property template
-
sequence
public static Template sequence(Template... templates)
Constructs a new sequence template from the giventemplates
list.- Parameters:
templates
- list of templates- Returns:
- a new sequence template
-
-