Search in sources :

Example 1 with PageExceptionImpl

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

the class Admin method doCompileFile.

private void doCompileFile(Mapping mapping, Resource file, String path, Map<String, String> errors, Boolean explicitIgnoreScope) throws PageException {
    if (ResourceUtil.exists(file)) {
        if (file.isDirectory()) {
            Resource[] files = file.listResources(FILTER_CFML_TEMPLATES);
            if (files != null)
                for (int i = 0; i < files.length; i++) {
                    String p = path + '/' + files[i].getName();
                    // print.ln(files[i]+" - "+p);
                    doCompileFile(mapping, files[i], p, errors, explicitIgnoreScope);
                }
        } else if (file.isFile()) {
            PageSource ps = mapping.getPageSource(path);
            PageContextImpl pci = (PageContextImpl) pageContext;
            boolean envIgnoreScopes = pci.ignoreScopes();
            try {
                if (explicitIgnoreScope != null)
                    pci.setIgnoreScopes(explicitIgnoreScope);
                ((PageSourceImpl) ps).clear();
                ((PageSourceImpl) ps).loadPage(pageContext, explicitIgnoreScope != null);
            // pageContext.compile(ps);
            } catch (PageException pe) {
                SystemOut.printDate(pe);
                String template = ps.getDisplayPath();
                StringBuilder msg = new StringBuilder(pe.getMessage());
                msg.append(", Error Occurred in File [");
                msg.append(template);
                if (pe instanceof PageExceptionImpl) {
                    try {
                        PageExceptionImpl pei = (PageExceptionImpl) pe;
                        Array context = pei.getTagContext(config);
                        if (context.size() > 0) {
                            msg.append(":");
                            msg.append(Caster.toString(((Struct) context.getE(1)).get("line")));
                        }
                    } catch (Throwable t) {
                        ExceptionUtil.rethrowIfNecessary(t);
                    }
                }
                msg.append("]");
                if (errors != null)
                    errors.put(template, msg.toString());
                else
                    throw new ApplicationException(msg.toString());
            } finally {
                pci.setIgnoreScopes(envIgnoreScopes);
            }
        }
    }
}
Also used : Array(lucee.runtime.type.Array) PageException(lucee.runtime.exp.PageException) ApplicationException(lucee.runtime.exp.ApplicationException) PageExceptionImpl(lucee.runtime.exp.PageExceptionImpl) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) PageSource(lucee.runtime.PageSource) Struct(lucee.runtime.type.Struct)

Example 2 with PageExceptionImpl

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

the class Throw method toPageException.

public static PageException toPageException(Object object, PageException defaultValue) throws PageException {
    if ((object instanceof ObjectWrap))
        return toPageException(((ObjectWrap) object).getEmbededObject(), defaultValue);
    if (object instanceof CatchBlock) {
        CatchBlock cb = (CatchBlock) object;
        return cb.getPageException();
    }
    if (object instanceof PageException)
        return (PageException) object;
    if (object instanceof Throwable) {
        Throwable t = (Throwable) object;
        return new CustomTypeException(t.getMessage(), "", "", t.getClass().getName(), "");
    }
    if (object instanceof Struct) {
        Struct sct = (Struct) object;
        String type = Caster.toString(sct.get(KeyConstants._type, ""), "").trim();
        String msg = Caster.toString(sct.get(KeyConstants._message, null), null);
        if (!StringUtil.isEmpty(msg, true)) {
            String detail = Caster.toString(sct.get(KeyConstants._detail, null), null);
            String errCode = Caster.toString(sct.get("ErrorCode", null), null);
            String extInfo = Caster.toString(sct.get("ExtendedInfo", null), null);
            PageException pe = null;
            if ("application".equalsIgnoreCase(type))
                pe = new ApplicationException(msg, detail);
            else if ("expression".equalsIgnoreCase(type))
                pe = new ExpressionException(msg, detail);
            else
                pe = new CustomTypeException(msg, detail, errCode, type, extInfo);
            // Extended Info
            if (!StringUtil.isEmpty(extInfo, true))
                pe.setExtendedInfo(extInfo);
            // Error Code
            if (!StringUtil.isEmpty(errCode, true))
                pe.setErrorCode(errCode);
            // Additional
            if (pe instanceof PageExceptionImpl) {
                PageExceptionImpl pei = (PageExceptionImpl) pe;
                sct = Caster.toStruct(sct.get("additional", null), null);
                if (sct != null) {
                    Iterator<Entry<Key, Object>> it = sct.entryIterator();
                    Entry<Key, Object> e;
                    while (it.hasNext()) {
                        e = it.next();
                        pei.setAdditional(e.getKey(), e.getValue());
                    }
                }
            }
            return pe;
        }
    }
    return defaultValue;
}
Also used : PageException(lucee.runtime.exp.PageException) ObjectWrap(lucee.runtime.type.ObjectWrap) PageExceptionImpl(lucee.runtime.exp.PageExceptionImpl) ExpressionException(lucee.runtime.exp.ExpressionException) Struct(lucee.runtime.type.Struct) Entry(java.util.Map.Entry) ApplicationException(lucee.runtime.exp.ApplicationException) CatchBlock(lucee.runtime.exp.CatchBlock) CustomTypeException(lucee.runtime.exp.CustomTypeException) Key(lucee.runtime.type.Collection.Key)

Aggregations

ApplicationException (lucee.runtime.exp.ApplicationException)2 PageException (lucee.runtime.exp.PageException)2 PageExceptionImpl (lucee.runtime.exp.PageExceptionImpl)2 Struct (lucee.runtime.type.Struct)2 Entry (java.util.Map.Entry)1 Resource (lucee.commons.io.res.Resource)1 PageContextImpl (lucee.runtime.PageContextImpl)1 PageSource (lucee.runtime.PageSource)1 CatchBlock (lucee.runtime.exp.CatchBlock)1 CustomTypeException (lucee.runtime.exp.CustomTypeException)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 Array (lucee.runtime.type.Array)1 Key (lucee.runtime.type.Collection.Key)1 ObjectWrap (lucee.runtime.type.ObjectWrap)1