Search in sources :

Example 1 with Page

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

the class ChildThreadImpl method execute.

public PageException execute(Config config) {
    PageContext oldPc = ThreadLocalPageContext.get();
    Page p = page;
    PageContextImpl pc = null;
    try {
        // deamon
        if (this.pc != null) {
            pc = this.pc;
            ThreadLocalPageContext.register(pc);
        } else // task
        {
            ConfigWebImpl cwi;
            try {
                cwi = (ConfigWebImpl) config;
                DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
                pc = ThreadUtil.createPageContext(cwi, os, serverName, requestURI, queryString, SerializableCookie.toCookies(cookies), headers, null, parameters, attributes, true, -1);
                pc.setRequestTimeout(requestTimeout);
                p = PageSourceImpl.loadPage(pc, cwi.getPageSources(oldPc == null ? pc : oldPc, null, template, false, false, true));
            // p=cwi.getPageSources(oldPc,null, template, false,false,true).loadPage(cwi);
            } catch (PageException e) {
                return e;
            }
            pc.addPageSource(p.getPageSource(), true);
        }
        threadScope = pc.getThreadScope(KeyConstants._cfthread, null);
        pc.setCurrentThreadScope(new ThreadsImpl(this));
        pc.setThread(Thread.currentThread());
        // String encodings = pc.getHttpServletRequest().getHeader("Accept-Encoding");
        Undefined undefined = pc.us();
        Argument newArgs = new ArgumentThreadImpl((Struct) Duplicator.duplicate(attrs, false));
        LocalImpl newLocal = pc.getScopeFactory().getLocalInstance();
        // Key[] keys = attrs.keys();
        Iterator<Entry<Key, Object>> it = attrs.entryIterator();
        Entry<Key, Object> e;
        while (it.hasNext()) {
            e = it.next();
            newArgs.setEL(e.getKey(), e.getValue());
        }
        newLocal.setEL(KEY_ATTRIBUTES, newArgs);
        Argument oldArgs = pc.argumentsScope();
        Local oldLocal = pc.localScope();
        int oldMode = undefined.setMode(Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
        pc.setFunctionScopes(newLocal, newArgs);
        try {
            p.threadCall(pc, threadIndex);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            if (!Abort.isSilentAbort(t)) {
                ConfigWeb c = pc.getConfig();
                if (c instanceof ConfigImpl) {
                    ConfigImpl ci = (ConfigImpl) c;
                    Log log = ci.getLog("thread");
                    if (log != null)
                        LogUtil.log(log, Log.LEVEL_ERROR, this.getName(), t);
                }
                PageException pe = Caster.toPageException(t);
                if (!serializable)
                    catchBlock = pe.getCatchBlock(pc.getConfig());
                return pe;
            }
        } finally {
            completed = true;
            pc.setFunctionScopes(oldLocal, oldArgs);
            undefined.setMode(oldMode);
            // pc.getScopeFactory().recycle(newArgs);
            pc.getScopeFactory().recycle(pc, newLocal);
            if (pc.getHttpServletResponse() instanceof HttpServletResponseDummy) {
                HttpServletResponseDummy rsp = (HttpServletResponseDummy) pc.getHttpServletResponse();
                pc.flush();
                contentType = rsp.getContentType();
                Pair<String, Object>[] _headers = rsp.getHeaders();
                if (_headers != null)
                    for (int i = 0; i < _headers.length; i++) {
                        if (_headers[i].getName().equalsIgnoreCase("Content-Encoding"))
                            contentEncoding = Caster.toString(_headers[i].getValue(), null);
                    }
            }
        }
    } finally {
        pc.getConfig().getFactory().releaseLuceePageContext(pc, true);
        pc = null;
        if (oldPc != null)
            ThreadLocalPageContext.register(oldPc);
    }
    return null;
}
Also used : Argument(lucee.runtime.type.scope.Argument) Page(lucee.runtime.Page) Entry(java.util.Map.Entry) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) LocalImpl(lucee.runtime.type.scope.LocalImpl) Pair(lucee.commons.lang.Pair) PageException(lucee.runtime.exp.PageException) Undefined(lucee.runtime.type.scope.Undefined) Log(lucee.commons.io.log.Log) Local(lucee.runtime.type.scope.Local) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) DevNullOutputStream(lucee.commons.io.DevNullOutputStream) ArgumentThreadImpl(lucee.runtime.type.scope.ArgumentThreadImpl) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) HttpServletResponseDummy(lucee.runtime.net.http.HttpServletResponseDummy) Key(lucee.runtime.type.Collection.Key) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 2 with Page

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

the class DebugEntryTemplatePartComparator method writeOut.

@Override
public void writeOut(PageContext pc) throws IOException {
    // stop();
    if (!output)
        return;
    String addr = pc.getHttpServletRequest().getRemoteAddr();
    lucee.runtime.config.DebugEntry debugEntry = ((ConfigImpl) pc.getConfig()).getDebugEntry(addr, null);
    if (debugEntry == null) {
        // pc.forceWrite(pc.getConfig().getDefaultDumpWriter().toString(pc,toDumpData(pc, 9999,DumpUtil.toDumpProperties()),true));
        return;
    }
    Struct args = new StructImpl();
    args.setEL(KeyConstants._custom, debugEntry.getCustom());
    try {
        args.setEL(KeyConstants._debugging, pc.getDebugger().getDebuggingData(pc));
    } catch (PageException e1) {
    }
    try {
        String path = debugEntry.getPath();
        PageSource[] arr = ((PageContextImpl) pc).getPageSources(path);
        Page p = PageSourceImpl.loadPage(pc, arr, null);
        // patch for old path
        String fullname = debugEntry.getFullname();
        if (p == null) {
            if (path != null) {
                boolean changed = false;
                if (path.endsWith("/Modern.cfc") || path.endsWith("\\Modern.cfc")) {
                    path = "/lucee-server-context/admin/debug/Modern.cfc";
                    fullname = "lucee-server-context.admin.debug.Modern";
                    changed = true;
                } else if (path.endsWith("/Classic.cfc") || path.endsWith("\\Classic.cfc")) {
                    path = "/lucee-server-context/admin/debug/Classic.cfc";
                    fullname = "lucee-server-context.admin.debug.Classic";
                    changed = true;
                } else if (path.endsWith("/Comment.cfc") || path.endsWith("\\Comment.cfc")) {
                    path = "/lucee-server-context/admin/debug/Comment.cfc";
                    fullname = "lucee-server-context.admin.debug.Comment";
                    changed = true;
                }
                if (changed)
                    pc.write("<span style='color:red'>Please update your debug template defintions in the Lucee admin by going into the detail view and hit the \"update\" button.</span>");
            }
            arr = ((PageContextImpl) pc).getPageSources(path);
            p = PageSourceImpl.loadPage(pc, arr);
        }
        pc.addPageSource(p.getPageSource(), true);
        try {
            Component c = pc.loadComponent(fullname);
            c.callWithNamedValues(pc, "output", args);
        } finally {
            pc.removeLastPageSource(true);
        }
    } catch (PageException e) {
        pc.handlePageException(e);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) Page(lucee.runtime.Page) PageContextImpl(lucee.runtime.PageContextImpl) Struct(lucee.runtime.type.Struct) PageSource(lucee.runtime.PageSource) StructImpl(lucee.runtime.type.StructImpl) Component(lucee.runtime.Component) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 3 with Page

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

the class Renderer method loadPage.

private static Page loadPage(ConfigWeb cw, PageSource ps, String cfml, int dialect, boolean ignoreScopes) throws Exception {
    String className = HashUtil.create64BitHashAsString(cfml);
    // do we already have the page?
    Page p = pages.get(className);
    if (p != null)
        return p;
    // load class
    Constructor<? extends Page> constr = loadClass(cw, className, cfml, dialect, ignoreScopes).getDeclaredConstructor(PageSource.class);
    p = constr.newInstance(ps);
    pages.put(className, p);
    return p;
}
Also used : Page(lucee.runtime.Page)

Example 4 with Page

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

the class ComponentLoader method _search.

private static Object _search(PageContext pc, PageSource loadingLocation, String rawPath, Boolean searchLocal, Boolean searchRoot, boolean executeConstr, short returnType, final boolean isExtendedComponent) throws PageException {
    PageSource currPS = pc.getCurrentPageSource(null);
    ImportDefintion[] importDefintions = null;
    if (currPS != null) {
        Page currP;
        Component cfc = pc.getActiveComponent();
        if (cfc instanceof ComponentImpl && currPS.equals(cfc.getPageSource())) {
            importDefintions = ((ComponentImpl) cfc)._getImportDefintions();
        } else if ((currP = currPS.loadPage(pc, false, null)) != null) {
            importDefintions = currP.getImportDefintions();
        }
    }
    int dialect = currPS == null ? pc.getCurrentTemplateDialect() : currPS.getDialect();
    // first try for the current dialect
    Object obj = _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, executeConstr, returnType, currPS, importDefintions, dialect, isExtendedComponent);
    // then we try the opposite dialect
    if (obj == null && ((ConfigImpl) pc.getConfig()).allowLuceeDialect()) {
        // only when the lucee dialect is enabled we have to check the opposite
        obj = _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, executeConstr, returnType, currPS, importDefintions, dialect == CFMLEngine.DIALECT_CFML ? CFMLEngine.DIALECT_LUCEE : CFMLEngine.DIALECT_CFML, isExtendedComponent);
    }
    if (obj == null)
        throw new ExpressionException("invalid " + toStringType(returnType, dialect) + " definition, can't find " + toStringType(returnType, dialect) + " [" + rawPath + "]");
    return obj;
}
Also used : Page(lucee.runtime.Page) CIPage(lucee.runtime.CIPage) CIObject(lucee.runtime.CIObject) Component(lucee.runtime.Component) ComponentImpl(lucee.runtime.ComponentImpl) ExpressionException(lucee.runtime.exp.ExpressionException) PageSource(lucee.runtime.PageSource)

Example 5 with Page

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

the class ComponentUtil method getPage.

public static Page getPage(PageContext pc, PageSource ps) throws PageException {
    PageSourceImpl psi = (PageSourceImpl) ps;
    Page p = psi.getPage();
    if (p != null) {
        // print.o("getPage(existing):"+ps.getDisplayPath()+":"+psi.hashCode()+":"+p.hashCode());
        return p;
    }
    pc = ThreadLocalPageContext.get(pc);
    return psi.loadPage(pc, false);
}
Also used : Page(lucee.runtime.Page) PageSourceImpl(lucee.runtime.PageSourceImpl)

Aggregations

Page (lucee.runtime.Page)10 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)3 PageException (lucee.runtime.exp.PageException)3 Component (lucee.runtime.Component)2 PageContextImpl (lucee.runtime.PageContextImpl)2 PageSource (lucee.runtime.PageSource)2 ConfigImpl (lucee.runtime.config.ConfigImpl)2 ExpressionException (lucee.runtime.exp.ExpressionException)2 Struct (lucee.runtime.type.Struct)2 StructImpl (lucee.runtime.type.StructImpl)2 Entry (java.util.Map.Entry)1 DevNullOutputStream (lucee.commons.io.DevNullOutputStream)1 Log (lucee.commons.io.log.Log)1 Pair (lucee.commons.lang.Pair)1 CIObject (lucee.runtime.CIObject)1 CIPage (lucee.runtime.CIPage)1 ComponentImpl (lucee.runtime.ComponentImpl)1 Interface (lucee.runtime.Interface)1 Mapping (lucee.runtime.Mapping)1 PageContext (lucee.runtime.PageContext)1