Search in sources :

Example 16 with RefBooleanImpl

use of lucee.commons.lang.types.RefBooleanImpl in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method __singleAttrStatement.

private final Statement __singleAttrStatement(Body parent, ExprData data, TagLibTag tlt, boolean allowTwiceAttr) throws TemplateException {
    String tagName = tlt.getName();
    if (data.srcCode.forwardIfCurrent(tagName)) {
        if (!data.srcCode.isCurrent(' ') && !data.srcCode.isCurrent(';')) {
            data.srcCode.setPos(data.srcCode.getPos() - tagName.length());
            return null;
        }
    } else
        return null;
    int pos = data.srcCode.getPos() - tagName.length();
    Position line = data.srcCode.getPosition();
    // TagLibTag tlt = CFMLTransformer.getTLT(data.srcCode,tagName.equals("pageencoding")?"processingdirective":tagName);
    Tag tag = getTag(data, parent, tlt, line, null);
    tag.setScriptBase(true);
    tag.setTagLibTag(tlt);
    comments(data);
    // attribute
    TagLibTagAttr attr = tlt.getScript().getSingleAttr();
    String attrName = null;
    Expression attrValue = null;
    short attrType = ATTR_TYPE_NONE;
    if (attr != null) {
        attrType = attr.getScriptSupport();
        char c = data.srcCode.getCurrent();
        if (ATTR_TYPE_REQUIRED == attrType || (!data.srcCode.isCurrent(';') && ATTR_TYPE_OPTIONAL == attrType)) {
            if (data.srcCode.isCurrent('{')) {
                // this can be only a json string
                int p = data.srcCode.getPos();
                try {
                    attrValue = isSimpleValue(attr.getType()) ? null : json(data, JSON_STRUCT, '{', '}');
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                    data.srcCode.setPos(p);
                }
            } else
                attrValue = attributeValue(data, tlt.getScript().getRtexpr());
            if (attrValue != null && isOperator(c)) {
                data.srcCode.setPos(pos);
                return null;
            }
        }
    }
    if (attrValue != null) {
        attrName = attr.getName();
        TagLibTagAttr tlta = tlt.getAttribute(attr.getName(), true);
        tag.addAttribute(new Attribute(false, attrName, CastOther.toExpression(attrValue, tlta.getType()), tlta.getType()));
    } else if (ATTR_TYPE_REQUIRED == attrType) {
        data.srcCode.setPos(pos);
        return null;
    }
    // body
    if (tlt.getHasBody()) {
        Body body = new BodyBase(data.factory);
        boolean wasSemiColon = statement(data, body, tlt.getScript().getContext());
        if (!wasSemiColon || !tlt.isBodyFree() || body.hasStatements())
            tag.setBody(body);
    } else
        checkSemiColonLineFeed(data, true, true, true);
    if (tlt.hasTTE())
        data.ep.add(tlt, tag, data.flibs, data.srcCode);
    if (!StringUtil.isEmpty(attrName))
        validateAttributeName(attrName, data.srcCode, new ArrayList<String>(), tlt, new RefBooleanImpl(false), new StringBuffer(), allowTwiceAttr);
    tag.setEnd(data.srcCode.getPosition());
    eval(tlt, data, tag);
    return tag;
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) Position(lucee.transformer.Position) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ArrayList(java.util.ArrayList) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase)

Example 17 with RefBooleanImpl

use of lucee.commons.lang.types.RefBooleanImpl in project Lucee by lucee.

the class ModernAppListener method _onRequest.

protected void _onRequest(PageContext pc, PageSource requestedPage, PageSource appPS, RequestListener rl) throws PageException {
    PageContextImpl pci = (PageContextImpl) pc;
    pci.setAppListenerType(ApplicationListener.TYPE_MODERN);
    if (appPS != null) {
        String callPath = appPS.getComponentName();
        Component app = ComponentLoader.loadComponent(pci, appPS, callPath, false, false);
        // init
        ModernApplicationContext appContext = initApplicationContext(pci, app);
        apps.put(appContext.getName(), app);
        if (!pci.initApplicationContext(this))
            return;
        if (rl != null) {
            requestedPage = rl.execute(pc, requestedPage);
            if (requestedPage == null)
                return;
        }
        String targetPage = requestedPage.getRealpathWithVirtual();
        RefBoolean goon = new RefBooleanImpl(true);
        // onRequestStart
        if (app.contains(pc, ON_REQUEST_START)) {
            try {
                Object rtn = call(app, pci, ON_REQUEST_START, new Object[] { targetPage }, false);
                if (!Caster.toBooleanValue(rtn, true))
                    return;
            } catch (PageException pe) {
                pe = handlePageException(pci, app, pe, requestedPage, targetPage, goon);
                if (pe != null)
                    throw pe;
            }
        }
        // onRequest
        if (goon.toBooleanValue()) {
            boolean isComp = isComponent(pc, requestedPage);
            Object method;
            if (isComp && app.contains(pc, ON_CFCREQUEST) && (method = pc.urlFormScope().get(KeyConstants._method, null)) != null) {
                Struct url = (Struct) Duplicator.duplicate(pc.urlFormScope(), true);
                url.removeEL(KeyConstants._fieldnames);
                url.removeEL(KeyConstants._method);
                Object args = url.get(KeyConstants._argumentCollection, null);
                // url returnFormat
                Object oReturnFormat = url.removeEL(KeyConstants._returnFormat);
                int urlReturnFormat = -1;
                if (oReturnFormat != null)
                    urlReturnFormat = UDFUtil.toReturnFormat(Caster.toString(oReturnFormat, null), -1);
                // request header accept
                List<MimeType> accept = ReqRspUtil.getAccept(pc);
                int headerReturnFormat = MimeType.toFormat(accept, -1, -1);
                Object queryFormat = url.removeEL(KeyConstants._queryFormat);
                if (args == null) {
                    args = pc.getHttpServletRequest().getAttribute("argumentCollection");
                }
                if (args instanceof String) {
                    args = new JSONExpressionInterpreter().interpret(pc, (String) args);
                }
                if (args != null) {
                    if (Decision.isCastableToStruct(args)) {
                        Struct sct = Caster.toStruct(args, false);
                        // Key[] keys = url.keys();
                        Iterator<Entry<Key, Object>> it = url.entryIterator();
                        Entry<Key, Object> e;
                        while (it.hasNext()) {
                            e = it.next();
                            sct.setEL(e.getKey(), e.getValue());
                        }
                        args = sct;
                    } else if (Decision.isCastableToArray(args)) {
                        args = Caster.toArray(args);
                    } else {
                        Array arr = new ArrayImpl();
                        arr.appendEL(args);
                        args = arr;
                    }
                } else
                    args = url;
                Object rtn = call(app, pci, ON_CFCREQUEST, new Object[] { requestedPage.getComponentName(), method, args }, true);
                if (rtn != null) {
                    if (pc.getHttpServletRequest().getHeader("AMF-Forward") != null) {
                        pc.variablesScope().setEL("AMF-Forward", rtn);
                    // ThreadLocalWDDXResult.set(rtn);
                    } else {
                        try {
                            ComponentPageImpl.writeToResponseStream(pc, app, method.toString(), urlReturnFormat, headerReturnFormat, queryFormat, rtn);
                        } catch (Exception e) {
                            throw Caster.toPageException(e);
                        }
                    }
                }
            } else {
                // TODO impl die nicht so generisch ist
                try {
                    if (!isComp && app.contains(pc, ON_REQUEST))
                        call(app, pci, ON_REQUEST, new Object[] { targetPage }, false);
                    else
                        pci._doInclude(new PageSource[] { requestedPage }, false, null);
                } catch (PageException pe) {
                    pe = handlePageException(pci, app, pe, requestedPage, targetPage, goon);
                    if (pe != null)
                        throw pe;
                }
            }
        }
        // onRequestEnd
        if (goon.toBooleanValue() && app.contains(pc, ON_REQUEST_END)) {
            try {
                call(app, pci, ON_REQUEST_END, new Object[] { targetPage }, false);
            } catch (PageException pe) {
                pe = handlePageException(pci, app, pe, requestedPage, targetPage, goon);
                if (pe != null)
                    throw pe;
            }
        }
    } else {
        apps.put(pc.getApplicationContext().getName(), null);
        if (rl != null) {
            requestedPage = rl.execute(pc, requestedPage);
            if (requestedPage == null)
                return;
        }
        pci._doInclude(new PageSource[] { requestedPage }, false, null);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) RefBoolean(lucee.commons.lang.types.RefBoolean) ArrayImpl(lucee.runtime.type.ArrayImpl) PageContextImpl(lucee.runtime.PageContextImpl) MimeType(lucee.commons.lang.mimetype.MimeType) PageException(lucee.runtime.exp.PageException) MissingIncludeException(lucee.runtime.exp.MissingIncludeException) IOException(java.io.IOException) Struct(lucee.runtime.type.Struct) PageSource(lucee.runtime.PageSource) Array(lucee.runtime.type.Array) Entry(java.util.Map.Entry) JSONExpressionInterpreter(lucee.runtime.interpreter.JSONExpressionInterpreter) Component(lucee.runtime.Component) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) Key(lucee.runtime.type.Collection.Key)

Example 18 with RefBooleanImpl

use of lucee.commons.lang.types.RefBooleanImpl in project Lucee by lucee.

the class ComponentHandler method setupService.

/**
 * handle all the work necessary set
 * up the "proxy" RPC service surrounding it as the MessageContext's
 * active service.
 */
protected void setupService(MessageContext msgContext) throws Exception {
    RefBoolean isnew = new RefBooleanImpl(false);
    Component cfc = (Component) msgContext.getProperty(Constants.COMPONENT);
    Class clazz = cfc.getJavaAccessClass(ThreadLocalPageContext.get(), isnew, false, true, true, true);
    String clazzName = clazz.getName();
    ClassLoader classLoader = clazz.getClassLoader();
    Pair pair;
    SOAPService rpc = null;
    if (!isnew.toBooleanValue() && (pair = (Pair) soapServices.get(clazzName)) != null) {
        if (classLoader == pair.classloader)
            rpc = pair.rpc;
    }
    // else classLoader = clazz.getClassLoader();
    // print.out("cl:"+classLoader);
    msgContext.setClassLoader(classLoader);
    if (rpc == null) {
        rpc = new SOAPService(new RPCProvider());
        rpc.setName(clazzName);
        rpc.setOption(JavaProvider.OPTION_CLASSNAME, clazzName);
        rpc.setEngine(msgContext.getAxisEngine());
        rpc.setOption(JavaProvider.OPTION_ALLOWEDMETHODS, "*");
        rpc.setOption(JavaProvider.OPTION_SCOPE, Scope.REQUEST.getName());
        rpc.getInitializedServiceDesc(msgContext);
        soapServices.put(clazzName, new Pair(classLoader, rpc));
    }
    rpc.setEngine(msgContext.getAxisEngine());
    // ??
    rpc.init();
    msgContext.setService(rpc);
}
Also used : SOAPService(org.apache.axis.handlers.soap.SOAPService) RefBoolean(lucee.commons.lang.types.RefBoolean) RPCProvider(org.apache.axis.providers.java.RPCProvider) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) Component(lucee.runtime.Component)

Example 19 with RefBooleanImpl

use of lucee.commons.lang.types.RefBooleanImpl in project Lucee by lucee.

the class InstrumentationFactory method getInstrumentation.

public static synchronized Instrumentation getInstrumentation(final Config config) {
    final Log log = config.getLog("application");
    final CFMLEngine engine = ConfigWebUtil.getEngine(config);
    Instrumentation instr = _getInstrumentation(log, config);
    // agent already exist
    if (instr != null)
        return instr;
    AccessController.doPrivileged(new PrivilegedAction<Object>() {

        @Override
        public Object run() {
            ClassLoader ccl = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
            try {
                JavaVendor vendor = JavaVendor.getCurrentVendor();
                Resource toolsJar = null;
                // When running on IBM, the attach api classes are packaged in vm.jar which is a part
                // of the default vm classpath.
                RefBoolean useOurOwn = new RefBooleanImpl(true);
                // if (!vendor.isIBM()) {
                // If we can't find the tools.jar and we're not on IBM we can't load the agent.
                toolsJar = findToolsJar(config, log, useOurOwn);
                if (toolsJar == null) {
                    return null;
                }
                // }
                log.info("Instrumentation", "tools.jar used:" + toolsJar);
                // add the attach native library
                if (useOurOwn.toBooleanValue())
                    addAttachIfNecessary(config, log);
                Class<?> vmClass = loadVMClass(toolsJar, log, vendor);
                log.info("Instrumentation", "loaded VirtualMachine class:" + (vmClass == null ? "null" : vmClass.getName()));
                if (vmClass == null) {
                    return null;
                }
                String agentPath = createAgentJar(log, config).getAbsolutePath();
                if (agentPath == null) {
                    return null;
                }
                log.info("Instrumentation", "try to load agent (path:" + agentPath + ")");
                loadAgent(config, log, agentPath, vmClass);
            // log.info("Instrumentation","agent loaded (path:"+agentPath+")");
            } catch (IOException ioe) {
                log.log(Log.LEVEL_INFO, "Instrumentation", ioe);
            } finally {
                Thread.currentThread().setContextClassLoader(ccl);
            }
            return null;
        }
    });
    // If the load(...) agent call was successful, this variable will no
    // longer be null.
    instr = _getInstrumentation(log, config);
    if (instr == null) {
        try {
            Resource agentJar = createAgentJar(log, config);
            throw new PageRuntimeException(new ApplicationException(Constants.NAME + " was not able to load a Agent dynamically! " + "You need to load one manually by adding the following to your JVM arguments [-javaagent:\"" + (agentJar) + "\"]"));
        } catch (IOException ioe) {
            SystemOut.printDate(ioe);
        }
    }
    return instr;
}
Also used : RefBoolean(lucee.commons.lang.types.RefBoolean) Log(lucee.commons.io.log.Log) Resource(lucee.commons.io.res.Resource) FileResource(lucee.commons.io.res.type.file.FileResource) Instrumentation(java.lang.instrument.Instrumentation) IOException(java.io.IOException) ApplicationException(lucee.runtime.exp.ApplicationException) URLClassLoader(java.net.URLClassLoader) CFMLEngine(lucee.loader.engine.CFMLEngine) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl)

Aggregations

RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)19 RefBoolean (lucee.commons.lang.types.RefBoolean)16 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)4 Expression (lucee.transformer.expression.Expression)4 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)4 IOException (java.io.IOException)3 ParserString (lucee.commons.lang.ParserString)3 PageException (lucee.runtime.exp.PageException)3 Struct (lucee.runtime.type.Struct)3 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 Resource (lucee.commons.io.res.Resource)2 Component (lucee.runtime.Component)2 PageSource (lucee.runtime.PageSource)2 ApplicationException (lucee.runtime.exp.ApplicationException)2 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)2 ApplicationContext (lucee.runtime.listener.ApplicationContext)2 ColumnExpression (lucee.runtime.sql.exp.ColumnExpression)2 Expression (lucee.runtime.sql.exp.Expression)2 ValueString (lucee.runtime.sql.exp.value.ValueString)2