use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class VariableUtilImpl method remove.
/**
* @see lucee.runtime.util.VariableUtil#remove(java.lang.Object, java.lang.String)
*/
@Override
public Object remove(Object coll, String key) throws PageException {
// Collection
if (coll instanceof Collection) {
return ((Collection) coll).remove(KeyImpl.init(key));
} else // Map
if (coll instanceof Map) {
Object obj = ((Map) coll).remove(key);
// 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) + "]");
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class ArgumentImpl method getE.
/**
* return a value matching to key
* @param intKey
* @return value matching key
* @throws PageException
*/
@Override
public Object getE(int intKey) throws PageException {
// getMap().keySet().iterator();
Iterator it = valueIterator();
int count = 0;
Object o;
while (it.hasNext()) {
o = it.next();
if ((++count) == intKey) {
// super.get(o.toString());
return o;
}
}
throw new ExpressionException("invalid index [" + intKey + "] for argument scope");
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class ArgumentImpl method insert.
@Override
public boolean insert(int index, String key, Object value) throws ExpressionException {
int len = size();
if (index < 1 || index > len)
throw new ExpressionException("invalid index to insert a value to argument scope", len == 0 ? "can't insert in a empty argument scope" : "valid index goes from 1 to " + (len - 1));
// remove all upper
LinkedHashMap lhm = new LinkedHashMap();
Collection.Key[] keys = keys();
Collection.Key k;
for (int i = 1; i <= keys.length; i++) {
if (i < index)
continue;
k = keys[i - 1];
lhm.put(k.getString(), get(k, null));
removeEL(k);
}
// set new value
setEL(key, value);
// reset upper values
Iterator it = lhm.entrySet().iterator();
Map.Entry entry;
while (it.hasNext()) {
entry = (Entry) it.next();
setEL(KeyImpl.toKey(entry.getKey()), entry.getValue());
}
return true;
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class ArgumentImpl method setArgument.
@Override
public Object setArgument(Object obj) throws PageException {
if (obj == this)
return obj;
if (Decision.isStruct(obj)) {
// TODO bessere impl. anstelle vererbung wrao auf struct
clear();
Struct sct = Caster.toStruct(obj);
Iterator<Key> it = sct.keyIterator();
Key key;
while (it.hasNext()) {
key = it.next();
setEL(key, sct.get(key, null));
}
return obj;
}
throw new ExpressionException("can not overwrite arguments scope");
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class Throw method toPageException.
public static PageException toPageException(Object object, PageException defaultValue) throws PageException {
if ((object instanceof ObjectWrap))
return toPageException(((ObjectWrap) object).getEmbededObject(), defaultValue);
if (object instanceof CatchBlock) {
CatchBlock cb = (CatchBlock) object;
return cb.getPageException();
}
if (object instanceof PageException)
return (PageException) object;
if (object instanceof Throwable) {
Throwable t = (Throwable) object;
return new CustomTypeException(t.getMessage(), "", "", t.getClass().getName(), "");
}
if (object instanceof Struct) {
Struct sct = (Struct) object;
String type = Caster.toString(sct.get(KeyConstants._type, ""), "").trim();
String msg = Caster.toString(sct.get(KeyConstants._message, null), null);
if (!StringUtil.isEmpty(msg, true)) {
String detail = Caster.toString(sct.get(KeyConstants._detail, null), null);
String errCode = Caster.toString(sct.get("ErrorCode", null), null);
String extInfo = Caster.toString(sct.get("ExtendedInfo", null), null);
PageException pe = null;
if ("application".equalsIgnoreCase(type))
pe = new ApplicationException(msg, detail);
else if ("expression".equalsIgnoreCase(type))
pe = new ExpressionException(msg, detail);
else
pe = new CustomTypeException(msg, detail, errCode, type, extInfo);
// Extended Info
if (!StringUtil.isEmpty(extInfo, true))
pe.setExtendedInfo(extInfo);
// Error Code
if (!StringUtil.isEmpty(errCode, true))
pe.setErrorCode(errCode);
// Additional
if (pe instanceof PageExceptionImpl) {
PageExceptionImpl pei = (PageExceptionImpl) pe;
sct = Caster.toStruct(sct.get("additional", null), null);
if (sct != null) {
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
pei.setAdditional(e.getKey(), e.getValue());
}
}
}
return pe;
}
}
return defaultValue;
}
Aggregations