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.TemplateSequenceModel;
|
||||||
import freemarker.template.utility.DeepUnwrap;
|
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 {
|
public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(BaseDumpDirective.class);
|
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 {
|
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<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put(Key.NAME.toString(), varName);
|
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.
|
// Don't return null if model == null. We still want to send the map to the template.
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
// TemplateMethodModel and TemplateDirectiveModel objects can only be
|
// TemplateMethodModel and TemplateDirectiveModel objects can only be
|
||||||
|
@ -132,14 +133,14 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
||||||
map.putAll( getTemplateModelData( ( TemplateDirectiveModel)model, varName ) );
|
map.putAll( getTemplateModelData( ( TemplateDirectiveModel)model, varName ) );
|
||||||
|
|
||||||
} else {
|
} 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>();
|
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.
|
// 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);
|
List<Map<String, Object>> items = new ArrayList<Map<String, Object>>(itemCount);
|
||||||
for ( int i = 0; i < itemCount; i++ ) {
|
for ( int i = 0; i < itemCount; i++ ) {
|
||||||
TemplateModel item = model.get(i);
|
TemplateModel item = model.get(i);
|
||||||
items.add(getDump(item));
|
items.add(getData(item));
|
||||||
}
|
}
|
||||||
map.put(Key.VALUE.toString(), items);
|
map.put(Key.VALUE.toString(), items);
|
||||||
return map;
|
return map;
|
||||||
|
@ -280,7 +281,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
||||||
while (iModel.hasNext()) {
|
while (iModel.hasNext()) {
|
||||||
String key = iModel.next().toString();
|
String key = iModel.next().toString();
|
||||||
TemplateModel value = model.get(key);
|
TemplateModel value = model.get(key);
|
||||||
items.put(key, getDump(value));
|
items.put(key, getData(value));
|
||||||
}
|
}
|
||||||
map.put(Key.VALUE.toString(), items);
|
map.put(Key.VALUE.toString(), items);
|
||||||
return map;
|
return map;
|
||||||
|
@ -343,7 +344,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
||||||
// The method is available as a property
|
// The method is available as a property
|
||||||
if (keySet.contains(propertyName)) {
|
if (keySet.contains(propertyName)) {
|
||||||
TemplateModel value = model.get(propertyName);
|
TemplateModel value = model.get(propertyName);
|
||||||
properties.put(propertyName, getDump(value));
|
properties.put(propertyName, getData(value));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,7 +398,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
||||||
TemplateModelIterator iModel = model.iterator();
|
TemplateModelIterator iModel = model.iterator();
|
||||||
while (iModel.hasNext()) {
|
while (iModel.hasNext()) {
|
||||||
TemplateModel m = iModel.next();
|
TemplateModel m = iModel.next();
|
||||||
items.add(getDump(m));
|
items.add(getData(m));
|
||||||
}
|
}
|
||||||
map.put(Key.VALUE.toString(), items);
|
map.put(Key.VALUE.toString(), items);
|
||||||
return map;
|
return map;
|
||||||
|
@ -448,7 +449,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
||||||
return map;
|
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 {
|
throws TemplateException, IOException {
|
||||||
|
|
||||||
Template template = env.getConfiguration().getTemplate(templateName);
|
Template template = env.getConfiguration().getTemplate(templateName);
|
||||||
|
|
|
@ -30,7 +30,6 @@ public class DumpDirective extends BaseDumpDirective {
|
||||||
throw new TemplateModelException(
|
throw new TemplateModelException(
|
||||||
"The dump directive doesn't allow loop variables.");
|
"The dump directive doesn't allow loop variables.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
throw new TemplateModelException(
|
throw new TemplateModelException(
|
||||||
"The dump directive doesn't allow nested content.");
|
"The dump directive doesn't allow nested content.");
|
||||||
|
@ -44,8 +43,8 @@ public class DumpDirective extends BaseDumpDirective {
|
||||||
|
|
||||||
String varName = ((SimpleScalar)o).getAsString();
|
String varName = ((SimpleScalar)o).getAsString();
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
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