Search in sources :

Example 1 with PageSource

use of lucee.runtime.PageSource 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 PageSource

use of lucee.runtime.PageSource in project Lucee by lucee.

the class TagUtil method addTagMetaData.

private static void addTagMetaData(PageContext pc, TagLib tl, TagLibTag tlt, String filename, boolean isWeb) {
    if (pc == null)
        return;
    try {
        ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
        PageSource ps = isWeb ? config.getTagMapping().getPageSource(filename) : config.getServerTagMapping().getPageSource(filename);
        // Page p = ps.loadPage(pc);
        ComponentImpl c = ComponentLoader.loadComponent(pc, ps, filename, true, true);
        ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, c);
        Struct meta = Caster.toStruct(cw.get(KeyConstants._metadata, null), null);
        // TODO handle all metadata here and make checking at runtime useless
        if (meta != null) {
            // parse body
            boolean rtexprvalue = Caster.toBooleanValue(meta.get(KeyConstants._parsebody, Boolean.FALSE), false);
            tlt.setParseBody(rtexprvalue);
            // hint
            String hint = Caster.toString(meta.get(KeyConstants._hint, null), null);
            if (!StringUtil.isEmpty(hint))
                tlt.setDescription(hint);
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) ComponentImpl(lucee.runtime.ComponentImpl) PageSource(lucee.runtime.PageSource) Struct(lucee.runtime.type.Struct)

Example 3 with PageSource

use of lucee.runtime.PageSource in project Lucee by lucee.

the class Admin method doGetError.

private void doGetError() throws PageException {
    Struct sct = new StructImpl();
    pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
    // sct.set("errorTemplate",config.getErrorTemplate());
    Struct templates = new StructImpl();
    Struct str = new StructImpl();
    sct.set(TEMPLATES, templates);
    sct.set(STR, str);
    sct.set(DO_STATUS_CODE, Caster.toBoolean(config.getErrorStatusCode()));
    // 500
    String template = config.getErrorTemplate(500);
    try {
        PageSource ps = ((PageContextImpl) pageContext).getPageSourceExisting(template);
        if (ps != null)
            templates.set("500", ps.getDisplayPath());
        else
            templates.set("500", "");
    } catch (PageException e) {
        templates.set("500", "");
    }
    str.set("500", template);
    // 404
    template = config.getErrorTemplate(404);
    try {
        PageSource ps = ((PageContextImpl) pageContext).getPageSourceExisting(template);
        if (ps != null)
            templates.set("404", ps.getDisplayPath());
        else
            templates.set("404", "");
    } catch (PageException e) {
        templates.set("404", "");
    }
    str.set("404", template);
}
Also used : PageException(lucee.runtime.exp.PageException) StructImpl(lucee.runtime.type.StructImpl) PageContextImpl(lucee.runtime.PageContextImpl) Struct(lucee.runtime.type.Struct) PageSource(lucee.runtime.PageSource)

Example 4 with PageSource

use of lucee.runtime.PageSource in project Lucee by lucee.

the class Admin method doAddDump.

private void doAddDump() throws ApplicationException {
    Debugger debugger = pageContext.getDebugger();
    PageSource ps = pageContext.getCurrentTemplatePageSource();
    if (ps != null)
        debugger.addDump(ps, getString("admin", action, "dump", true));
}
Also used : Debugger(lucee.runtime.debug.Debugger) PageSource(lucee.runtime.PageSource)

Example 5 with PageSource

use of lucee.runtime.PageSource 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)

Aggregations

PageSource (lucee.runtime.PageSource)59 PageContextImpl (lucee.runtime.PageContextImpl)19 Resource (lucee.commons.io.res.Resource)16 Struct (lucee.runtime.type.Struct)10 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)8 Mapping (lucee.runtime.Mapping)7 PageException (lucee.runtime.exp.PageException)7 StructImpl (lucee.runtime.type.StructImpl)7 ConfigImpl (lucee.runtime.config.ConfigImpl)6 ConfigWeb (lucee.runtime.config.ConfigWeb)6 ExpressionException (lucee.runtime.exp.ExpressionException)6 ArrayList (java.util.ArrayList)5 Component (lucee.runtime.Component)5 PageSourceCode (lucee.transformer.util.PageSourceCode)5 IOException (java.io.IOException)4 MissingIncludeException (lucee.runtime.exp.MissingIncludeException)4 Array (lucee.runtime.type.Array)4 LitString (lucee.transformer.expression.literal.LitString)4 HTTPResource (lucee.commons.io.res.type.http.HTTPResource)3 Entry (java.util.Map.Entry)2