Search in sources :

Example 36 with PageException

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

the class FunctionHandlerPool method use.

/**
 * return a tag to use from a class
 * @param tagClass
 * @return Tag
 * @throws PageException
 */
public static BIF use(PageContext pc, String className, String bundleName, String bundleVersion) throws PageException {
    String id = toId(className, bundleName, bundleVersion);
    BIF bif = map.get(id);
    if (bif != null)
        return bif;
    try {
        Class<?> clazz;
        // OSGi bundle
        if (!StringUtil.isEmpty(bundleName))
            clazz = ClassUtil.loadClassByBundle(className, bundleName, bundleVersion, pc.getConfig().getIdentification());
        else
            // JAR
            clazz = ClassUtil.loadClass(className);
        if (Reflector.isInstaneOf(clazz, BIF.class))
            bif = (BIF) clazz.newInstance();
        else
            bif = new BIFProxy(clazz);
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
    map.put(id, bif);
    return bif;
}
Also used : BIF(lucee.runtime.ext.function.BIF) PageException(lucee.runtime.exp.PageException)

Example 37 with PageException

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

the class ArrayReverse method call.

public static Array call(PageContext pc, Array array) throws ExpressionException {
    Array rev = ArrayUtil.getInstance(array.getDimension());
    int len = array.size();
    for (int i = 0; i < len; i++) {
        try {
            rev.setE(len - i, array.getE(i + 1));
        } catch (PageException e) {
        }
    }
    return rev;
}
Also used : Array(lucee.runtime.type.Array) PageException(lucee.runtime.exp.PageException)

Example 38 with PageException

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

the class CacheClear method _call.

private static double _call(PageContext pc, Object filterOrTags, String cacheName) throws PageException {
    try {
        Object filter = FILTER;
        // tags
        boolean isArray = false;
        String dsn = null;
        if ((isArray = Decision.isArray(filterOrTags)) || Decision.isStruct(filterOrTags)) {
            // read tags from collection and datasource (optional)
            String[] tags;
            if (!isArray) {
                Struct sct = Caster.toStruct(filterOrTags);
                Array arr = Caster.toArray(sct.get("tags", null), null);
                if (arr == null)
                    throw new FunctionException(pc, "CacheClear", 1, "tags", "if you pass the tags within a struct, that struct need to have a key [tags] containing the tags in an array.");
                tags = ListUtil.toStringArray(arr);
                dsn = Caster.toString(sct.get(KeyConstants._datasource, null), null);
            } else {
                tags = ListUtil.toStringArray(Caster.toArray(filterOrTags));
            }
            // get default datasource
            if (StringUtil.isEmpty(dsn)) {
                Object tmp = pc.getApplicationContext().getDefDataSource();
                dsn = tmp instanceof CharSequence ? Caster.toString(tmp, null) : null;
            }
            filter = new QueryTagFilter(tags, StringUtil.isEmpty(dsn) ? null : dsn);
        } else // filter
        {
            String strFilter = Caster.toString(filterOrTags);
            if (CacheGetAllIds.isFilter(strFilter))
                filter = new WildCardFilter(strFilter, true);
        }
        Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
        if (filter instanceof CacheKeyFilter)
            return cache.remove((CacheKeyFilter) filter);
        return cache.remove((CacheEntryFilter) filter);
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
}
Also used : QueryTagFilter(lucee.runtime.cache.util.QueryTagFilter) FunctionException(lucee.runtime.exp.FunctionException) FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) WildCardFilter(lucee.runtime.cache.util.WildCardFilter) CacheKeyFilter(lucee.commons.io.cache.CacheKeyFilter) Cache(lucee.commons.io.cache.Cache)

Example 39 with PageException

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

the class CacheGetAllIds method call.

public static Array call(PageContext pc, String filter, String cacheName) throws PageException {
    try {
        Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
        List<String> keys = isFilter(filter) ? cache.keys(new WildCardFilter(filter, true)) : cache.keys();
        Iterator<String> it = keys.iterator();
        Array arr = new ArrayImpl();
        while (it.hasNext()) {
            arr.append(it.next());
        }
        return arr;
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) WildCardFilter(lucee.runtime.cache.util.WildCardFilter) FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException) Cache(lucee.commons.io.cache.Cache)

Example 40 with PageException

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

the class CachePut method _call.

private static String _call(PageContext pc, String key, Object value, Long timeSpan, Long idleTime, String cacheName) throws PageException {
    try {
        Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
        cache.put(CacheUtil.key(key), value, idleTime, timeSpan);
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
    return "";
}
Also used : FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException) Cache(lucee.commons.io.cache.Cache)

Aggregations

PageException (lucee.runtime.exp.PageException)200 ApplicationException (lucee.runtime.exp.ApplicationException)56 IOException (java.io.IOException)54 Struct (lucee.runtime.type.Struct)49 StructImpl (lucee.runtime.type.StructImpl)37 ExpressionException (lucee.runtime.exp.ExpressionException)32 Resource (lucee.commons.io.res.Resource)30 SecurityException (lucee.runtime.exp.SecurityException)26 BundleException (org.osgi.framework.BundleException)26 MalformedURLException (java.net.MalformedURLException)25 Array (lucee.runtime.type.Array)21 Key (lucee.runtime.type.Collection.Key)17 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)15 SAXException (org.xml.sax.SAXException)15 Entry (java.util.Map.Entry)14 ClassException (lucee.commons.lang.ClassException)14 DeprecatedException (lucee.runtime.exp.DeprecatedException)14 SMTPException (lucee.runtime.net.mail.SMTPException)13 ArrayImpl (lucee.runtime.type.ArrayImpl)13 Query (lucee.runtime.type.Query)13