java - StringTemplate: how to detect, if variable in tempate is not explicitly set? -
i using stringtemplate auto-generate configuration files , it's error, if user haven't defined of variables.
stringtemplate replace undefined variables (i mean $var$) empty string , error remain undetected. e.g.:
some_property=$some_property$
is rendered into:
some_property=
how forcefulness stringtemplate raise exception, if variable in template not explicitly defined using
stringtemplate.setattribute(key, value)
?
with stringtemplate 4 error listener informed undefined attribute. custom error-listener can handle required. example:
st tmp = new st("hello <name>!"); tmp.write(new noindentwriter(new stringwriter()), new sterrorlistener() { @override public void runtimeerror(stmessage msg) { if(msg.error == errortype.no_such_attribute) system.out.println("attribute not defined: "+ msg.arg); } @override public void compiletimeerror(stmessage msg) { } @override public void ioerror(stmessage msg) { } @override public void internalerror(stmessage msg) { } });
java string stringtemplate
No comments:
Post a Comment