use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class ArrayUtil method min.
/**
* the smallest value, of all values inside the array, only work when all values are numeric
* @param array
* @return the smallest value
* @throws PageException
*/
public static double min(Array array) throws PageException {
if (array.getDimension() > 1)
throw new ExpressionException("can only get max value from 1 dimensional arrays");
if (array.size() == 0)
return 0;
double rtn = _toDoubleValue(array, 1);
int len = array.size();
try {
for (int i = 2; i <= len; i++) {
double v = _toDoubleValue(array, i);
if (rtn > v)
rtn = v;
}
} catch (PageException e) {
throw new ExpressionException("exception while execute array operation: " + e.getMessage());
}
return rtn;
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class ComponentUtil method _getComponentPropertiesClass.
private static Class _getComponentPropertiesClass(PageContext pc, Config secondChanceConfig, String className, ASMProperty[] properties, Class extendsClass) throws PageException, IOException, ClassNotFoundException {
String real = className.replace('.', '/');
PhysicalClassLoader cl;
if (pc == null)
cl = (PhysicalClassLoader) secondChanceConfig.getRPCClassLoader(false);
else
cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(false);
Resource rootDir = cl.getDirectory();
Resource classFile = rootDir.getRealResource(real.concat(".class"));
if (classFile.exists()) {
try {
Class clazz = cl.loadClass(className);
Field field = clazz.getField("_md5_");
if (ASMUtil.createMD5(properties).equals(field.get(null))) {
// if(equalInterface(properties,clazz)) {
return clazz;
}
} catch (Exception e) {
}
}
// create file
if (extendsClass == null)
extendsClass = Object.class;
byte[] barr = ASMUtil.createPojo(real, properties, extendsClass, new Class[] { Pojo.class }, null);
boolean exist = classFile.exists();
ResourceUtil.touch(classFile);
IOUtil.copy(new ByteArrayInputStream(barr), classFile, true);
if (pc == null)
cl = (PhysicalClassLoader) secondChanceConfig.getRPCClassLoader(exist);
else
cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(exist);
return cl.loadClass(className);
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class ListUtil method listToArray.
/**
* casts a list to Array object
* @param list list to cast
* @param delimiter delimter of the list
* @return Array Object
*/
public static Array listToArray(String list, char delimiter) {
if (list.length() == 0)
return new ArrayImpl();
int len = list.length();
int last = 0;
Array array = new ArrayImpl();
try {
for (int i = 0; i < len; i++) {
if (list.charAt(i) == delimiter) {
array.append(list.substring(last, i));
last = i + 1;
}
}
if (last <= len)
array.append(list.substring(last));
} catch (PageException e) {
}
return array;
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class QueryUtil method duplicate2QueryColumnImpl.
public static QueryColumnImpl duplicate2QueryColumnImpl(QueryImpl targetQuery, QueryColumn col, boolean deepCopy) {
if (col instanceof QueryColumnImpl)
return ((QueryColumnImpl) col).cloneColumnImpl(deepCopy);
// fill array for column
Array content = new ArrayImpl();
int len = col.size();
for (int i = 1; i <= len; i++) {
content.setEL(i, col.get(i, null));
}
// create and return column
try {
return new QueryColumnImpl(targetQuery, col.getKey(), content, col.getType());
} catch (PageException e) {
throw new PageRuntimeException(e);
}
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class UDFUtil method toDumpData.
public static DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp, UDF udf, short type) {
if (!dp.getShowUDFs()) {
if (TYPE_UDF == type)
return new SimpleDumpData("<UDF>");
if (TYPE_BIF == type)
return new SimpleDumpData("<BIF>");
if (TYPE_CLOSURE == type)
return new SimpleDumpData("<Closure>");
if (TYPE_LAMBDA == type)
return new SimpleDumpData("<Lambda>");
}
// arguments
FunctionArgument[] args = udf.getFunctionArguments();
DumpTable atts;
if (TYPE_UDF == type)
atts = new DumpTable("udf", "#ca5095", "#e9accc", "#000000");
else if (TYPE_CLOSURE == type)
atts = new DumpTable("udf", "#9cb770", "#c7e1ba", "#000000");
else if (TYPE_BIF == type)
atts = new DumpTable("udf", "#e1c039", "#f1e2a3", "#000000");
else
atts = new DumpTable("udf", "#f3d5bd", "#f6e4cc", "#000000");
atts.appendRow(new DumpRow(63, new DumpData[] { new SimpleDumpData("label"), new SimpleDumpData("name"), new SimpleDumpData("required"), new SimpleDumpData("type"), new SimpleDumpData("default"), new SimpleDumpData("hint") }));
for (int i = 0; i < args.length; i++) {
FunctionArgument arg = args[i];
DumpData def;
try {
Object oa = udf.getDefaultValue(pageContext, i, null);
if (oa == null)
oa = "null";
def = new SimpleDumpData(Caster.toString(oa));
} catch (PageException e) {
def = new SimpleDumpData("");
}
atts.appendRow(new DumpRow(0, new DumpData[] { new SimpleDumpData(arg.getDisplayName()), new SimpleDumpData(arg.getName().getString()), new SimpleDumpData(arg.isRequired()), new SimpleDumpData(arg.getTypeAsString()), def, new SimpleDumpData(arg.getHint()) }));
// atts.setRow(0,arg.getHint());
}
DumpTable func;
String label = udf.getDisplayName();
if (TYPE_CLOSURE == type) {
func = new DumpTable("#9cb770", "#c7e1ba", "#000000");
func.setTitle(StringUtil.isEmpty(label) ? "Closure" : "Closure " + label);
} else if (TYPE_UDF == type) {
func = new DumpTable("#ca5095", "#e9accc", "#000000");
String f = "Function ";
try {
f = StringUtil.ucFirst(ComponentUtil.toStringAccess(udf.getAccess()).toLowerCase()) + " " + f;
} catch (ApplicationException e) {
}
f += udf.getFunctionName();
if (udf instanceof UDFGSProperty)
f += " (generated)";
func.setTitle(f);
} else if (TYPE_BIF == type) {
String f = "Build in Function " + (!StringUtil.isEmpty(label) ? label : udf.getFunctionName());
func = new DumpTable("#e1c039", "#f1e2a3", "#000000");
func.setTitle(f);
} else {
func = new DumpTable("#f3d5bd", "#f6e4cc", "#000000");
func.setTitle(StringUtil.isEmpty(label) ? "Lambda" : "Lambda " + label);
}
// Source
String src = udf.getSource();
if (!StringUtil.isEmpty(src))
func.setComment("source:" + src);
String hint = udf.getHint();
String desc = udf.getDescription();
if (!StringUtil.isEmpty(desc))
addComment(func, desc);
if (!StringUtil.isEmpty(hint))
addComment(func, hint);
if (Component.MODIFIER_NONE != udf.getModifier())
func.appendRow(1, new SimpleDumpData("modifier"), new SimpleDumpData(ComponentUtil.toModifier(udf.getModifier(), "")));
func.appendRow(1, new SimpleDumpData("arguments"), atts);
func.appendRow(1, new SimpleDumpData("return type"), new SimpleDumpData(udf.getReturnTypeAsString()));
return func;
}
Aggregations