Search in sources :

Example 1 with CFMLExpressionInterpreter

use of lucee.runtime.interpreter.CFMLExpressionInterpreter in project Lucee by lucee.

the class ReqRspUtil method toObject.

public static Object toObject(PageContext pc, byte[] data, int format, Charset charset, Object defaultValue) {
    switch(format) {
        case UDF.RETURN_FORMAT_JSON:
            try {
                return new JSONExpressionInterpreter().interpret(pc, toString(data, charset));
            } catch (PageException pe) {
            }
            break;
        case UDF.RETURN_FORMAT_SERIALIZE:
            try {
                return new CFMLExpressionInterpreter().interpret(pc, toString(data, charset));
            } catch (PageException pe) {
            }
            break;
        case UDF.RETURN_FORMAT_WDDX:
            try {
                WDDXConverter converter = new WDDXConverter(pc.getTimeZone(), false, true);
                converter.setTimeZone(pc.getTimeZone());
                return converter.deserialize(toString(data, charset), false);
            } catch (Exception pe) {
            }
            break;
        case UDF.RETURN_FORMAT_XML:
            try {
                InputSource xml = XMLUtil.toInputSource(pc, toString(data, charset));
                InputSource validator = null;
                return XMLCaster.toXMLStruct(XMLUtil.parse(xml, validator, false), true);
            } catch (Exception pe) {
            }
            break;
        case UDF.RETURN_FORMAT_JAVA:
            try {
                return JavaConverter.deserialize(new ByteArrayInputStream(data));
            } catch (Exception pe) {
            }
            break;
    }
    return defaultValue;
}
Also used : WDDXConverter(lucee.runtime.converter.WDDXConverter) PageException(lucee.runtime.exp.PageException) InputSource(org.xml.sax.InputSource) JSONExpressionInterpreter(lucee.runtime.interpreter.JSONExpressionInterpreter) ByteArrayInputStream(java.io.ByteArrayInputStream) CFMLExpressionInterpreter(lucee.runtime.interpreter.CFMLExpressionInterpreter) PageException(lucee.runtime.exp.PageException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with CFMLExpressionInterpreter

use of lucee.runtime.interpreter.CFMLExpressionInterpreter in project Lucee by lucee.

the class QueryImpl method readExternal.

public void readExternal(ObjectInput in) throws IOException {
    try {
        QueryImpl other = (QueryImpl) new CFMLExpressionInterpreter(false).interpret(ThreadLocalPageContext.get(), in.readUTF());
        this.arrCurrentRow = other.arrCurrentRow;
        this.columncount = other.columncount;
        this.columnNames = other.columnNames;
        this.columns = other.columns;
        this.exeTime = other.exeTime;
        this.generatedKeys = other.generatedKeys;
        this.cacheType = other.cacheType;
        this.name = other.name;
        this.recordcount = other.recordcount;
        this.sql = other.sql;
        this.updateCount = other.updateCount;
    } catch (PageException e) {
        throw new IOException(e.getMessage());
    }
}
Also used : PageException(lucee.runtime.exp.PageException) CFMLExpressionInterpreter(lucee.runtime.interpreter.CFMLExpressionInterpreter) IOException(java.io.IOException)

Example 3 with CFMLExpressionInterpreter

use of lucee.runtime.interpreter.CFMLExpressionInterpreter in project Lucee by lucee.

the class Props method callWDDX.

private void callWDDX(PageContext pc, Component component, Collection.Key methodName, boolean suppressContent) throws PageException {
    try {
        // Struct url = StructUtil.duplicate(pc.urlFormScope(),true);
        Struct url = StructUtil.merge(new Struct[] { pc.formScope(), pc.urlScope() });
        // define args
        url.removeEL(KeyConstants._fieldnames);
        url.removeEL(KeyConstants._method);
        Object args = url.get(KeyConstants._argumentCollection, null);
        String strArgCollFormat = Caster.toString(url.get("argumentCollectionFormat", null), null);
        // url.returnFormat
        int urlReturnFormat = -1;
        Object oReturnFormatFromURL = url.get(KeyConstants._returnFormat, null);
        if (oReturnFormatFromURL != null)
            urlReturnFormat = UDFUtil.toReturnFormat(Caster.toString(oReturnFormatFromURL, null), -1);
        // request header "accept"
        List<MimeType> accept = ReqRspUtil.getAccept(pc);
        int headerReturnFormat = MimeType.toFormat(accept, UDF.RETURN_FORMAT_XML, -1);
        Object queryFormat = url.get(KeyConstants._queryFormat, null);
        if (args == null) {
            args = pc.getHttpServletRequest().getAttribute("argumentCollection");
        }
        if (StringUtil.isEmpty(strArgCollFormat)) {
            strArgCollFormat = Caster.toString(pc.getHttpServletRequest().getAttribute("argumentCollectionFormat"), null);
        }
        // content-type
        Charset cs = getCharset(pc);
        Object o = component.get(pc, methodName, null);
        // onMissingMethod
        if (o == null)
            o = component.get(pc, KeyConstants._onmissingmethod, null);
        Props props = getProps(pc, o, urlReturnFormat, headerReturnFormat);
        // if(!props.output)
        setFormat(pc.getHttpServletResponse(), props.format, cs);
        Object rtn = null;
        try {
            if (suppressContent)
                pc.setSilent();
            if (args == null) {
                url = translate(component, methodName.getString(), url);
                rtn = component.callWithNamedValues(pc, methodName, url);
            } else if (args instanceof String) {
                String str = (String) args;
                int format = UDFUtil.toReturnFormat(strArgCollFormat, -1);
                // CFML
                if (UDF.RETURN_FORMAT_SERIALIZE == format) {
                    // do not catch exception when format is defined
                    args = new CFMLExpressionInterpreter().interpret(pc, str);
                }
                // JSON
                if (UDF.RETURN_FORMAT_JSON == format) {
                    // do not catch exception when format is defined
                    args = new JSONExpressionInterpreter(false).interpret(pc, str);
                } else // default
                {
                    // catch exception when format is not defined, then in this case the string can also be a simple argument
                    try {
                        args = new JSONExpressionInterpreter(false).interpret(pc, str);
                    } catch (PageException pe) {
                        try {
                            args = new CFMLExpressionInterpreter().interpret(pc, str);
                        } catch (PageException _pe) {
                        }
                    }
                }
            }
            // call
            if (args != null) {
                if (Decision.isCastableToStruct(args)) {
                    rtn = component.callWithNamedValues(pc, methodName, Caster.toStruct(args, false));
                } else if (Decision.isCastableToArray(args)) {
                    rtn = component.call(pc, methodName, Caster.toNativeArray(args));
                } else {
                    Object[] ac = new Object[1];
                    ac[0] = args;
                    rtn = component.call(pc, methodName, ac);
                }
            }
        } finally {
            if (suppressContent)
                pc.unsetSilent();
        }
        // convert result
        if (rtn != null) {
            if (pc.getHttpServletRequest().getHeader("AMF-Forward") != null) {
                pc.variablesScope().setEL("AMF-Forward", rtn);
            } else {
                _writeOut(pc, props, queryFormat, rtn, cs, false);
            }
        }
    } catch (Throwable t) {
        PageException pe = Caster.toPageException(t);
        pe.setExposeMessage(true);
        throw pe;
    }
}
Also used : PageException(lucee.runtime.exp.PageException) JSONExpressionInterpreter(lucee.runtime.interpreter.JSONExpressionInterpreter) Charset(java.nio.charset.Charset) CFMLExpressionInterpreter(lucee.runtime.interpreter.CFMLExpressionInterpreter) MimeType(lucee.commons.lang.mimetype.MimeType) StaticStruct(lucee.runtime.component.StaticStruct) Struct(lucee.runtime.type.Struct)

Example 4 with CFMLExpressionInterpreter

use of lucee.runtime.interpreter.CFMLExpressionInterpreter in project Lucee by lucee.

the class AxisCaster method _initPojo.

private static void _initPojo(PageContext pc, TypeEntry typeEntry, QName type, Pojo pojo, Property[] props, Struct sct, Component comp, TypeMapping tm, Set<Object> done) throws PageException {
    Property p;
    Object v;
    Collection.Key k;
    CFMLExpressionInterpreter interpreter = new CFMLExpressionInterpreter(false);
    for (int i = 0; i < props.length; i++) {
        p = props[i];
        k = Caster.toKey(p.getName());
        // value
        v = sct.get(k, null);
        if (v == null && comp != null)
            v = comp.get(k, null);
        if (v != null)
            v = Caster.castTo(pc, p.getType(), v, false);
        else {
            if (!StringUtil.isEmpty(p.getDefault())) {
                try {
                    v = Caster.castTo(pc, p.getType(), p.getDefault(), false);
                } catch (PageException pe) {
                    try {
                        v = interpreter.interpret(pc, p.getDefault());
                        v = Caster.castTo(pc, p.getType(), v, false);
                    } catch (PageException pe2) {
                        throw new ExpressionException("can not use default value [" + p.getDefault() + "] for property [" + p.getName() + "] with type [" + p.getType() + "]");
                    }
                }
            }
        }
        // set or throw
        if (v == null) {
            if (p.isRequired())
                throw new ExpressionException("required property [" + p.getName() + "] is not defined");
        } else {
            TypeEntry childTE = null;
            QName childT = null;
            if (typeEntry != null) {
                childTE = AxisUtil.getContainedElement(typeEntry, p.getName(), null);
                if (childTE != null)
                    childT = childTE.getQName();
            }
            Reflector.callSetter(pojo, p.getName().toLowerCase(), _toAxisType(tm, null, childTE, childT, null, v, done));
        }
    }
}
Also used : Key(lucee.runtime.type.Collection.Key) PageException(lucee.runtime.exp.PageException) QName(javax.xml.namespace.QName) Collection(lucee.runtime.type.Collection) CFMLExpressionInterpreter(lucee.runtime.interpreter.CFMLExpressionInterpreter) Property(lucee.runtime.component.Property) ExpressionException(lucee.runtime.exp.ExpressionException) TypeEntry(org.apache.axis.wsdl.symbolTable.TypeEntry)

Aggregations

PageException (lucee.runtime.exp.PageException)4 CFMLExpressionInterpreter (lucee.runtime.interpreter.CFMLExpressionInterpreter)4 JSONExpressionInterpreter (lucee.runtime.interpreter.JSONExpressionInterpreter)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Charset (java.nio.charset.Charset)1 QName (javax.xml.namespace.QName)1 MimeType (lucee.commons.lang.mimetype.MimeType)1 Property (lucee.runtime.component.Property)1 StaticStruct (lucee.runtime.component.StaticStruct)1 WDDXConverter (lucee.runtime.converter.WDDXConverter)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 Collection (lucee.runtime.type.Collection)1 Key (lucee.runtime.type.Collection.Key)1 Struct (lucee.runtime.type.Struct)1 TypeEntry (org.apache.axis.wsdl.symbolTable.TypeEntry)1 InputSource (org.xml.sax.InputSource)1