Fixed problem with OFBiz script syntax versus UEL syntax. UEL identifiers cannot start with a digit, so identifiers created from IDs would generate syntax errors. This commit fixes that by converting ID identifiers internally by prefixing them with an underscore.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@729819 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrian Crum
2008-12-29 00:43:05 +00:00
parent 9c5286fc42
commit 01fdf5c723
2 changed files with 14 additions and 5 deletions
@@ -59,7 +59,7 @@ public class FlexibleMapAccessor<T> implements Serializable {
name = name.substring(1);
}
if (name.contains(FlexibleStringExpander.openBracket)) {
fse = FlexibleStringExpander.getInstance(UelUtil.prepareExpression(name));
fse = FlexibleStringExpander.getInstance(name);
} else {
bracketedOriginal = FlexibleStringExpander.openBracket.concat(UelUtil.prepareExpression(name).concat(FlexibleStringExpander.closeBracket));
}
@@ -189,7 +189,7 @@ public class FlexibleMapAccessor<T> implements Serializable {
protected String getExpression(Map<String, ? extends Object> base) {
String expression = null;
if (this.fse != null) {
expression = FlexibleStringExpander.openBracket.concat(this.fse.expandString(base).concat(FlexibleStringExpander.closeBracket));
expression = FlexibleStringExpander.openBracket.concat(UelUtil.prepareExpression(this.fse.expandString(base)).concat(FlexibleStringExpander.closeBracket));
} else {
expression = this.bracketedOriginal;
}
@@ -322,15 +322,24 @@ public class UelUtil {
* @return Converted expression
*/
public static String prepareExpression(String expression) {
String result = expression;
int openBrace = expression.indexOf("[+");
int closeBrace = (openBrace == -1 ? -1 : expression.indexOf(']', openBrace));
if (closeBrace != -1) {
String base = expression.substring(0, openBrace);
String property = expression.substring(openBrace+2, closeBrace).trim();
String end = expression.substring(closeBrace + 1);
expression = base + "['insert@" + property + "']" + end;
result = base + "['insert@" + property + "']" + end;
}
expression = expression.replace("[]", "['add']");
return expression;
result = result.replace("[]", "['add']");
int pos = result.indexOf(".");
while (pos != -1) {
char c = result.charAt(pos + 1);
if (c >= '0' && c <= '9') {
result = result.substring(0, pos) + "._" + result.substring(pos + 1);
}
pos = result.indexOf(".", pos + 1);
}
return result;
}
}