Search in sources :

Example 11 with ApplicationException

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

the class InvokeArgument method doStartTag.

@Override
public int doStartTag() throws PageException {
    Tag parent = getParent();
    while (parent != null && !(parent instanceof Invoke)) {
        parent = parent.getParent();
    }
    if (parent instanceof Invoke) {
        Invoke invoke = (Invoke) parent;
        invoke.setArgument(name, value);
    } else {
        throw new ApplicationException("Wrong Context, tag InvokeArgument must be inside a Invoke tag");
    }
    return SKIP_BODY;
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) Tag(javax.servlet.jsp.tagext.Tag)

Example 12 with ApplicationException

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

the class Location method setStatuscode.

/**
 * @param statuscode the statuscode to set
 * @throws ApplicationException
 */
public void setStatuscode(double statuscode) throws ApplicationException {
    int sc = (int) statuscode;
    if (sc < 300 || sc > 307)
        throw new ApplicationException("invalid value for attribute statuscode [" + Caster.toString(statuscode) + "]", "attribute must have one of the folloing values [300|301|302|303|304|305|307]");
    this.statuscode = sc;
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException)

Example 13 with ApplicationException

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

the class Log method doStartTag.

@Override
public int doStartTag() throws PageException {
    if (text == null && exception == null)
        throw new ApplicationException("Wrong Context, you must define one of the following attributes [text, exception]");
    PageContextImpl pci = (PageContextImpl) pageContext;
    ConfigImpl config = (ConfigImpl) pageContext.getConfig();
    lucee.commons.io.log.Log logger;
    if (file == null) {
        logger = pci.getLog(log.toLowerCase(), false);
        if (logger == null) {
            // for backward compatiblity
            if ("console".equalsIgnoreCase(log))
                logger = new LogAdapter(Log4jUtil.getConsoleLog(config, false, "cflog", Level.INFO));
            else {
                java.util.Collection<String> set = pci.getLogNames();
                Iterator<String> it = set.iterator();
                lucee.runtime.type.Collection.Key[] keys = new lucee.runtime.type.Collection.Key[set.size()];
                int index = 0;
                while (it.hasNext()) {
                    keys[index++] = KeyImpl.init(it.next());
                }
                throw new ApplicationException(ExceptionUtil.similarKeyMessage(keys, log, "attribute log", "log names", null, true));
            }
        }
    } else {
        logger = getFileLog(pageContext, file, charset, async);
    }
    String contextName = pageContext.getApplicationContext().getName();
    if (contextName == null || !application)
        contextName = "";
    if (exception != null) {
        if (StringUtil.isEmpty(text))
            LogUtil.log(logger, type, contextName, exception);
        else
            LogUtil.log(logger, type, contextName, text, exception);
    } else if (!StringUtil.isEmpty(text))
        logger.log(type, contextName, text);
    else
        throw new ApplicationException("you must define attribute text or attribute exception with the tag cflog");
    // logger.write(toStringType(type),contextName,text);
    return SKIP_BODY;
}
Also used : PageContextImpl(lucee.runtime.PageContextImpl) ApplicationException(lucee.runtime.exp.ApplicationException) LogAdapter(lucee.commons.io.log.log4j.LogAdapter) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 14 with ApplicationException

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

the class MailParam method doStartTag.

@Override
public int doStartTag() throws PageException {
    if (content != null) {
        required("mailparam", "file", file);
        String id = "id-" + CreateUniqueId.invoke();
        String ext = ResourceUtil.getExtension(file, "tmp");
        if (StringUtil.isEmpty(fileName) && !StringUtil.isEmpty(file))
            fileName = ListUtil.last(file, "/\\", true);
        Resource res = SystemUtil.getTempDirectory().getRealResource(id + "." + ext);
        if (res.exists())
            ResourceUtil.removeEL(res, true);
        try {
            IOUtil.write(res, content);
        } catch (IOException e) {
            throw Caster.toPageException(e);
        }
        this.file = ResourceUtil.getCanonicalPathEL(res);
        remove = true;
    } else if (!StringUtil.isEmpty(this.file)) {
        Resource res = ResourceUtil.toResourceNotExisting(pageContext, this.file);
        if (res != null) {
            if (res.exists())
                pageContext.getConfig().getSecurityManager().checkFileLocation(res);
            this.file = ResourceUtil.getCanonicalPathEL(res);
        }
    }
    // check attributes
    boolean hasFile = !StringUtil.isEmpty(file);
    boolean hasName = !StringUtil.isEmpty(name);
    // both attributes
    if (hasName && hasFile) {
        throw new ApplicationException("Wrong Context for tag MailParam, you cannot use attribute file and name together");
    }
    // no attributes
    if (!hasName && !hasFile) {
        throw new ApplicationException("Wrong Context for tag MailParam, you must use attribute file or attribute name for this tag");
    }
    // get Mail Tag
    Tag parent = getParent();
    while (parent != null && !(parent instanceof Mail)) {
        parent = parent.getParent();
    }
    if (parent instanceof Mail) {
        Mail mail = (Mail) parent;
        mail.setParam(type, file, fileName, name, value, disposition, contentID, remove);
    } else {
        throw new ApplicationException("Wrong Context, tag MailParam must be inside a Mail tag");
    }
    return SKIP_BODY;
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) Tag(javax.servlet.jsp.tagext.Tag)

Example 15 with ApplicationException

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

the class ObjectCache method _doStartTag.

public void _doStartTag() throws PageException, IOException {
    CacheHandlerCollection factory = null;
    Cache cache = null;
    if (type == TYPE_FUNCTION)
        factory = pageContext.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_FUNCTION, null);
    else if (type == TYPE_INCLUDE)
        factory = pageContext.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_INCLUDE, null);
    else if (type == TYPE_QUERY)
        factory = pageContext.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_QUERY, null);
    else if (type == TYPE_RESOURCE) {
        cache = CacheUtil.getDefault(pageContext, Config.CACHE_TYPE_RESOURCE, null);
        // no specific cache is defined, get default default cache
        if (cache == null) {
            // get cache resource provider
            CacheResourceProvider crp = null;
            ResourceProvider[] providers = ResourcesImpl.getGlobal().getResourceProviders();
            for (int i = 0; i < providers.length; i++) {
                if (providers[i].getScheme().equals("ram") && providers[i] instanceof CacheResourceProvider) {
                    crp = (CacheResourceProvider) providers[i];
                }
            }
            if (crp == null)
                throw new ApplicationException(Constants.NAME + " was not able to load the Ram Resource Provider");
            // get cache from resource provider
            cache = crp.getCache();
        }
    } else if (type == TYPE_OBJECT) {
        // throws a exception if not explicitly defined
        cache = CacheUtil.getDefault(pageContext, Config.CACHE_TYPE_OBJECT);
    } else if (type == TYPE_TEMPLATE) {
        // throws a exception if not explicitly defined
        cache = CacheUtil.getDefault(pageContext, Config.CACHE_TYPE_TEMPLATE);
    }
    // Clear
    if (action.equalsIgnoreCase("clear")) {
        if (filter == null) {
            if (cache != null)
                cache.remove(CacheKeyFilterAll.getInstance());
            else
                factory.clear(pageContext);
        } else {
            if (cache != null)
                CacheHandlerCollectionImpl.clear(pageContext, cache, filter);
            else
                factory.clear(pageContext, filter);
        }
    } else // Size
    if (action.equalsIgnoreCase("size")) {
        int size = 0;
        if (cache != null)
            size = cache.keys().size();
        else
            size = factory.size(pageContext);
        pageContext.setVariable(result, Caster.toDouble(size));
    } else
        throw new ApplicationException("attribute action has an invalid value [" + action + "], valid is only [clear,size]");
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) CacheHandlerCollection(lucee.runtime.cache.tag.CacheHandlerCollection) CacheResourceProvider(lucee.commons.io.res.type.cache.CacheResourceProvider) Cache(lucee.commons.io.cache.Cache)

Aggregations

ApplicationException (lucee.runtime.exp.ApplicationException)173 IOException (java.io.IOException)41 Resource (lucee.commons.io.res.Resource)36 PageException (lucee.runtime.exp.PageException)30 Struct (lucee.runtime.type.Struct)25 SecurityException (lucee.runtime.exp.SecurityException)17 BundleException (org.osgi.framework.BundleException)16 StructImpl (lucee.runtime.type.StructImpl)15 MalformedURLException (java.net.MalformedURLException)13 Element (org.w3c.dom.Element)13 Array (lucee.runtime.type.Array)12 Key (lucee.runtime.type.Collection.Key)12 Iterator (java.util.Iterator)11 InputStream (java.io.InputStream)10 Query (lucee.runtime.type.Query)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ExpressionException (lucee.runtime.exp.ExpressionException)9 Entry (java.util.Map.Entry)8 PageContextImpl (lucee.runtime.PageContextImpl)8 ClassDefinition (lucee.runtime.db.ClassDefinition)8