use of lucee.commons.lang.ParserString 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.ParserString 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.ParserString in project Lucee by lucee.
the class SelectParser method identifier.
private String identifier(ParserString raw, RefBoolean hasBracked) throws SQLParserException {
if (hasBracked != null && raw.forwardIfCurrent('[')) {
hasBracked.setValue(true);
return identifierBracked(raw);
} else if (!(raw.isCurrentLetter() || raw.isCurrent('*') || raw.isCurrent('?') || raw.isCurrent('_')))
return null;
int start = raw.getPos();
do {
raw.next();
if (!(raw.isCurrentLetter() || raw.isCurrentBetween('0', '9') || raw.isCurrent('*') || raw.isCurrent('?') || raw.isCurrent('_'))) {
break;
}
} while (raw.isValidIndex());
String str = raw.substring(start, raw.getPos() - start);
raw.removeSpace();
return str;
}
use of lucee.commons.lang.ParserString in project Lucee by lucee.
the class SelectParser method column.
private Expression column(ParserString raw) throws SQLParserException {
RefBoolean hb = new RefBooleanImpl(false);
String name = identifier(raw, hb);
if (name == null)
return null;
if (!hb.toBooleanValue()) {
if ("true".equalsIgnoreCase(name))
return ValueBoolean.TRUE;
if ("false".equalsIgnoreCase(name))
return ValueBoolean.FALSE;
if ("null".equalsIgnoreCase(name))
return ValueNull.NULL;
}
ColumnExpression column = new ColumnExpression(name, name.equals("?") ? columnIndex++ : 0);
raw.removeSpace();
while (raw.forwardIfCurrent(".")) {
raw.removeSpace();
String sub = identifier(raw, hb);
if (sub == null)
throw new SQLParserException("invalid column definition");
column.setSub(sub);
}
raw.removeSpace();
if (raw.forwardIfCurrent('(')) {
return new OperationN(column.getFullName(), readArguments(raw));
}
return column;
}
use of lucee.commons.lang.ParserString in project Lucee by lucee.
the class ClientScopeConverter method unserialize.
public static Struct unserialize(String str) {
Struct sct = new StructImpl();
ParserString ps = new ParserString(str);
StringBuilder sb = new StringBuilder();
String key = null;
while (!ps.isAfterLast()) {
if (ps.isCurrent('#')) {
if (ps.isNext('=')) {
ps.next();
sb.append('=');
} else if (ps.isNext('#')) {
ps.next();
sb.append('#');
} else {
sct.setEL(key, sb.toString());
sb = new StringBuilder();
}
} else if (ps.isCurrent('=')) {
key = sb.toString();
sb = new StringBuilder();
} else
sb.append(ps.getCurrent());
ps.next();
}
if (!StringUtil.isEmpty(key) && !StringUtil.isEmpty(sb)) {
sct.setEL(key, sb.toString());
}
return sct;
/*
int index=0,last=0;
while((index=str.indexOf('#',last))!=-1) {
outer:while(str.length()+1>index) {
c=str.charAt(index+1);
if(c=='#' || c=='=') {
last=index+1;
continue;
}
}
_unserialize(str.substring(last,index));
last=index+1;
}
_unserialize(str.substring(last));
*/
}
Aggregations