use of lucee.runtime.converter.JSONConverter in project Lucee by lucee.
the class CallStackGet method call.
public static Object call(PageContext pc, String type) throws PageException {
Array arr = (Array) call(pc);
if (type.equalsIgnoreCase("array"))
return arr;
if (type.equalsIgnoreCase("json")) {
try {
return new JSONConverter(true, null).serialize(pc, arr, false);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw Caster.toPageException(t);
}
}
StringBuilder sb = new StringBuilder(64 * arr.size());
Struct struct;
String func;
Iterator it = arr.valueIterator();
if (type.equalsIgnoreCase("text") || type.equalsIgnoreCase("string")) {
while (it.hasNext()) {
struct = (Struct) it.next();
sb.append((String) struct.get(KeyConstants._template));
func = (String) struct.get(KeyConstants._function);
if (!func.isEmpty()) {
sb.append('.').append(func).append("()");
}
sb.append(':').append(((Double) struct.get(LINE_NUMBER)).intValue());
if (it.hasNext())
sb.append("; ");
}
return sb.toString();
}
if (type.equalsIgnoreCase("html")) {
sb.append("<ul class='-lucee-array'>");
while (it.hasNext()) {
struct = (Struct) it.next();
sb.append("<li>");
sb.append((String) struct.get(KeyConstants._template));
func = (String) struct.get(KeyConstants._function);
if (!func.isEmpty()) {
sb.append('.').append(func).append("()");
}
sb.append(':').append(((Double) struct.get(LINE_NUMBER)).intValue());
sb.append("</li>");
}
sb.append("</ul>");
return sb.toString();
}
throw new FunctionException(pc, CallStackGet.class.getSimpleName(), 1, "type", "Argument type [" + type + "] is not valid. Valid types are: [array], text, html, json.");
}
Aggregations