org.zodiac.template.freemarker.directive.SystemPropertiesDirective Maven / Gradle / Ivy
The newest version!
package org.zodiac.template.freemarker.directive;
import java.io.IOException;
import java.util.Map;
import org.zodiac.sdk.toolkit.util.lang.StrUtil;
import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
public class SystemPropertiesDirective extends AbstractSystemPropertiesDirective {
public static final String DIRECTIVE_NAME = "sysProp";
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
CheckResult result = check(params, env);
String value = (null != result.getDefaultValue() ? System.getProperty(result.getName(), result.getDefaultValue()) :
StrUtil.trimToEmpty(System.getProperty(result.getName())));
env.setVariable(VARIABLE_NAME, wrapTemplateModel(value));
//writeOut(env, value);
if (null != body) body.render(env.getOut());
}
@Override
public String getName() {
return DIRECTIVE_NAME;
}
}