* Remove processed parameter feature ($(...), $[...]), as it is largely redundant.
* Fix bug reported by Tobi on helma-user where nested macros in default, prefix or suffix returned something else than a string.
This commit is contained in:
parent
20ff053619
commit
1dcdb8e452
1 changed files with 16 additions and 44 deletions
|
@ -323,8 +323,6 @@ public final class Skin {
|
||||||
throws Exception {
|
throws Exception {
|
||||||
if (value instanceof Macro) {
|
if (value instanceof Macro) {
|
||||||
return ((Macro) value).invokeAsParameter(cx);
|
return ((Macro) value).invokeAsParameter(cx);
|
||||||
} else if (value instanceof ProcessedParameter) {
|
|
||||||
return ((ProcessedParameter) value).process(cx.reval);
|
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -496,7 +494,7 @@ public final class Skin {
|
||||||
return parse(macroOffset, true);
|
return parse(macroOffset, true);
|
||||||
}
|
}
|
||||||
// add parameter
|
// add parameter
|
||||||
addParameter(lastParamName, parseParameter(b.toString()));
|
addParameter(lastParamName, b.toString());
|
||||||
lastParamName = null;
|
lastParamName = null;
|
||||||
b.setLength(0);
|
b.setLength(0);
|
||||||
quotechar = '\u0000';
|
quotechar = '\u0000';
|
||||||
|
@ -528,7 +526,7 @@ public final class Skin {
|
||||||
if (quotechar == '\u0000') {
|
if (quotechar == '\u0000') {
|
||||||
if (b.length() > 0) {
|
if (b.length() > 0) {
|
||||||
// add parameter
|
// add parameter
|
||||||
addParameter(lastParamName, parseParameter(b.toString()));
|
addParameter(lastParamName, b.toString());
|
||||||
lastParamName = null;
|
lastParamName = null;
|
||||||
b.setLength(0);
|
b.setLength(0);
|
||||||
}
|
}
|
||||||
|
@ -569,7 +567,7 @@ public final class Skin {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
name = b.toString().trim();
|
name = b.toString().trim();
|
||||||
} else {
|
} else {
|
||||||
addParameter(lastParamName, parseParameter(b.toString()));
|
addParameter(lastParamName, b.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,17 +586,6 @@ public final class Skin {
|
||||||
positionalParams = null;
|
positionalParams = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object parseParameter(String str) {
|
|
||||||
int length = str.length();
|
|
||||||
if (length > 3 && str.charAt(0) == '$') {
|
|
||||||
if (str.charAt(1) == '[' && str.charAt(length - 1) == ']')
|
|
||||||
return new ProcessedParameter(str.substring(2, str.length()-1), 0);
|
|
||||||
else if (str.charAt(1) == '(' && str.charAt(length - 1) == ')')
|
|
||||||
return new ProcessedParameter(str.substring(2, str.length()-1), 1);
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addParameter(String name, Object value) {
|
private void addParameter(String name, Object value) {
|
||||||
if (!(value instanceof String)) {
|
if (!(value instanceof String)) {
|
||||||
hasNestedMacros = true;
|
hasNestedMacros = true;
|
||||||
|
@ -1052,12 +1039,22 @@ public final class Skin {
|
||||||
if (!containsMacros())
|
if (!containsMacros())
|
||||||
return this;
|
return this;
|
||||||
StandardParams stdParams = new StandardParams();
|
StandardParams stdParams = new StandardParams();
|
||||||
stdParams.prefix = processParameter(prefix, cx);
|
stdParams.prefix = renderToString(prefix, cx);
|
||||||
stdParams.suffix = processParameter(suffix, cx);
|
stdParams.suffix = renderToString(suffix, cx);
|
||||||
stdParams.defaultValue = processParameter(defaultValue, cx);
|
stdParams.defaultValue = renderToString(defaultValue, cx);
|
||||||
return stdParams;
|
return stdParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String renderToString(Object obj, RenderContext cx) throws Exception {
|
||||||
|
Object value = processParameter(obj, cx);
|
||||||
|
if (value == null)
|
||||||
|
return null;
|
||||||
|
else if (value instanceof String)
|
||||||
|
return (String) value;
|
||||||
|
else
|
||||||
|
return cx.reval.scriptingEngine.toString(value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class RenderContext {
|
class RenderContext {
|
||||||
|
@ -1126,31 +1123,6 @@ public final class Skin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Processed macro parameter
|
|
||||||
*/
|
|
||||||
class ProcessedParameter {
|
|
||||||
String value;
|
|
||||||
int type;
|
|
||||||
|
|
||||||
ProcessedParameter(String value, int type) {
|
|
||||||
this.value = value;
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object process(RequestEvaluator reval) throws Exception {
|
|
||||||
switch (type) {
|
|
||||||
case 1:
|
|
||||||
Object function = app.processMacroParameter;
|
|
||||||
Object[] args = {value};
|
|
||||||
return reval.invokeDirectFunction(null, function, args);
|
|
||||||
case 0:
|
|
||||||
default:
|
|
||||||
return reval.getResponse().getMacroHandlers().get(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception type for unhandled macros
|
* Exception type for unhandled macros
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue