use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class GetFunctionData method cfmlBasedFunction.
private static Struct cfmlBasedFunction(PageContext pc, FunctionLibFunction function) throws PageException {
Struct sct = new StructImpl();
ArrayList<FunctionLibFunctionArg> args = function.getArg();
String filename = Caster.toString(args.get(0).getDefaultValue());
Key name = KeyImpl.toKey(args.get(1).getDefaultValue());
boolean isWeb = Caster.toBooleanValue(args.get(2).getDefaultValue());
UDF udf = CFFunction.loadUDF(pc, filename, name, isWeb);
sct.set(KeyConstants._name, function.getName());
sct.set(ARGUMENT_TYPE, "fixed");
sct.set(KeyConstants._description, StringUtil.emptyIfNull(udf.getHint()));
sct.set(RETURN_TYPE, StringUtil.emptyIfNull(udf.getReturnTypeAsString()));
sct.set(KeyConstants._type, "cfml");
sct.set(SOURCE, udf.getSource());
sct.set(KeyConstants._status, "implemeted");
FunctionArgument[] fas = udf.getFunctionArguments();
Array _args = new ArrayImpl();
sct.set(KeyConstants._arguments, _args);
int min = 0, max = 0;
for (int i = 0; i < fas.length; i++) {
FunctionArgument fa = fas[i];
Struct meta = fa.getMetaData();
Struct _arg = new StructImpl();
if (fa.isRequired())
min++;
max++;
_arg.set(KeyConstants._required, fa.isRequired() ? Boolean.TRUE : Boolean.FALSE);
_arg.set(KeyConstants._type, StringUtil.emptyIfNull(fa.getTypeAsString()));
_arg.set(KeyConstants._name, StringUtil.emptyIfNull(fa.getName()));
_arg.set(KeyConstants._description, StringUtil.emptyIfNull(fa.getHint()));
String status;
if (meta == null)
status = "implemeted";
else
status = TagLibFactory.toStatus(TagLibFactory.toStatus(Caster.toString(meta.get(KeyConstants._status, "implemeted"))));
_arg.set(KeyConstants._status, status);
_args.append(_arg);
}
sct.set(ARG_MIN, Caster.toDouble(min));
sct.set(ARG_MAX, Caster.toDouble(max));
return sct;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class QueryColumnData method call.
public static Array call(PageContext pc, Query query, String columnName, UDF udf) throws PageException {
Array arr = new ArrayImpl();
QueryColumn column = query.getColumn(KeyImpl.init(columnName));
Iterator<Object> it = column.valueIterator();
Object value;
short type = SQLCaster.toCFType(column.getType(), lucee.commons.lang.CFTypes.TYPE_UNDEFINED);
while (it.hasNext()) {
value = it.next();
if (!NullSupportHelper.full(pc) && value == null)
value = "";
// callback call
if (udf != null)
value = udf.call(pc, new Object[] { value }, true);
// convert (if necessary)
value = Caster.castTo(pc, type, column.getTypeAsString(), value, value);
arr.append(value);
}
return arr;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class QueryDeleteColumn method toArray.
public static Array toArray(QueryColumn column) throws PageException {
Array clone = new ArrayImpl();
int len = column.size();
clone.resize(len);
for (int i = 1; i <= len; i++) {
clone.setE(i, QueryUtil.getValue(column, i));
}
return clone;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class QuerySetColumn method call.
public static String call(PageContext pc, Query query, String columnName, String newColumnName) throws PageException {
columnName = columnName.trim();
newColumnName = newColumnName.trim();
Collection.Key src = KeyImpl.getInstance(columnName);
Collection.Key trg = KeyImpl.getInstance(newColumnName);
Query qp = Caster.toQuery(query, null);
if (qp != null)
qp.rename(src, trg);
else {
QueryColumn qc = query.removeColumn(src);
Array content = new ArrayImpl();
int len = qc.size();
for (int i = 1; i <= len; i++) {
content.setE(i, qc.get(i, null));
}
query.addColumn(trg, content, qc.getType());
}
return null;
}
use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.
the class ValueArray method call.
public static Array call(PageContext pc, QueryColumn column) throws PageException {
Array arr = new ArrayImpl();
int size = column.size();
Object obj;
short type = SQLCaster.toCFType(column.getType(), lucee.commons.lang.CFTypes.TYPE_UNDEFINED);
for (int i = 1; i <= size; i++) {
obj = column.get(i, null);
try {
obj = Caster.castTo(pc, type, column.getTypeAsString(), obj);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
arr.append(obj);
}
return arr;
}
Aggregations