Search in sources :

Example 1 with JavaConverter

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

IOException (java.io.IOException)1 JSONConverter (lucee.runtime.converter.JSONConverter)1 JavaConverter (lucee.runtime.converter.JavaConverter)1 ScriptConverter (lucee.runtime.converter.ScriptConverter)1 WDDXConverter (lucee.runtime.converter.WDDXConverter)1 XMLConverter (lucee.runtime.converter.XMLConverter)1 ApplicationException (lucee.runtime.exp.ApplicationException)1