Revert changes from r7821 - incomplete refactoring
This commit is contained in:
parent
4227bfb2ad
commit
15ed59d494
2 changed files with 22 additions and 22 deletions
|
@ -41,6 +41,11 @@ import freemarker.template.TemplateScalarModel;
|
|||
import freemarker.template.TemplateSequenceModel;
|
||||
import freemarker.template.utility.DeepUnwrap;
|
||||
|
||||
/* TODO
|
||||
* - Check error messages generated for TemplateModelException-s. If too generic, need to catch, create specific
|
||||
* error message, and rethrow.
|
||||
*/
|
||||
|
||||
public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
||||
|
||||
private static final Log log = LogFactory.getLog(BaseDumpDirective.class);
|
||||
|
@ -107,20 +112,16 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
|||
}
|
||||
}
|
||||
|
||||
protected Map<String, Object> getTemplateVariableDump(String varName, Environment env)
|
||||
|
||||
protected Map<String, Object> getTemplateVariableData(String varName, Environment env)
|
||||
throws TemplateModelException {
|
||||
|
||||
TemplateHashModel dataModel = env.getDataModel();
|
||||
TemplateModel model = dataModel.get(varName);
|
||||
return getTemplateVariableDump(varName, model);
|
||||
}
|
||||
|
||||
protected Map<String, Object> getTemplateVariableDump(String varName, TemplateModel model)
|
||||
throws TemplateModelException {
|
||||
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(Key.NAME.toString(), varName);
|
||||
|
||||
TemplateHashModel dataModel = env.getDataModel();
|
||||
TemplateModel model = dataModel.get(varName);
|
||||
|
||||
// Don't return null if model == null. We still want to send the map to the template.
|
||||
if (model != null) {
|
||||
// TemplateMethodModel and TemplateDirectiveModel objects can only be
|
||||
|
@ -132,14 +133,14 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
|||
map.putAll( getTemplateModelData( ( TemplateDirectiveModel)model, varName ) );
|
||||
|
||||
} else {
|
||||
map.putAll(getDump(model));
|
||||
map.putAll(getData(model));
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map<String, Object> getDump(TemplateModel model) throws TemplateModelException {
|
||||
|
||||
private Map<String, Object> getData(TemplateModel model) throws TemplateModelException {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
// Don't return null if model == null. We still want to send the map to the template.
|
||||
|
@ -253,7 +254,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
|||
List<Map<String, Object>> items = new ArrayList<Map<String, Object>>(itemCount);
|
||||
for ( int i = 0; i < itemCount; i++ ) {
|
||||
TemplateModel item = model.get(i);
|
||||
items.add(getDump(item));
|
||||
items.add(getData(item));
|
||||
}
|
||||
map.put(Key.VALUE.toString(), items);
|
||||
return map;
|
||||
|
@ -280,7 +281,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
|||
while (iModel.hasNext()) {
|
||||
String key = iModel.next().toString();
|
||||
TemplateModel value = model.get(key);
|
||||
items.put(key, getDump(value));
|
||||
items.put(key, getData(value));
|
||||
}
|
||||
map.put(Key.VALUE.toString(), items);
|
||||
return map;
|
||||
|
@ -343,7 +344,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
|||
// The method is available as a property
|
||||
if (keySet.contains(propertyName)) {
|
||||
TemplateModel value = model.get(propertyName);
|
||||
properties.put(propertyName, getDump(value));
|
||||
properties.put(propertyName, getData(value));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -397,7 +398,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
|||
TemplateModelIterator iModel = model.iterator();
|
||||
while (iModel.hasNext()) {
|
||||
TemplateModel m = iModel.next();
|
||||
items.add(getDump(m));
|
||||
items.add(getData(m));
|
||||
}
|
||||
map.put(Key.VALUE.toString(), items);
|
||||
return map;
|
||||
|
@ -448,7 +449,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
|||
return map;
|
||||
}
|
||||
|
||||
protected void dump(String templateName, Map<String, Object> map, Environment env)
|
||||
protected void dump(String templateName, Map<String, Object> map, String modelName, Environment env)
|
||||
throws TemplateException, IOException {
|
||||
|
||||
Template template = env.getConfiguration().getTemplate(templateName);
|
||||
|
|
|
@ -30,7 +30,6 @@ public class DumpDirective extends BaseDumpDirective {
|
|||
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.");
|
||||
|
@ -44,8 +43,8 @@ public class DumpDirective extends BaseDumpDirective {
|
|||
|
||||
String varName = ((SimpleScalar)o).getAsString();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("var", getTemplateVariableDump(varName, env));
|
||||
map.put("var", getTemplateVariableData(varName, env));
|
||||
|
||||
dump("dumpvar.ftl", map, env);
|
||||
dump("dumpvar.ftl", map, varName, env);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue