use of lucee.runtime.converter.XMLConverter 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);
}
use of lucee.runtime.converter.XMLConverter in project Lucee by lucee.
the class Props method callCFCMetaData.
private void callCFCMetaData(PageContext pc, Component cfc, int format) throws IOException, PageException, ConverterException {
ComponentSpecificAccess cw = new ComponentSpecificAccess(Component.ACCESS_REMOTE, cfc);
ComponentScope scope = cw.getComponentScope();
Struct udfs = new StructImpl(), sctUDF, sctArg;
Array arrArg;
Iterator<Object> it = scope.valueIterator();
Object v;
UDF udf;
FunctionArgument[] args;
while (it.hasNext()) {
v = it.next();
// UDF
if (v instanceof UDF) {
udf = (UDF) v;
sctUDF = new StructImpl();
arrArg = new ArrayImpl();
udfs.setEL(udf.getFunctionName(), sctUDF);
args = udf.getFunctionArguments();
for (int i = 0; i < args.length; i++) {
sctArg = new StructImpl();
arrArg.appendEL(sctArg);
sctArg.setEL(KeyConstants._name, args[i].getName().getString());
sctArg.setEL(KeyConstants._type, args[i].getTypeAsString());
sctArg.setEL(KeyConstants._required, args[i].isRequired());
if (!StringUtil.isEmpty(args[i].getHint()))
sctArg.setEL(KeyConstants._hint, args[i].getHint());
}
sctUDF.set(KeyConstants._arguments, arrArg);
sctUDF.set(KeyConstants._returntype, udf.getReturnTypeAsString());
}
}
Struct rtn = new StructImpl();
rtn.set(KeyConstants._functions, udfs);
rtn.set(ACCEPT_ARG_COLL_FORMATS, "cfml,json");
InputStream is;
Charset cs = null;
// WDDX
if (UDF.RETURN_FORMAT_WDDX == format) {
WDDXConverter converter = new WDDXConverter(pc.getTimeZone(), false, false);
converter.setTimeZone(pc.getTimeZone());
String str = converter.serialize(rtn);
cs = getCharset(pc);
is = new ByteArrayInputStream(str.getBytes(cs));
} else // JSON
if (UDF.RETURN_FORMAT_JSON == format) {
boolean byColumn = false;
cs = getCharset(pc);
JSONConverter converter = new JSONConverter(false, cs);
String str = converter.serialize(pc, rtn, byColumn);
is = new ByteArrayInputStream(str.getBytes(cs));
} else // CFML
if (UDF.RETURN_FORMAT_SERIALIZE == format) {
ScriptConverter converter = new ScriptConverter(false);
String str = converter.serialize(rtn);
cs = getCharset(pc);
is = new ByteArrayInputStream(str.getBytes(cs));
} else // XML
if (UDF.RETURN_FORMAT_XML == format) {
XMLConverter converter = new XMLConverter(pc.getTimeZone(), false);
converter.setTimeZone(pc.getTimeZone());
String str = converter.serialize(rtn);
cs = getCharset(pc);
is = new ByteArrayInputStream(str.getBytes(cs));
} else // Plain
if (UDF.RETURN_FORMAT_PLAIN == format) {
String str = Caster.toString(rtn);
cs = getCharset(pc);
is = new ByteArrayInputStream(str.getBytes(cs));
} else // Java
if (UDF.RETURN_FORMAT_JAVA == format) {
byte[] bytes = JavaConverter.serializeAsBinary(rtn);
is = new ByteArrayInputStream(bytes);
} else
throw new IOException("invalid format defintion:" + format);
OutputStream os = null;
try {
os = pc.getResponseStream();
setFormat(pc.getHttpServletResponse(), format, cs);
IOUtil.copy(is, os, false, false);
} finally {
IOUtil.flushEL(os);
IOUtil.closeEL(os);
((PageContextImpl) pc).getRootOut().setClosed(true);
}
}
Aggregations