Search in sources :

Example 76 with ExpressionException

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

the class CFImportTag method initFile.

@Override
public void initFile() throws PageException {
    ConfigWeb config = pageContext.getConfig();
    // = appendix+'.'+config.getCFMLExtension();
    String[] filenames = CustomTagUtil.getFileNames(config, getAppendix());
    String strRealPathes = attributesScope.remove("__custom_tag_path").toString();
    String[] realPathes = ListUtil.listToStringArray(strRealPathes, File.pathSeparatorChar);
    for (int i = 0; i < realPathes.length; i++) {
        if (!StringUtil.endsWith(realPathes[i], '/'))
            realPathes[i] = realPathes[i] + "/";
    }
    // MUSTMUST use cache like regular ct
    // page source
    PageSource ps;
    for (int rp = 0; rp < realPathes.length; rp++) {
        for (int fn = 0; fn < filenames.length; fn++) {
            ps = ((PageContextImpl) pageContext).getRelativePageSourceExisting(realPathes[rp] + filenames[fn]);
            if (ps != null) {
                source = new InitFile(pageContext, ps, filenames[fn]);
                return;
            }
        }
    }
    // EXCEPTION
    // message
    StringBuffer msg = new StringBuffer("could not find template [");
    msg.append(CustomTagUtil.getDisplayName(config, getAppendix()));
    msg.append("] in the following directories [");
    msg.append(strRealPathes.replace(File.pathSeparatorChar, ','));
    msg.append(']');
    throw new ExpressionException(msg.toString());
}
Also used : InitFile(lucee.runtime.customtag.InitFile) ConfigWeb(lucee.runtime.config.ConfigWeb) ExpressionException(lucee.runtime.exp.ExpressionException) PageSource(lucee.runtime.PageSource)

Example 77 with ExpressionException

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

the class Cookie method doStartTag.

@Override
public int doStartTag() throws PageException {
    Key key = KeyImpl.getInstance(name);
    String appName = Login.getApplicationName(pageContext.getApplicationContext());
    boolean isAppName = false;
    if (KeyConstants._CFID.equalsIgnoreCase(key) || KeyConstants._CFTOKEN.equalsIgnoreCase(key) || (isAppName = key.equals(appName))) {
        ApplicationContext ac = pageContext.getApplicationContext();
        if (ac instanceof ApplicationContextSupport) {
            ApplicationContextSupport acs = (ApplicationContextSupport) ac;
            CookieData data = isAppName ? acs.getAuthCookie() : acs.getSessionCookie();
            if (data != null && data.isDisableUpdate())
                throw new ExpressionException("customize " + key + " is disabled!");
        }
    }
    pageContext.cookieScope().setCookie(key, value, expires, secure, path, domain, httponly, preservecase, encode);
    return SKIP_BODY;
}
Also used : CookieData(lucee.runtime.listener.CookieData) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) ApplicationContext(lucee.runtime.listener.ApplicationContext) Key(lucee.runtime.type.Collection.Key) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 78 with ExpressionException

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

the class ArrayUtil method swap.

/**
 * swap to values of the array
 * @param array
 * @param left left value to swap
 * @param right right value to swap
 * @throws ExpressionException
 */
public static void swap(Array array, int left, int right) throws ExpressionException {
    int len = array.size();
    if (len == 0)
        throw new ExpressionException("array is empty");
    if (left < 1 || left > len)
        throw new ExpressionException("invalid index [" + left + "]", "valid indexes are from 1 to " + len);
    if (right < 1 || right > len)
        throw new ExpressionException("invalid index [" + right + "]", "valid indexes are from 1 to " + len);
    try {
        Object leftValue = array.get(left, null);
        Object rightValue = array.get(right, null);
        array.setE(left, rightValue);
        array.setE(right, leftValue);
    } catch (PageException e) {
        throw new ExpressionException("can't swap values of array", e.getMessage());
    }
}
Also used : PageException(lucee.runtime.exp.PageException) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 79 with ExpressionException

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

the class ArrayUtil method max.

/**
 * the greatest value, of all values inside the array, only work when all values are numeric
 * @param array
 * @return the greatest value
 * @throws PageException
 */
public static double max(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 80 with ExpressionException

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

the class ArrayUtil method median.

/**
 * median value of all items in the arrays, only works when all values are numeric
 *
 * @param array
 * @return
 * @throws ExpressionException
 */
public static double median(Array array) throws ExpressionException {
    int len = array.size();
    if (len == 0)
        return 0;
    if (array.getDimension() > 1)
        throw new ExpressionException("Median() can only be calculated for one dimensional arrays");
    double[] arr = new double[len];
    for (int i = 0; i < len; i++) arr[i] = _toDoubleValue(array, i + 1);
    Arrays.sort(arr);
    double result = arr[len / 2];
    if (len % 2 == 0) {
        return (result + arr[(len - 2) / 2]) / 2;
    }
    return result;
}
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