NIHVIVO-2470 Restore parameter type checking on DumpDirective and HelpDirective. Handle undefined variables by assigning value = "Undefined."

This commit is contained in:
ryounes 2011-04-20 21:37:12 +00:00
parent 84f779238c
commit d64d45d8e6
4 changed files with 21 additions and 7 deletions

View file

@ -83,8 +83,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
METHOD("Method"),
NUMBER("Number"),
SEQUENCE("Sequence"),
STRING("String"),
UNDEFINED("Undefined");
STRING("String");
private final String type;
@ -128,7 +127,6 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
Map<String, Object> value = new HashMap<String, Object>();
if (model == null) {
value.put(Key.TYPE.toString(), Type.UNDEFINED);
value.put(Key.VALUE.toString(), VALUE_UNDEFINED);
// TemplateMethodModel and TemplateDirectiveModel objects can only be

View file

@ -37,7 +37,19 @@ public class DumpDirective extends BaseDumpDirective {
"The dump directive doesn't allow nested content.");
}
String varName = params.get("var").toString();
Object o = params.get("var");
if ( o == null) {
throw new TemplateModelException(
"Must specify 'var' argument.");
}
if ( !(o instanceof SimpleScalar)) {
throw new TemplateModelException(
"Value of parameter 'var' must be a string.");
}
String varName = o.toString(); //((SimpleScalar)o).getAsString();
Map<String, Object> map = getTemplateVariableDump(varName, env);
dump(TEMPLATE_DEFAULT, map, env);

View file

@ -40,8 +40,13 @@ public class HelpDirective extends BaseDumpDirective {
throw new TemplateModelException(
"Must specify 'for' argument.");
}
String varName = params.get("var").toString();
if ( !(o instanceof SimpleScalar)) {
throw new TemplateModelException(
"Value of parameter 'for' must be a string.");
}
String varName = o.toString(); //((SimpleScalar)o).getAsString();
TemplateHashModel dataModel = env.getDataModel();
Object templateModel = dataModel.get(varName);

View file

@ -78,7 +78,6 @@ public class DumpDirectiveTest {
Map<String, Object> dataModel = new HashMap<String, Object>();
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.UNDEFINED);
expectedDumpValue.put(Key.VALUE.toString(), BaseDumpDirective.VALUE_UNDEFINED);
Map<String, Object> expectedDump = new HashMap<String, Object>();