vitro/webapp/src/freemarker/ext/dump/DumpDirective.java

51 lines
1.7 KiB
Java
Raw Normal View History

/* $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<String, Object> map = new HashMap<String, Object>();
map.put("var", getTemplateVariableData(varName, env));
dump("dumpvar.ftl", map, varName, env);
}
}