Search in sources :

Example 6 with Scope

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

the class Exit method doEndTag.

@Override
public int doEndTag() throws TemplateException {
    Scope variables = pageContext.variablesScope();
    Object thistagObj = variables.get("thistag", null);
    boolean insideCT = (thistagObj != null) && (thistagObj instanceof lucee.runtime.type.Collection);
    // Inside Custom Tag
    if (insideCT) {
        lucee.runtime.type.Collection thistag = (lucee.runtime.type.Collection) thistagObj;
        // executionmode
        Object exeModeObj = thistag.get("executionmode", null);
        boolean isEndMode = (exeModeObj != null) && (exeModeObj instanceof String) && exeModeObj.toString().equalsIgnoreCase("end");
        // Start
        if (!isEndMode) {
            if (method == MODE_LOOP) {
                throw new TemplateException("invalid context for the tag exit, method loop can only be used in the end tag of a custom tag");
            } else if (method == MODE_EXIT_TAG) {
                thistag.setEL("executebody", Boolean.FALSE);
                return SKIP_PAGE;
            }
        } else // End
        if (method == MODE_LOOP) {
            thistag.setEL("executebody", Boolean.TRUE);
            return SKIP_PAGE;
        }
        return SKIP_PAGE;
    }
    // OUTside Custom Tag
    if (method == MODE_LOOP)
        throw new TemplateException("invalid context for the tag exit, method loop can only be used inside a custom tag");
    return SKIP_PAGE;
}
Also used : Scope(lucee.runtime.type.scope.Scope) TemplateException(lucee.runtime.exp.TemplateException)

Example 7 with Scope

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

the class Props method call.

@Override
public Object call(PageContext pc) throws PageException {
    // remote persistent (only type server is supported)
    // Caster.toString(pc.urlFormScope().get(REMOTE_PERSISTENT_ID,null),null);
    String strRemotePersisId = Caster.toString(getURLorForm(pc, REMOTE_PERSISTENT_ID, null), null);
    if (!StringUtil.isEmpty(strRemotePersisId, true)) {
        strRemotePersisId = strRemotePersisId.trim();
    } else
        strRemotePersisId = null;
    HttpServletRequest req = pc.getHttpServletRequest();
    // client
    String client = Caster.toString(req.getAttribute("client"), null);
    // call type (invocation, store-only)
    String callType = Caster.toString(req.getAttribute("call-type"), null);
    boolean internalCall = "lucee-gateway-1-0".equals(client) || "lucee-listener-1-0".equals(client);
    boolean fromRest = "lucee-rest-1-0".equals(client);
    Component component;
    try {
        pc.setSilent();
        // load the cfc
        try {
            if (internalCall && strRemotePersisId != null) {
                ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
                GatewayEngineImpl engine = config.getGatewayEngine();
                component = engine.getPersistentRemoteCFC(strRemotePersisId);
                if (component == null) {
                    component = newInstance(pc, getComponentName(), false, false, true);
                    if (!internalCall)
                        component = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_REMOTE, component);
                    engine.setPersistentRemoteCFC(strRemotePersisId, component);
                }
            } else {
                component = newInstance(pc, getComponentName(), false, false, true);
                if (!internalCall)
                    component = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_REMOTE, component);
            }
        } finally {
            pc.unsetSilent();
        }
        // Only get the Component, no invocation
        if ("store-only".equals(callType)) {
            req.setAttribute("component", component);
            return null;
        }
        // METHOD INVOCATION
        String qs = ReqRspUtil.getQueryString(pc.getHttpServletRequest());
        if (pc.getBasePageSource() == this.getPageSource() && pc.getConfig().debug())
            pc.getDebugger().setOutput(false);
        boolean isPost = pc.getHttpServletRequest().getMethod().equalsIgnoreCase("POST");
        boolean suppressContent = pc.getRequestDialect() == CFMLEngine.DIALECT_LUCEE || ((PageContextImpl) pc).getSuppressContent();
        if (suppressContent)
            pc.clear();
        Object method;
        if (fromRest) {
            callRest(pc, component, Caster.toString(req.getAttribute("rest-path"), ""), (Result) req.getAttribute("rest-result"), suppressContent);
            return null;
        }
        // POST
        if (isPost) {
            // Soap
            if (isSoap(pc)) {
                callWebservice(pc, component);
                // close(pc);
                return null;
            } else // WDDX
            if ((method = getURLorForm(pc, KeyConstants._method, null)) != null) {
                callWDDX(pc, component, KeyImpl.toKey(method), suppressContent);
                // close(pc);
                return null;
            }
        } else // GET
        {
            // WSDL
            if (qs != null && (qs.trim().equalsIgnoreCase("wsdl") || qs.trim().startsWith("wsdl&"))) {
                callWSDL(pc, component);
                // close(pc);
                return null;
            } else // WDDX
            if ((method = getURLorForm(pc, KeyConstants._method, null)) != null) {
                callWDDX(pc, component, KeyImpl.toKey(method), suppressContent);
                // close(pc);
                return null;
            }
            if (qs != null) {
                int rf = UDFUtil.toReturnFormat(qs.trim(), -1);
                if (rf != -1)
                    callCFCMetaData(pc, component, rf);
                // close(pc);
                return null;
            }
        }
        // Include MUST
        Array path = pc.getTemplatePath();
        // if(path.size()>1 ) {
        if (path.size() > 1 && !(path.size() == 3 && ListUtil.last(path.getE(2).toString(), "/\\", true).equalsIgnoreCase(pc.getRequestDialect() == CFMLEngine.DIALECT_CFML ? lucee.runtime.config.Constants.CFML_APPLICATION_EVENT_HANDLER : lucee.runtime.config.Constants.LUCEE_APPLICATION_EVENT_HANDLER))) {
            // MUSTMUST bad impl -> check with and without application . cfc
            ComponentSpecificAccess c = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, component);
            Key[] keys = c.keys();
            Object el;
            Scope var = pc.variablesScope();
            for (int i = 0; i < keys.length; i++) {
                el = c.get(keys[i], null);
                if (el instanceof UDF)
                    var.set(keys[i], el);
            }
            return null;
        }
        // DUMP
        // TODO component.setAccess(pc,Component.ACCESS_PUBLIC);
        String cdf = pc.getConfig().getComponentDumpTemplate();
        if (cdf != null && cdf.trim().length() > 0) {
            pc.variablesScope().set(KeyConstants._component, component);
            pc.doInclude(cdf, false);
        } else
            pc.write(pc.getConfig().getDefaultDumpWriter(DumpWriter.DEFAULT_RICH).toString(pc, component.toDumpData(pc, 9999, DumpUtil.toDumpProperties()), true));
    } catch (Throwable t) {
        // Exception Handler.castAnd Stack(t, this, pc);
        throw Caster.toPageException(t);
    }
    return null;
}
Also used : GatewayEngineImpl(lucee.runtime.gateway.GatewayEngineImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) Array(lucee.runtime.type.Array) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) Scope(lucee.runtime.type.scope.Scope) UDF(lucee.runtime.type.UDF) Key(lucee.runtime.type.Collection.Key)

Aggregations

Scope (lucee.runtime.type.scope.Scope)7 PageContextImpl (lucee.runtime.PageContextImpl)2 PageException (lucee.runtime.exp.PageException)2 FDLanguageException (com.intergral.fusiondebug.server.FDLanguageException)1 ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Log (lucee.commons.io.log.Log)1 PageSource (lucee.runtime.PageSource)1 ConfigImpl (lucee.runtime.config.ConfigImpl)1 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)1 ConverterException (lucee.runtime.converter.ConverterException)1 ScriptConverter (lucee.runtime.converter.ScriptConverter)1 DebugTrace (lucee.runtime.debug.DebugTrace)1 DebuggerImpl (lucee.runtime.debug.DebuggerImpl)1 Abort (lucee.runtime.exp.Abort)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 TemplateException (lucee.runtime.exp.TemplateException)1 GatewayEngineImpl (lucee.runtime.gateway.GatewayEngineImpl)1 Ref (lucee.runtime.interpreter.ref.Ref)1 BIFCall (lucee.runtime.interpreter.ref.func.BIFCall)1