use of lucee.commons.lang.StringList in project Lucee by lucee.
the class VariableInterpreter method parse.
public static StringList parse(String var, boolean doLowerCase) {
ParserString ps = new ParserString(var);
String id = readIdentifier(ps, doLowerCase);
if (id == null)
return null;
StringList list = new StringList(id);
while (true) {
if (ps.forwardIfCurrent('.')) {
id = readIdentifier(ps, doLowerCase);
if (id == null)
return null;
list.add(id);
} else
break;
}
if (ps.isValidIndex())
return null;
list.reset();
return list;
}
use of lucee.commons.lang.StringList in project Lucee by lucee.
the class VariableInterpreter method getVariableELAsCollection.
public static Object getVariableELAsCollection(PageContext pc, String var, Object defaultValue) {
StringList list = parse(pc, new ParserString(var), false);
if (list == null)
return defaultValue;
int scope = scopeString2Int(pc.ignoreScopes(), list.next());
Object coll = null;
if (scope == Scope.SCOPE_UNDEFINED) {
try {
coll = pc.undefinedScope().getCollection(list.current());
} catch (PageException e) {
coll = null;
}
if (coll == null)
return defaultValue;
} else {
try {
coll = VariableInterpreter.scope(pc, scope, list.hasNext());
// coll=pc.scope(scope);
} catch (PageException e) {
return defaultValue;
}
}
while (list.hasNext()) {
coll = pc.getVariableUtil().getCollection(pc, coll, list.next(), null);
if (coll == null)
return defaultValue;
}
return coll;
}
use of lucee.commons.lang.StringList in project Lucee by lucee.
the class VariableInterpreter method getVariableEL.
/**
* get a variable from page context
* @param pc Page Context
* @param var variable string to get value to
* @param defaultValue value returnded if variable was not found
* @return the value or default value if not found
*/
public static Object getVariableEL(PageContext pc, String var, Object defaultValue) {
StringList list = parse(pc, new ParserString(var), false);
if (list == null)
return defaultValue;
int scope = scopeString2Int(pc.ignoreScopes(), list.next());
Object coll = null;
if (scope == Scope.SCOPE_UNDEFINED) {
coll = pc.undefinedScope().get(KeyImpl.init(list.current()), NullSupportHelper.NULL());
if (coll == NullSupportHelper.NULL())
return defaultValue;
} else {
try {
coll = VariableInterpreter.scope(pc, scope, list.hasNext());
// coll=pc.scope(scope);
} catch (PageException e) {
return defaultValue;
}
}
while (list.hasNext()) {
coll = pc.getVariableUtil().get(pc, coll, KeyImpl.init(list.next()), NullSupportHelper.NULL());
if (coll == NullSupportHelper.NULL())
return defaultValue;
}
return coll;
}
use of lucee.commons.lang.StringList in project Lucee by lucee.
the class IsDefined method execute.
@Override
public void execute(BIF bif, FunctionLibFunction flf) throws TemplateException {
Argument arg = bif.getArguments()[0];
Expression value = arg.getValue();
if (value instanceof LitString) {
String str = ((LitString) value).getString();
StringList sl = VariableInterpreter.parse(str, false);
if (sl != null) {
// scope
str = sl.next();
int scope = VariableInterpreter.scopeString2Int(bif.ts.ignoreScopes, str);
if (scope == Scope.SCOPE_UNDEFINED)
sl.reset();
// keys
String[] arr = sl.toArray();
ArrayUtil.trim(arr);
// update first arg
arg.setValue(bif.getFactory().createLitDouble(scope), "number");
if (arr.length == 1) {
// LitString.toExprString(str);
Expression expr = new CollectionKey(bif.getFactory(), arr[0]);
arg = new Argument(expr, Collection.Key.class.getName());
bif.addArgument(arg);
} else {
CollectionKeyArray expr = new CollectionKeyArray(bif.getFactory(), arr);
// LiteralStringArray expr = new LiteralStringArray(arr);
arg = new Argument(expr, Collection.Key[].class.getName());
bif.addArgument(arg);
}
}
}
// print.out("bif:"+arg.getValue().getClass().getName());
}
use of lucee.commons.lang.StringList in project Lucee by lucee.
the class VariableInterpreter method isDefined.
/**
* check if a variable is defined in Page Context
* @param pc PageContext to check
* @param var variable String
* @return exists or not
*/
public static boolean isDefined(PageContext pc, String var) {
StringList list = parse(pc, new ParserString(var), false);
if (list == null)
return false;
try {
int scope = scopeString2Int(pc.ignoreScopes(), list.next());
Object coll = NULL;
if (scope == Scope.SCOPE_UNDEFINED) {
coll = pc.undefinedScope().get(list.current(), null);
if (coll == null)
return false;
} else {
coll = VariableInterpreter.scope(pc, scope, list.hasNext());
// coll=pc.scope(scope);
}
while (list.hasNext()) {
coll = pc.getVariableUtil().getCollection(pc, coll, list.next(), null);
if (coll == null)
return false;
}
} catch (PageException e) {
return false;
}
return true;
}
Aggregations