stringtemplate-4

What is the best way to ensure HTML entities are escaped in StringTemplate

不羁岁月 提交于 2019-12-01 01:29:31
Assuming the following string template, is being given a list of Java Bean objects: <ul>$people:{p|<li>$p.name$ $p.email</li>}$</ul> ie the list of people might contain Person objects which you may or may not have the ability to enhance/extend: class Person { .... public getName() { ... } public getEmail() { ... } } The getName() and getEmail() methods don't return sanitised (escaped html entities). How do you get around this? You may use a custom renderer, for example: public static class HtmlEscapeStringRenderer implements AttributeRenderer { public String toString(Object o, String s, Locale

StringTemplate list of attributes defined for a given template

你。 提交于 2019-11-29 07:54:31
I am getting started with StringTemplate 4 and I am trying to create a template from a simple string stored in a database. I use something like this: STGroup group = new STGroupString(null, someTemplateString, '$', '$'); ST st = group.getInstanceOf(someTemplateName); st.add(someAttribute, someValue); Now everything works fine if I define all or less than the attribute defined for the template someTemplateName . Now if I try to add an attribute that doesn't exist, I get the following exception: no such attribute: fake java.lang.IllegalArgumentException: no such attribute: fake ... which makes

StringTemplate list of attributes defined for a given template

若如初见. 提交于 2019-11-28 01:26:42
问题 I am getting started with StringTemplate 4 and I am trying to create a template from a simple string stored in a database. I use something like this: STGroup group = new STGroupString(null, someTemplateString, '$', '$'); ST st = group.getInstanceOf(someTemplateName); st.add(someAttribute, someValue); Now everything works fine if I define all or less than the attribute defined for the template someTemplateName . Now if I try to add an attribute that doesn't exist, I get the following exception