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