use of lucee.runtime.type.Array in project Lucee by lucee.
the class ModernApplicationContext method initJava.
private void initJava() {
if (!initJavaSettings) {
Object o = get(component, JAVA_SETTING, null);
if (o != null && Decision.isStruct(o)) {
Struct sct = Caster.toStruct(o, null);
// loadPaths
Object obj = sct.get(KeyImpl.init("loadPaths"), null);
List<Resource> paths;
if (obj != null) {
paths = loadPaths(ThreadLocalPageContext.get(), obj);
} else
paths = new ArrayList<Resource>();
// loadCFMLClassPath
Boolean loadCFMLClassPath = Caster.toBoolean(sct.get(KeyImpl.init("loadCFMLClassPath"), null), null);
if (loadCFMLClassPath == null)
loadCFMLClassPath = Caster.toBoolean(sct.get(KeyImpl.init("loadColdFusionClassPath"), null), null);
if (loadCFMLClassPath == null)
loadCFMLClassPath = javaSettings.loadCFMLClassPath();
// reloadOnChange
boolean reloadOnChange = Caster.toBooleanValue(sct.get(KeyImpl.init("reloadOnChange"), null), javaSettings.reloadOnChange());
// watchInterval
int watchInterval = Caster.toIntValue(sct.get(KeyImpl.init("watchInterval"), null), javaSettings.watchInterval());
// watchExtensions
obj = sct.get(KeyImpl.init("watchExtensions"), null);
List<String> extensions = new ArrayList<String>();
if (obj != null) {
Array arr;
if (Decision.isArray(obj)) {
try {
arr = Caster.toArray(obj);
} catch (PageException e) {
arr = new ArrayImpl();
}
} else {
arr = lucee.runtime.type.util.ListUtil.listToArrayRemoveEmpty(Caster.toString(obj, ""), ',');
}
Iterator<Object> it = arr.valueIterator();
String ext;
while (it.hasNext()) {
ext = Caster.toString(it.next(), null);
if (StringUtil.isEmpty(ext))
continue;
ext = ext.trim();
if (ext.startsWith("."))
ext = ext.substring(1);
if (ext.startsWith("*."))
ext = ext.substring(2);
extensions.add(ext);
}
}
javaSettings = new JavaSettingsImpl(paths.toArray(new Resource[paths.size()]), loadCFMLClassPath, reloadOnChange, watchInterval, extensions.toArray(new String[extensions.size()]));
}
initJavaSettings = true;
}
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class ModernApplicationContext method loadPaths.
public static java.util.List<Resource> loadPaths(PageContext pc, Object obj) {
Resource res;
if (!Decision.isArray(obj)) {
String list = Caster.toString(obj, null);
if (!StringUtil.isEmpty(list)) {
obj = ListUtil.listToArray(list, ',');
}
}
if (Decision.isArray(obj)) {
Array arr = Caster.toArray(obj, null);
java.util.List<Resource> list = new ArrayList<Resource>();
Iterator<Object> it = arr.valueIterator();
while (it.hasNext()) {
try {
String path = Caster.toString(it.next(), null);
if (path == null)
continue;
// print.e("--------------------------------------------------");
// print.e(path);
res = ORMConfigurationImpl.toResourceExisting(pc.getConfig(), pc.getApplicationContext(), path, false);
// print.e(res+"->"+(res!=null && res.exists()));
if (res == null || !res.exists())
res = ResourceUtil.toResourceExisting(pc, path, true, null);
// print.e(res+"->"+(res!=null && res.exists()));
if (res != null)
list.add(res);
} catch (Exception e) {
SystemOut.printDate(e);
}
}
return list;
}
return null;
}
use of lucee.runtime.type.Array 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.Array 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.Array 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;
}
Aggregations