Search in sources :

Example 46 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class ResourceUtil method toResourceExistingParent.

public static Resource toResourceExistingParent(PageContext pc, String destination, boolean allowRealpath) throws ExpressionException {
    destination = destination.replace('\\', '/');
    Resource res = pc.getConfig().getResource(destination);
    // not allow realpath
    if (!allowRealpath) {
        if (res.exists() || parentExists(res))
            return res;
        throw new ExpressionException("parent directory " + res.getParent() + "  for file " + destination + " doesn't exist");
    }
    // allow realpath
    if (res.isAbsolute() && (res.exists() || parentExists(res))) {
        return res;
    }
    if (StringUtil.startsWith(destination, '/')) {
        PageContextImpl pci = (PageContextImpl) pc;
        ConfigWebImpl cwi = (ConfigWebImpl) pc.getConfig();
        PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), destination, false, pci.useSpecialMappings(), true);
        // Resource[] reses = cwi.getPhysicalResourcesX(pc,pc.getApplicationContext().getMappings(),destination,false,pci.useSpecialMappings(),true);
        if (!ArrayUtil.isEmpty(sources)) {
            for (int i = 0; i < sources.length; i++) {
                if (sources[i].exists() || parentExists(sources[i])) {
                    res = sources[i].getResource();
                    if (res != null)
                        return res;
                }
            }
        }
    }
    res = getRealResource(pc, destination, res);
    if (res != null && (res.exists() || parentExists(res)))
        return res;
    throw new ExpressionException("parent directory " + res.getParent() + "  for file " + destination + " doesn't exist");
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) HTTPResource(lucee.commons.io.res.type.http.HTTPResource) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) ExpressionException(lucee.runtime.exp.ExpressionException) PageSource(lucee.runtime.PageSource)

Example 47 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class ClusterWrap method set.

@Override
public Object set(Key key, Object value) throws PageException {
    if (!core.checkValue(value))
        throw new ExpressionException("object from type [" + Caster.toTypeName(value) + "] are not allowed in cluster scope");
    ClusterEntry entry;
    core.addEntry(entry = new ClusterEntryImpl(key, (Serializable) value, offset));
    super.setEL(key, entry);
    return value;
}
Also used : ExpressionException(lucee.runtime.exp.ExpressionException)

Example 48 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class UndefinedImpl method get.

@Override
public Object get(Collection.Key key) throws PageException {
    // print.e();
    Object rtn;
    if (checkArguments) {
        rtn = local.get(key, NullSupportHelper.NULL());
        if (rtn != NullSupportHelper.NULL())
            return rtn;
        rtn = argument.getFunctionArgument(key, NullSupportHelper.NULL());
        if (rtn != NullSupportHelper.NULL()) {
            if (debug)
                debugCascadedAccess(pc, argument.getTypeAsString(), key);
            return rtn;
        }
    }
    // get data from queries
    if (allowImplicidQueryCall && pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML && !qryStack.isEmpty()) {
        rtn = qryStack.getDataFromACollection(pc, key, NullSupportHelper.NULL());
        if (rtn != NullSupportHelper.NULL()) {
            if (debug)
                debugCascadedAccess(pc, "query", key);
            if (!NullSupportHelper.full() && rtn == null)
                return "";
            return rtn;
        }
    }
    // variable
    rtn = variable.get(key, NullSupportHelper.NULL());
    if (rtn != NullSupportHelper.NULL()) {
        if (debug && checkArguments)
            debugCascadedAccess(pc, variable, rtn, key);
        return rtn;
    }
    // thread scopes
    if (pc.hasFamily()) {
        // ThreadTag.getThreadScope(pc, key, ThreadTag.LEVEL_CURRENT+ThreadTag.LEVEL_KIDS);
        rtn = pc.getThreadScope(key, NullSupportHelper.NULL());
        if (rtn != NullSupportHelper.NULL()) {
            if (debug)
                debugCascadedAccess(pc, "thread", key);
            return rtn;
        }
    }
    // get a scope value (only CFML is searching additional scopes)
    if (pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML) {
        for (int i = 0; i < scopes.length; i++) {
            rtn = scopes[i].get(key, NullSupportHelper.NULL());
            if (rtn != NullSupportHelper.NULL()) {
                if (debug)
                    debugCascadedAccess(pc, scopes[i].getTypeAsString(), key);
                return rtn;
            }
        }
    }
    if (pc.getConfig().debug())
        throw new ExpressionException(ExceptionUtil.similarKeyMessage(this, key.getString(), "key", "keys", null, false));
    throw new ExpressionException("variable [" + key.getString() + "] doesn't exist");
}
Also used : ExpressionException(lucee.runtime.exp.ExpressionException)

Example 49 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class ArrayUtil method min.

/**
 * the smallest value, of all values inside the array, only work when all values are numeric
 * @param array
 * @return the smallest value
 * @throws PageException
 */
public static double min(Array array) throws PageException {
    if (array.getDimension() > 1)
        throw new ExpressionException("can only get max value from 1 dimensional arrays");
    if (array.size() == 0)
        return 0;
    double rtn = _toDoubleValue(array, 1);
    int len = array.size();
    try {
        for (int i = 2; i <= len; i++) {
            double v = _toDoubleValue(array, i);
            if (rtn > v)
                rtn = v;
        }
    } catch (PageException e) {
        throw new ExpressionException("exception while execute array operation: " + e.getMessage());
    }
    return rtn;
}
Also used : PageException(lucee.runtime.exp.PageException) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 50 with ExpressionException

use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.

the class ArrayUtil method sum.

/**
 * sum of all values of a array, only work when all values are numeric
 * @param array Array
 * @return sum of all values
 * @throws ExpressionException
 */
public static double sum(Array array) throws ExpressionException {
    if (array.getDimension() > 1)
        throw new ExpressionException("can only get sum/avg from 1 dimensional arrays");
    double rtn = 0;
    int len = array.size();
    // try {
    for (int i = 1; i <= len; i++) {
        rtn += _toDoubleValue(array, i);
    }
    /*} 
		catch (PageException e) {
			throw new ExpressionException("exception while execute array operation: "+e.getMessage());
		}*/
    return rtn;
}
Also used : ExpressionException(lucee.runtime.exp.ExpressionException)

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