Search in sources :

Example 1 with MissingIncludeException

use of lucee.runtime.exp.MissingIncludeException 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 2 with MissingIncludeException

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

the class Error method setTemplate.

/**
 * set the value template
 *  The relative path to the custom error page.
 * @param template value to set
 * @throws MissingIncludeException
 */
public void setTemplate(String template) throws MissingIncludeException {
    PageSource ps = pageContext.getCurrentPageSource().getRealPage(template);
    if (!ps.exists())
        throw new MissingIncludeException(ps);
    errorPage.setTemplate(ps);
}
Also used : MissingIncludeException(lucee.runtime.exp.MissingIncludeException) PageSource(lucee.runtime.PageSource)

Example 3 with MissingIncludeException

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

the class PageContextImpl method getStatusCode.

private int getStatusCode(PageException pe) {
    int statusCode = 500;
    int maxDeepFor404 = 0;
    if (pe instanceof ModernAppListenerException) {
        pe = ((ModernAppListenerException) pe).getPageException();
        maxDeepFor404 = 1;
    } else if (pe instanceof PageExceptionBox)
        pe = ((PageExceptionBox) pe).getPageException();
    if (pe instanceof MissingIncludeException) {
        MissingIncludeException mie = (MissingIncludeException) pe;
        if (mie.getPageDeep() <= maxDeepFor404)
            statusCode = 404;
    }
    return statusCode;
}
Also used : ModernAppListenerException(lucee.runtime.listener.ModernAppListenerException) MissingIncludeException(lucee.runtime.exp.MissingIncludeException) PageExceptionBox(lucee.runtime.exp.PageExceptionBox)

Example 4 with MissingIncludeException

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

the class ClassicAppListener method _onRequest.

static void _onRequest(PageContext pc, PageSource requestedPage, PageSource application, RequestListener rl) throws PageException {
    PageContextImpl pci = (PageContextImpl) pc;
    pci.setAppListenerType(ApplicationListener.TYPE_CLASSIC);
    // on requestStart
    if (application != null)
        pci._doInclude(new PageSource[] { application }, false, null);
    if (rl != null) {
        requestedPage = rl.execute(pc, requestedPage);
        if (requestedPage == null)
            return;
    }
    // request
    try {
        pci._doInclude(new PageSource[] { requestedPage }, false, null);
    } catch (MissingIncludeException mie) {
        ApplicationContext ac = pc.getApplicationContext();
        boolean rethrow = true;
        if (ac instanceof ClassicApplicationContext) {
            ClassicApplicationContext cfc = (ClassicApplicationContext) ac;
            UDF udf = cfc.getOnMissingTemplate();
            if (udf != null) {
                String targetPage = requestedPage.getRealpathWithVirtual();
                rethrow = (!Caster.toBooleanValue(udf.call(pc, new Object[] { targetPage }, true), true));
            }
        }
        if (rethrow)
            throw mie;
    }
    // on Request End
    if (application != null) {
        PageSource onReqEnd = application.getRealPage(Constants.CFML_CLASSIC_APPLICATION_END_EVENT_HANDLER);
        if (onReqEnd.exists())
            pci._doInclude(new PageSource[] { onReqEnd }, false, null);
    }
}
Also used : UDF(lucee.runtime.type.UDF) MissingIncludeException(lucee.runtime.exp.MissingIncludeException) PageContextImpl(lucee.runtime.PageContextImpl) PageSource(lucee.runtime.PageSource)

Aggregations

MissingIncludeException (lucee.runtime.exp.MissingIncludeException)4 PageSource (lucee.runtime.PageSource)3 PageContextImpl (lucee.runtime.PageContextImpl)2 ConfigWeb (lucee.runtime.config.ConfigWeb)1 InitFile (lucee.runtime.customtag.InitFile)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 PageExceptionBox (lucee.runtime.exp.PageExceptionBox)1 ModernAppListenerException (lucee.runtime.listener.ModernAppListenerException)1 UDF (lucee.runtime.type.UDF)1