/* $This file is distributed under the terms of the license in /doc/license.txt$ */ package freemarker.ext.dump; import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import freemarker.core.Environment; import freemarker.template.SimpleScalar; import freemarker.template.TemplateDirectiveBody; import freemarker.template.TemplateException; import freemarker.template.TemplateModel; import freemarker.template.TemplateModelException; public class DumpDirective extends BaseDumpDirective { @SuppressWarnings("unused") private static final Log log = LogFactory.getLog(DumpDirective.class); @SuppressWarnings("rawtypes") @Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { if (loopVars.length != 0) { throw new TemplateModelException( "The dump directive doesn't allow loop variables."); } if (body != null) { throw new TemplateModelException( "The dump directive doesn't allow nested content."); } Object o = params.get("var"); if ( !(o instanceof SimpleScalar)) { throw new TemplateModelException( "Value of parameter 'var' must be a string."); } String varName = ((SimpleScalar)o).getAsString(); Map map = new HashMap(); map.put("var", getTemplateVariableData(varName, env)); dump("dumpvar.ftl", map, varName, env); } }