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;
}
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);
}
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;
}
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);
}
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);
}
Aggregations