Class StringTemplate
- java.lang.Object
-
- us.abstracta.jmeter.javadsl.core.util.StringTemplate
-
public class StringTemplate extends Object
String template engine allowing easy string regex matching and usual template engine resolution.This engine uses a syntax inspired in mustache using
{{}}as basic indicator of special treatment/replacement.To check fo string regex matching you can have a template like
<root version="1.2">{{\d+}}</root>and usematches(String). No need to escape regex special characters outside of{{}}.To use regular string template resolution you can use templates like
<root version="1.2">{{value}}</root>and usebind(String, Object)andsolve()to get the resulting string of replacing each occurrence of{{}}with the bound value. Additionally, you can define default values for each replacement expression. In this example<root version="1.2">{{value:3}}</root>it will solve "value" to string "3" if no value is bound to "value" or if bound value is null. If a replacement has no binding value different from null and no default value is specified, then an exception will be generated. You can always specify an empty default value (like{{value:}}) which avoids the exception and generates an empty string instead.You can even use one template for both regex matching or string template solving. Eg:
<root version="1.2">{{value:3~\d+}}</root>can be used withmatches(String)or withbind(String, Object)andsolve().
-
-
Field Summary
Fields Modifier and Type Field Description static StringEXPRESSION_END_MARKERstatic StringEXPRESSION_START_MARKER
-
Constructor Summary
Constructors Constructor Description StringTemplate(String template)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringTemplatebind(String key, Object value)StringTemplateignoreMissingBindings()booleanmatches(String string)Stringsolve()
-
-
-
Field Detail
-
EXPRESSION_START_MARKER
public static final String EXPRESSION_START_MARKER
- See Also:
- Constant Field Values
-
EXPRESSION_END_MARKER
public static final String EXPRESSION_END_MARKER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
StringTemplate
public StringTemplate(String template)
-
-
Method Detail
-
matches
public boolean matches(String string)
-
bind
public StringTemplate bind(String key, Object value)
-
ignoreMissingBindings
public StringTemplate ignoreMissingBindings()
-
solve
public String solve()
-
-