Search in sources :

Example 1 with ExpressionException

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

the class Image method toDimension.

private int toDimension(String label, String dimension, Info info) throws PageException {
    if (StringUtil.isEmpty(dimension))
        return -1;
    dimension = dimension.trim();
    // int value
    int i = Caster.toIntValue(dimension, -1);
    if (i > -1)
        return i;
    // percent value
    if (StringUtil.endsWith(dimension, '%')) {
        float pro = Caster.toIntValue(dimension.substring(0, dimension.length() - 1).trim(), -1);
        if (pro < 0 || pro > 100)
            throw new ExpressionException("attribute [" + label + "] value has an invalid percent definition [" + dimension + "]");
        pro /= 100F;
        return (int) (Caster.toFloatValue(info.getStruct().get(label)) * pro);
    }
    throw new ExpressionException("attribute [" + label + "] value has an invalid definition [" + dimension + "]");
}
Also used : ExpressionException(lucee.runtime.exp.ExpressionException)

Example 2 with ExpressionException

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

the class Index method doDelete.

/**
 * delete a collection
 * @throws PageException
 * @throws SearchException
 */
private void doDelete() throws PageException, SearchException {
    required("index", action, "collection", collection);
    if (type != SearchIndex.TYPE_CUSTOM)
        required("index", action, "key", key);
    // no type defined
    if (type == -1) {
        if (query != null) {
            type = SearchIndex.TYPE_CUSTOM;
        } else {
            Resource file = null;
            try {
                file = ResourceUtil.toResourceExisting(pageContext, key);
                pageContext.getConfig().getSecurityManager().checkFileLocation(file);
            } catch (ExpressionException e) {
            }
            if (file != null && file.exists() && file.isFile())
                type = SearchIndex.TYPE_FILE;
            else if (file != null && file.exists() && file.isDirectory())
                type = SearchIndex.TYPE_PATH;
            else {
                try {
                    new URL(key);
                    type = SearchIndex.TYPE_URL;
                } catch (MalformedURLException e) {
                }
            }
        }
    }
    collection.deleteIndex(pageContext, key, type, query);
}
Also used : MalformedURLException(java.net.MalformedURLException) Resource(lucee.commons.io.res.Resource) ExpressionException(lucee.runtime.exp.ExpressionException) URL(java.net.URL)

Example 3 with ExpressionException

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

the class Mail method setPriority.

public void setPriority(String strPriority) throws ExpressionException {
    strPriority = strPriority.trim().toLowerCase();
    boolean valid = true;
    if (Decision.isNumber(strPriority)) {
        int p = Caster.toIntValue(strPriority, -1);
        if (p < 1 || p > 5)
            valid = false;
        else
            this.priority = p;
    } else {
        if ("highest".equals(strPriority))
            priority = 1;
        else if ("urgent".equals(strPriority))
            priority = 1;
        else if ("high".equals(strPriority))
            priority = 2;
        else if ("normal".equals(strPriority))
            priority = 3;
        else if ("low".equals(strPriority))
            priority = 4;
        else if ("lowest".equals(strPriority))
            priority = 5;
        else if ("non-urgent".equals(strPriority))
            priority = 5;
        else if ("none-urgent".equals(strPriority))
            priority = 5;
        else
            valid = false;
    }
    if (!valid)
        throw new ExpressionException("the value of attribute priority is invalid [" + strPriority + "], " + "the value should be an integer between [1-5] or " + "one of the following [highest,urgent,high,normal,low,lowest,non-urgent]");
}
Also used : ExpressionException(lucee.runtime.exp.ExpressionException)

Example 4 with ExpressionException

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

the class Module method initFile.

@Override
public void initFile() throws MissingIncludeException, ExpressionException {
    ConfigWeb config = pageContext.getConfig();
    // MUSTMUST cache like ct
    // String[] filenames=getFileNames(config,getAppendix());// = appendix+'.'+config.getCFMLExtension();
    Object objTemplate = attributesScope.get(KeyConstants._template, null);
    Object objName = attributesScope.get(KeyConstants._name, null);
    source = null;
    if (objTemplate != null) {
        attributesScope.removeEL(KeyConstants._template);
        String template = objTemplate.toString();
        if (StringUtil.startsWith(template, '/')) {
            PageSource[] sources = ((PageContextImpl) pageContext).getPageSources(template);
            PageSource ps = MappingImpl.isOK(sources);
            if (ps == null)
                throw new MissingIncludeException(sources[0], "could not find template [" + template + "], file [" + sources[0].getDisplayPath() + "] doesn't exist");
            source = new InitFile(pageContext, ps, template);
        } else {
            source = new InitFile(pageContext, pageContext.getCurrentPageSource().getRealPage(template), template);
            if (!MappingImpl.isOK(source.getPageSource())) {
                throw new MissingIncludeException(source.getPageSource(), "could not find template [" + template + "], file [" + source.getPageSource().getDisplayPath() + "] doesn't exist");
            }
        }
        // attributesScope.removeEL(TEMPLATE);
        setAppendix(source.getPageSource());
    } else if (objName != null) {
        attributesScope.removeEL(KeyConstants._name);
        String[] filenames = toRealPath(config, objName.toString());
        boolean exist = false;
        // appcontext mappings
        Mapping[] ctms = pageContext.getApplicationContext().getCustomTagMappings();
        if (ctms != null) {
            outer: for (int f = 0; f < filenames.length; f++) {
                for (int i = 0; i < ctms.length; i++) {
                    source = new InitFile(pageContext, ctms[i].getPageSource(filenames[f]), filenames[f]);
                    if (MappingImpl.isOK(source.getPageSource())) {
                        exist = true;
                        break outer;
                    }
                }
            }
        }
        // config mappings
        if (!exist) {
            ctms = config.getCustomTagMappings();
            outer: for (int f = 0; f < filenames.length; f++) {
                for (int i = 0; i < ctms.length; i++) {
                    // TODO optimieren siehe CFTag
                    source = new InitFile(pageContext, ctms[i].getPageSource(filenames[f]), filenames[f]);
                    if (MappingImpl.isOK(source.getPageSource())) {
                        exist = true;
                        break outer;
                    }
                }
            }
        }
        if (!exist)
            throw new ExpressionException("custom tag (" + CustomTagUtil.getDisplayName(config, objName.toString()) + ") is not defined in custom tag directory [" + (ctms.length == 0 ? "no custom tag directory defined" : CustomTagUtil.toString(ctms)) + "]");
        setAppendix(source.getPageSource());
    } else {
        throw new ExpressionException("you must define attribute template or name for tag module");
    }
}
Also used : MissingIncludeException(lucee.runtime.exp.MissingIncludeException) InitFile(lucee.runtime.customtag.InitFile) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) ExpressionException(lucee.runtime.exp.ExpressionException) PageSource(lucee.runtime.PageSource)

Example 5 with ExpressionException

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

the class ThreadTag method toExecutionPlan.

private ExecutionPlan toExecutionPlan(Object obj, int plus) throws PageException {
    if (obj instanceof Struct) {
        Struct sct = (Struct) obj;
        // GERT
        // tries
        Object oTries = sct.get(KeyConstants._tries, null);
        if (oTries == null)
            throw new ExpressionException("missing key tries inside struct");
        int tries = Caster.toIntValue(oTries);
        if (tries < 0)
            throw new ExpressionException("tries must contain a none negative value");
        // interval
        Object oInterval = sct.get(KeyConstants._interval, null);
        if (oInterval == null)
            oInterval = sct.get(KeyConstants._intervall, null);
        if (oInterval == null)
            throw new ExpressionException("missing key interval inside struct");
        int interval = toSeconds(oInterval);
        if (interval < 0)
            throw new ExpressionException("interval should contain a positive value or 0");
        return new ExecutionPlanImpl(tries + plus, interval);
    }
    return new ExecutionPlanImpl(1 + plus, toSeconds(obj));
}
Also used : ExecutionPlanImpl(lucee.runtime.spooler.ExecutionPlanImpl) ExpressionException(lucee.runtime.exp.ExpressionException) Struct(lucee.runtime.type.Struct)

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