use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class ArrayUtil method toComparator.
public static Comparator toComparator(PageContext pc, String strSortType, String sortOrder, boolean localeSensitive) throws PageException {
// check order
boolean isAsc = true;
if (sortOrder.equalsIgnoreCase("asc"))
isAsc = true;
else if (sortOrder.equalsIgnoreCase("desc"))
isAsc = false;
else
throw new ExpressionException("invalid sort order type [" + sortOrder + "], sort order types are [asc and desc]");
// check type
int sortType;
if (strSortType.equalsIgnoreCase("text"))
sortType = ComparatorUtil.SORT_TYPE_TEXT;
else if (strSortType.equalsIgnoreCase("textnocase"))
sortType = ComparatorUtil.SORT_TYPE_TEXT_NO_CASE;
else if (strSortType.equalsIgnoreCase("numeric"))
sortType = ComparatorUtil.SORT_TYPE_NUMBER;
else
throw new ExpressionException("invalid sort type [" + strSortType + "], sort types are [text, textNoCase, numeric]");
return ComparatorUtil.toComparator(sortType, isAsc, localeSensitive ? ThreadLocalPageContext.getLocale(pc) : null, null);
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class ComponentUtil method notFunction.
public static ExpressionException notFunction(Component c, Collection.Key key, Object member, int access) {
if (member == null) {
String strAccess = toStringAccess(access, "");
Collection.Key[] other = c.keys(access);
if (other.length == 0)
return new ExpressionException("component [" + c.getCallName() + "] has no " + strAccess + " function with name [" + key + "]");
return new ExpressionException("component [" + c.getCallName() + "] has no " + strAccess + " function with name [" + key + "]", "accessible functions are [" + ListUtil.arrayToList(other, ",") + "]");
}
return new ExpressionException("member [" + key + "] of component [" + c.getCallName() + "] is not a function", "Member is of type [" + Caster.toTypeName(member) + "]");
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class MemberUtil method call.
public static Object call(PageContext pc, Object coll, Collection.Key methodName, Object[] args, short[] types, String[] strTypes) throws PageException {
// look for members
short type;
String strType;
Map<Key, FunctionLibFunction> members = null;
for (int i = 0; i < types.length; i++) {
type = types[i];
strType = strTypes[i];
members = getMembers(pc, type);
FunctionLibFunction member = members.get(methodName);
if (member != null) {
List<FunctionLibFunctionArg> _args = member.getArg();
if (args.length < _args.size()) {
ArrayList<Ref> refs = new ArrayList<Ref>();
int pos = member.getMemberPosition();
FunctionLibFunctionArg flfa;
Iterator<FunctionLibFunctionArg> it = _args.iterator();
int glbIndex = 0, argIndex = -1;
while (it.hasNext()) {
glbIndex++;
flfa = it.next();
if (glbIndex == pos) {
refs.add(new Casting(strType, type, coll));
} else if (args.length > ++argIndex) {
// careful, argIndex is only incremented when condition above is false
refs.add(new Casting(flfa.getTypeAsString(), flfa.getType(), args[argIndex]));
}
}
return new BIFCall(coll, member, refs.toArray(new Ref[refs.size()])).getValue(pc);
}
}
}
// do reflection
if (pc.getConfig().getSecurityManager().getAccess(lucee.runtime.security.SecurityManager.TYPE_DIRECT_JAVA_ACCESS) == lucee.runtime.security.SecurityManager.VALUE_YES) {
if (!(coll instanceof Undefined)) {
Object res = callMethod(coll, methodName, args);
if (res != DEFAULT)
return res;
}
}
// merge
if (types.length > 1) {
Map<Key, FunctionLibFunction> tmp;
members = null;
for (int i = 0; i < types.length; i++) {
tmp = getMembers(pc, types[i]);
if (members == null)
members = tmp;
else {
Iterator<Entry<Key, FunctionLibFunction>> it = tmp.entrySet().iterator();
Entry<Key, FunctionLibFunction> e;
while (it.hasNext()) {
e = it.next();
members.put(e.getKey(), e.getValue());
}
}
}
}
Set<Key> set = members.keySet();
String msg = ExceptionUtil.similarKeyMessage(set.toArray(new Key[set.size()]), methodName.getString(), "function", "functions", "Object", true);
throw new ExpressionException(msg);
// throw new ExpressionException("No matching function member ["+methodName+"] found, available function members are ["+
// lucee.runtime.type.util.ListUtil.sort(CollectionUtil.getKeyList(members.keySet().iterator(), ","),"textnocase","asc",",")+"]");
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class VariableUtilImpl method get.
public Object get(PageContext pc, Object coll, Collection.Key key) throws PageException {
// Objects
if (coll instanceof Objects) {
return ((Objects) coll).get(pc, key);
} else // Collection
if (coll instanceof Collection) {
return ((Collection) coll).get(key);
} else // Map
if (coll instanceof Map) {
Object rtn = null;
try {
rtn = ((Map) coll).get(key.getString());
if (rtn == null && coll.getClass().getName().startsWith("org.hibernate."))
rtn = ((Map) coll).get(MapAsStruct.getCaseSensitiveKey((Map) coll, key.getString()));
if (rtn != null)
return rtn;
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
rtn = Reflector.getProperty(coll, key.getString(), null);
if (rtn != null)
return rtn;
String realKey = MapAsStruct.getCaseSensitiveKey((Map) coll, key.getString());
String detail = null;
if (realKey != null) {
detail = "The keys for this Map are case-sensitive, use bracked notation like this \"map['" + realKey + "']\" instead of dot notation like this \"map." + realKey + "\" to address the Map";
}
throw new ExpressionException("Key [" + key.getString() + "] doesn't exist in Map (" + ((Map) coll).getClass().getName() + ")", detail);
} else // List
if (coll instanceof List) {
try {
Object rtn = ((List) coll).get(Caster.toIntValue(key.getString()) - 1);
if (rtn == null)
throw new ExpressionException("Key [" + key.getString() + "] doesn't exist in List");
return rtn;
} catch (IndexOutOfBoundsException e) {
throw new ExpressionException("Key [" + key.getString() + "] doesn't exist in List");
}
} else // Native Array
if (Decision.isNativeArray(coll)) {
Object rtn = ArrayUtil.get(coll, Caster.toIntValue(key.getString()) - 1, null);
if (rtn == null)
throw new ExpressionException("Key [" + key.getString() + "] doesn't exist in Native Array");
return rtn;
} else // Node
if (coll instanceof Node) {
// print.out("get:"+key);
return XMLStructFactory.newInstance((Node) coll, false).get(key);
} else if (coll instanceof String) {
if (Decision.isInteger(key.getString())) {
// i do the decision call and the caster call, because in most cases the if will be false
String str = (String) coll;
int index = Caster.toIntValue(key.getString(), -1);
if (index > 0 && index <= str.length()) {
return str.substring(index - 1, index);
}
}
}
// Direct Object Access
if (coll != null && pc.getConfig().getSecurityManager().getAccess(SecurityManager.TYPE_DIRECT_JAVA_ACCESS) == SecurityManager.VALUE_YES) {
return Reflector.getProperty(coll, key.getString());
}
throw new ExpressionException("No matching property [" + key.getString() + "] found");
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class VariableUtilImpl method remove.
public Object remove(Object coll, Collection.Key key) throws PageException {
// Collection
if (coll instanceof Collection) {
return ((Collection) coll).remove(key);
} else // Map
if (coll instanceof Map) {
Object obj = ((Map) coll).remove(key.getString());
// if(obj==null)obj=((Map)coll).remove(MapAsStruct.getCaseSensitiveKey((Map)coll, key));
if (obj == null)
throw new ExpressionException("can't remove key [" + key + "] from map");
return obj;
} else // List
if (coll instanceof List) {
int i = Caster.toIntValue(key);
Object obj = ((List) coll).remove(i);
if (obj == null)
throw new ExpressionException("can't remove index [" + key + "] from list");
return obj;
}
// TODO Support for Node
throw new ExpressionException("can't remove key [" + key + "] from Object of type [" + Caster.toTypeName(coll) + "]");
}
Aggregations