Search in sources :

Example 1 with WDDXConverter

use of lucee.runtime.converter.WDDXConverter 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 WDDXConverter

use of lucee.runtime.converter.WDDXConverter in project Lucee by lucee.

the class Wddx method wddx2cfml.

private Object wddx2cfml(String input) throws ConverterException, IOException, FactoryConfigurationError {
    WDDXConverter converter = new WDDXConverter(pageContext.getTimeZone(), xmlConform, true);
    converter.setTimeZone(pageContext.getTimeZone());
    return converter.deserialize(input, validate);
}
Also used : WDDXConverter(lucee.runtime.converter.WDDXConverter)

Example 3 with WDDXConverter

use of lucee.runtime.converter.WDDXConverter in project Lucee by lucee.

the class Decision method isWddx.

/**
 * tests if object is a WDDX Object
 * @param o Object to check
 * @return boolean
 */
public static boolean isWddx(Object o) {
    if (!(o instanceof String))
        return false;
    String str = o.toString();
    if (!(str.indexOf("wddxPacket") > 0))
        return false;
    // wrong timezone but this isent importend because date will not be used
    WDDXConverter converter = new WDDXConverter(TimeZone.getDefault(), false, true);
    try {
        converter.deserialize(Caster.toString(o), true);
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : WDDXConverter(lucee.runtime.converter.WDDXConverter) PageException(lucee.runtime.exp.PageException) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 4 with WDDXConverter

use of lucee.runtime.converter.WDDXConverter in project Lucee by lucee.

the class XMLConfigAdmin method storageGet.

public Object storageGet(Config config, String key) throws ConverterException, IOException, SecurityException {
    checkReadAccess();
    Resource storageDir = getStoragDir(config);
    Resource storage = storageDir.getRealResource(key + ".wddx");
    if (!storage.exists())
        throw new IOException("there is no storage with name " + key);
    WDDXConverter converter = new WDDXConverter(config.getTimeZone(), true, true);
    return converter.deserialize(IOUtil.toString(storage, "UTF-8"), true);
}
Also used : WDDXConverter(lucee.runtime.converter.WDDXConverter) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException)

Example 5 with WDDXConverter

use of lucee.runtime.converter.WDDXConverter in project Lucee by lucee.

the class Props method _writeOut.

private static void _writeOut(PageContext pc, Props props, Object queryFormat, Object rtn, Charset cs, boolean setFormat) throws ConverterException, PageException, IOException {
    // return type XML ignore WDDX
    if (props.type == CFTypes.TYPE_XML) {
        // if(UDF.RETURN_FORMAT_WDDX==format) format=UDF.RETURN_FORMAT_PLAIN;
        rtn = Caster.toString(Caster.toXML(rtn));
    } else
        // function does no real cast, only check it
        rtn = Caster.castTo(pc, (short) props.type, props.strType, rtn);
    if (setFormat)
        setFormat(pc.getHttpServletResponse(), props.format, cs);
    // WDDX
    if (UDF.RETURN_FORMAT_WDDX == props.format) {
        WDDXConverter converter = new WDDXConverter(pc.getTimeZone(), false, false);
        converter.setTimeZone(pc.getTimeZone());
        pc.forceWrite(converter.serialize(rtn));
    } else // JSON
    if (UDF.RETURN_FORMAT_JSON == props.format) {
        boolean byColumn = false;
        if (queryFormat instanceof String) {
            String strQF = ((String) queryFormat).trim();
            if (strQF.equalsIgnoreCase("row"))
                ;
            else if (strQF.equalsIgnoreCase("column"))
                byColumn = true;
            else
                throw new ApplicationException("invalid queryformat definition [" + strQF + "], valid formats are [row,column]");
        }
        JSONConverter converter = new JSONConverter(false, cs);
        String prefix = "";
        if (props.secureJson) {
            prefix = pc.getApplicationContext().getSecureJsonPrefix();
            if (prefix == null)
                prefix = "";
        }
        pc.forceWrite(prefix + converter.serialize(pc, rtn, byColumn));
    } else // CFML
    if (UDF.RETURN_FORMAT_SERIALIZE == props.format) {
        ScriptConverter converter = new ScriptConverter(false);
        pc.forceWrite(converter.serialize(rtn));
    } else // XML
    if (UDF.RETURN_FORMAT_XML == props.format) {
        XMLConverter converter = new XMLConverter(pc.getTimeZone(), false);
        converter.setTimeZone(pc.getTimeZone());
        pc.forceWrite(converter.serialize(rtn));
    } else // Plain
    if (UDF.RETURN_FORMAT_PLAIN == props.format) {
        pc.forceWrite(Caster.toString(rtn));
    } else // JAVA
    if (UDF.RETURN_FORMAT_JAVA == props.format) {
        writeOut(pc, rtn, MimeType.APPLICATION_JAVA, new JavaConverter());
    } else
        throw new IOException("invalid return format defintion:" + props.format);
}
Also used : WDDXConverter(lucee.runtime.converter.WDDXConverter) ApplicationException(lucee.runtime.exp.ApplicationException) ScriptConverter(lucee.runtime.converter.ScriptConverter) XMLConverter(lucee.runtime.converter.XMLConverter) JavaConverter(lucee.runtime.converter.JavaConverter) IOException(java.io.IOException) JSONConverter(lucee.runtime.converter.JSONConverter)

Aggregations

WDDXConverter (lucee.runtime.converter.WDDXConverter)8 IOException (java.io.IOException)3 Resource (lucee.commons.io.res.Resource)3 PageException (lucee.runtime.exp.PageException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Charset (java.nio.charset.Charset)2 JSONConverter (lucee.runtime.converter.JSONConverter)2 ScriptConverter (lucee.runtime.converter.ScriptConverter)2 XMLConverter (lucee.runtime.converter.XMLConverter)2 Array (lucee.runtime.type.Array)2 Struct (lucee.runtime.type.Struct)2 StructImpl (lucee.runtime.type.StructImpl)2 File (java.io.File)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Constructor (java.lang.reflect.Constructor)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ResultSet (java.sql.ResultSet)1