Search in sources :

Example 1 with Undefined

use of lucee.runtime.type.scope.Undefined 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 Undefined

use of lucee.runtime.type.scope.Undefined in project Lucee by lucee.

the class UDFImpl method _call.

private Object _call(PageContext pc, Collection.Key calledName, Object[] args, Struct values, boolean doIncludePath) throws PageException {
    // print.out(count++);
    PageContextImpl pci = (PageContextImpl) pc;
    Argument newArgs = pci.getScopeFactory().getArgumentInstance();
    newArgs.setFunctionArgumentNames(properties.getArgumentsSet());
    LocalImpl newLocal = pci.getScopeFactory().getLocalInstance();
    Undefined undefined = pc.undefinedScope();
    Argument oldArgs = pc.argumentsScope();
    Local oldLocal = pc.localScope();
    Collection.Key oldCalledName = pci.getActiveUDFCalledName();
    pc.setFunctionScopes(newLocal, newArgs);
    pci.setActiveUDFCalledName(calledName);
    int oldCheckArgs = undefined.setMode(pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML ? (properties.getLocalMode() == null ? pc.getApplicationContext().getLocalMode() : properties.getLocalMode().intValue()) : Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
    PageSource ps = null;
    PageSource psInc = null;
    try {
        ps = properties.getPageSource();
        if (doIncludePath)
            psInc = ps;
        if (doIncludePath && getOwnerComponent() != null) {
            psInc = ComponentUtil.getPageSource(getOwnerComponent());
            if (psInc == pci.getCurrentTemplatePageSource()) {
                psInc = null;
            }
        }
        if (ps != null)
            pci.addPageSource(ps, psInc);
        pci.addUDF(this);
        // ////////////////////////////////////////
        BodyContent bc = null;
        Boolean wasSilent = null;
        boolean bufferOutput = getBufferOutput(pci);
        if (!getOutput()) {
            if (bufferOutput)
                bc = pci.pushBody();
            else
                wasSilent = pc.setSilent() ? Boolean.TRUE : Boolean.FALSE;
        }
        UDF parent = null;
        if (ownerComponent != null) {
            parent = pci.getActiveUDF();
            pci.setActiveUDF(this);
        }
        Object returnValue = null;
        try {
            if (args != null)
                defineArguments(pc, getFunctionArguments(), args, newArgs);
            else
                defineArguments(pc, getFunctionArguments(), values, newArgs);
            returnValue = implementation(pci);
            if (ownerComponent != null)
                pci.setActiveUDF(parent);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            if (ownerComponent != null)
                pci.setActiveUDF(parent);
            if (!getOutput()) {
                if (bufferOutput)
                    BodyContentUtil.flushAndPop(pc, bc);
                else if (!wasSilent)
                    pc.unsetSilent();
            }
            // BodyContentUtil.flushAndPop(pc,bc);
            throw Caster.toPageException(t);
        }
        if (!getOutput()) {
            if (bufferOutput)
                BodyContentUtil.clearAndPop(pc, bc);
            else if (!wasSilent)
                pc.unsetSilent();
        }
        if (returnValue == null && pc.getConfig().getFullNullSupport())
            return returnValue;
        if (properties.getReturnType() == CFTypes.TYPE_ANY || !((PageContextImpl) pc).getTypeChecking())
            return returnValue;
        if (Decision.isCastableTo(properties.getReturnTypeAsString(), returnValue, false, false, -1))
            return returnValue;
        throw new UDFCasterException(this, properties.getReturnTypeAsString(), returnValue);
    // REALCAST return Caster.castTo(pageContext,returnType,returnValue,false);
    // ////////////////////////////////////////
    } finally {
        if (ps != null)
            pc.removeLastPageSource(psInc != null);
        pci.removeUDF();
        pci.setFunctionScopes(oldLocal, oldArgs);
        pci.setActiveUDFCalledName(oldCalledName);
        undefined.setMode(oldCheckArgs);
        pci.getScopeFactory().recycle(pci, newArgs);
        pci.getScopeFactory().recycle(pci, newLocal);
    }
}
Also used : Undefined(lucee.runtime.type.scope.Undefined) Argument(lucee.runtime.type.scope.Argument) Local(lucee.runtime.type.scope.Local) PageContextImpl(lucee.runtime.PageContextImpl) PageSource(lucee.runtime.PageSource) BodyContent(javax.servlet.jsp.tagext.BodyContent) Key(lucee.runtime.type.Collection.Key) LocalImpl(lucee.runtime.type.scope.LocalImpl) UDFCasterException(lucee.runtime.exp.UDFCasterException)

Example 3 with Undefined

use of lucee.runtime.type.scope.Undefined in project Lucee by lucee.

the class Evaluate method call.

public static Object call(PageContext pc, Object[] objs, boolean preciseMath) throws PageException {
    // define a ohter enviroment for the function
    if (objs.length > 1 && objs[objs.length - 1] instanceof Scope) {
        // Variables Scope
        Variables var = null;
        Local lcl = null, cLcl = null;
        Argument arg = null, cArg = null;
        if (objs[objs.length - 1] instanceof Variables) {
            var = (Variables) objs[objs.length - 1];
        } else if (objs[objs.length - 1] instanceof CallerImpl) {
            CallerImpl ci = ((CallerImpl) objs[objs.length - 1]);
            var = ci.getVariablesScope();
            lcl = ci.getLocalScope();
            arg = ci.getArgumentsScope();
        }
        if (var != null) {
            Variables cVar = pc.variablesScope();
            pc.setVariablesScope(var);
            if (lcl != null && !(lcl instanceof LocalNotSupportedScope)) {
                cLcl = pc.localScope();
                cArg = pc.argumentsScope();
                pc.setFunctionScopes(lcl, arg);
            }
            try {
                return _call(pc, objs, objs.length - 1, preciseMath);
            } finally {
                pc.setVariablesScope(cVar);
                if (cLcl != null)
                    pc.setFunctionScopes(cLcl, cArg);
            }
        } else // Undefined Scope
        if (objs[objs.length - 1] instanceof Undefined) {
            PageContextImpl pci = (PageContextImpl) pc;
            Undefined undefined = (Undefined) objs[objs.length - 1];
            boolean check = undefined.getCheckArguments();
            Variables orgVar = pc.variablesScope();
            Argument orgArgs = pc.argumentsScope();
            Local orgLocal = pc.localScope();
            pci.setVariablesScope(undefined.variablesScope());
            if (check)
                pci.setFunctionScopes(undefined.localScope(), undefined.argumentsScope());
            try {
                return _call(pc, objs, objs.length - 1, preciseMath);
            } finally {
                pc.setVariablesScope(orgVar);
                if (check)
                    pci.setFunctionScopes(orgLocal, orgArgs);
            }
        }
    }
    return _call(pc, objs, objs.length, preciseMath);
}
Also used : Variables(lucee.runtime.type.scope.Variables) Undefined(lucee.runtime.type.scope.Undefined) CallerImpl(lucee.runtime.type.scope.CallerImpl) Scope(lucee.runtime.type.scope.Scope) LocalNotSupportedScope(lucee.runtime.type.scope.LocalNotSupportedScope) Argument(lucee.runtime.type.scope.Argument) LocalNotSupportedScope(lucee.runtime.type.scope.LocalNotSupportedScope) Local(lucee.runtime.type.scope.Local) PageContextImpl(lucee.runtime.PageContextImpl)

Example 4 with Undefined

use of lucee.runtime.type.scope.Undefined in project Lucee by lucee.

the class MemberUtil method call.

public static Object call(PageContext pc, Object coll, Collection.Key methodName, Object[] args, short[] types, String[] strTypes) throws PageException {
    // look for members
    short type;
    String strType;
    Map<Key, FunctionLibFunction> members = null;
    for (int i = 0; i < types.length; i++) {
        type = types[i];
        strType = strTypes[i];
        members = getMembers(pc, type);
        FunctionLibFunction member = members.get(methodName);
        if (member != null) {
            List<FunctionLibFunctionArg> _args = member.getArg();
            if (args.length < _args.size()) {
                ArrayList<Ref> refs = new ArrayList<Ref>();
                int pos = member.getMemberPosition();
                FunctionLibFunctionArg flfa;
                Iterator<FunctionLibFunctionArg> it = _args.iterator();
                int glbIndex = 0, argIndex = -1;
                while (it.hasNext()) {
                    glbIndex++;
                    flfa = it.next();
                    if (glbIndex == pos) {
                        refs.add(new Casting(strType, type, coll));
                    } else if (args.length > ++argIndex) {
                        // careful, argIndex is only incremented when condition above is false
                        refs.add(new Casting(flfa.getTypeAsString(), flfa.getType(), args[argIndex]));
                    }
                }
                return new BIFCall(coll, member, refs.toArray(new Ref[refs.size()])).getValue(pc);
            }
        }
    }
    // do reflection
    if (pc.getConfig().getSecurityManager().getAccess(lucee.runtime.security.SecurityManager.TYPE_DIRECT_JAVA_ACCESS) == lucee.runtime.security.SecurityManager.VALUE_YES) {
        if (!(coll instanceof Undefined)) {
            Object res = callMethod(coll, methodName, args);
            if (res != DEFAULT)
                return res;
        }
    }
    // merge
    if (types.length > 1) {
        Map<Key, FunctionLibFunction> tmp;
        members = null;
        for (int i = 0; i < types.length; i++) {
            tmp = getMembers(pc, types[i]);
            if (members == null)
                members = tmp;
            else {
                Iterator<Entry<Key, FunctionLibFunction>> it = tmp.entrySet().iterator();
                Entry<Key, FunctionLibFunction> e;
                while (it.hasNext()) {
                    e = it.next();
                    members.put(e.getKey(), e.getValue());
                }
            }
        }
    }
    Set<Key> set = members.keySet();
    String msg = ExceptionUtil.similarKeyMessage(set.toArray(new Key[set.size()]), methodName.getString(), "function", "functions", "Object", true);
    throw new ExpressionException(msg);
// throw new ExpressionException("No matching function member ["+methodName+"] found, available function members are ["+
// lucee.runtime.type.util.ListUtil.sort(CollectionUtil.getKeyList(members.keySet().iterator(), ","),"textnocase","asc",",")+"]");
}
Also used : Undefined(lucee.runtime.type.scope.Undefined) ArrayList(java.util.ArrayList) LString(lucee.runtime.interpreter.ref.literal.LString) ExpressionException(lucee.runtime.exp.ExpressionException) Casting(lucee.runtime.interpreter.ref.cast.Casting) Ref(lucee.runtime.interpreter.ref.Ref) Entry(java.util.Map.Entry) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) BIFCall(lucee.runtime.interpreter.ref.func.BIFCall) Key(lucee.runtime.type.Collection.Key) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg)

Example 5 with Undefined

use of lucee.runtime.type.scope.Undefined in project Lucee by lucee.

the class CFTag method doInclude.

void doInclude() throws PageException {
    Variables var = pageContext.variablesScope();
    pageContext.setVariablesScope(ctVariablesScope);
    QueryStack cs = null;
    Undefined undefined = pageContext.undefinedScope();
    int oldMode = undefined.setMode(Undefined.MODE_NO_LOCAL_AND_ARGUMENTS);
    if (oldMode != Undefined.MODE_NO_LOCAL_AND_ARGUMENTS)
        callerScope.setScope(var, pageContext.localScope(), pageContext.argumentsScope(), true);
    else
        callerScope.setScope(var, null, null, false);
    if (pageContext.getConfig().allowImplicidQueryCall()) {
        cs = undefined.getQueryStack();
        undefined.setQueryStack(new QueryStackImpl());
    }
    try {
        pageContext.doInclude(new PageSource[] { source.getPageSource() }, false);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    } finally {
        undefined.setMode(oldMode);
        // varScopeData=variablesScope.getMap();
        pageContext.setVariablesScope(var);
        if (pageContext.getConfig().allowImplicidQueryCall()) {
            undefined.setQueryStack(cs);
        }
    }
}
Also used : Variables(lucee.runtime.type.scope.Variables) Undefined(lucee.runtime.type.scope.Undefined) QueryStack(lucee.runtime.util.QueryStack) QueryStackImpl(lucee.runtime.util.QueryStackImpl)

Aggregations

Undefined (lucee.runtime.type.scope.Undefined)9 PageContextImpl (lucee.runtime.PageContextImpl)4 Argument (lucee.runtime.type.scope.Argument)4 Local (lucee.runtime.type.scope.Local)4 PageException (lucee.runtime.exp.PageException)3 Key (lucee.runtime.type.Collection.Key)3 Variables (lucee.runtime.type.scope.Variables)3 Entry (java.util.Map.Entry)2 PageContext (lucee.runtime.PageContext)2 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)2 CallerImpl (lucee.runtime.type.scope.CallerImpl)2 LocalImpl (lucee.runtime.type.scope.LocalImpl)2 ArrayList (java.util.ArrayList)1 BodyContent (javax.servlet.jsp.tagext.BodyContent)1 DevNullOutputStream (lucee.commons.io.DevNullOutputStream)1 Log (lucee.commons.io.log.Log)1 Pair (lucee.commons.lang.Pair)1 SerializableObject (lucee.commons.lang.SerializableObject)1 Page (lucee.runtime.Page)1 PageSource (lucee.runtime.PageSource)1