Search in sources :

Example 86 with ExpressionException

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) + "]");
}
Also used : Collection(lucee.runtime.type.Collection) List(java.util.List) Map(java.util.Map) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 87 with ExpressionException

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");
}
Also used : Iterator(java.util.Iterator) EntryArrayIterator(lucee.runtime.type.it.EntryArrayIterator) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 88 with ExpressionException

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;
}
Also used : Iterator(java.util.Iterator) EntryArrayIterator(lucee.runtime.type.it.EntryArrayIterator) Collection(lucee.runtime.type.Collection) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ExpressionException(lucee.runtime.exp.ExpressionException) LinkedHashMap(java.util.LinkedHashMap)

Example 89 with ExpressionException

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");
}
Also used : ExpressionException(lucee.runtime.exp.ExpressionException) Struct(lucee.runtime.type.Struct)

Example 90 with ExpressionException

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;
}
Also used : PageException(lucee.runtime.exp.PageException) ObjectWrap(lucee.runtime.type.ObjectWrap) PageExceptionImpl(lucee.runtime.exp.PageExceptionImpl) ExpressionException(lucee.runtime.exp.ExpressionException) Struct(lucee.runtime.type.Struct) Entry(java.util.Map.Entry) ApplicationException(lucee.runtime.exp.ApplicationException) CatchBlock(lucee.runtime.exp.CatchBlock) CustomTypeException(lucee.runtime.exp.CustomTypeException) Key(lucee.runtime.type.Collection.Key)

Aggregations

ExpressionException (lucee.runtime.exp.ExpressionException)136 Element (org.w3c.dom.Element)24 Key (lucee.runtime.type.Collection.Key)15 SecurityException (lucee.runtime.exp.SecurityException)13 ArrayList (java.util.ArrayList)12 Struct (lucee.runtime.type.Struct)12 List (java.util.List)11 Collection (lucee.runtime.type.Collection)11 Entry (java.util.Map.Entry)10 Node (org.w3c.dom.Node)10 Resource (lucee.commons.io.res.Resource)9 Iterator (java.util.Iterator)8 PageException (lucee.runtime.exp.PageException)8 Map (java.util.Map)7 CasterException (lucee.runtime.exp.CasterException)7 NodeList (org.w3c.dom.NodeList)7 PageContextImpl (lucee.runtime.PageContextImpl)6 PageSource (lucee.runtime.PageSource)5 Casting (lucee.runtime.interpreter.ref.cast.Casting)5 ArrayImpl (lucee.runtime.type.ArrayImpl)5