use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class ResourceUtil method toResourceExistingParent.
public static Resource toResourceExistingParent(PageContext pc, String destination, boolean allowRealpath) throws ExpressionException {
destination = destination.replace('\\', '/');
Resource res = pc.getConfig().getResource(destination);
// not allow realpath
if (!allowRealpath) {
if (res.exists() || parentExists(res))
return res;
throw new ExpressionException("parent directory " + res.getParent() + " for file " + destination + " doesn't exist");
}
// allow realpath
if (res.isAbsolute() && (res.exists() || parentExists(res))) {
return res;
}
if (StringUtil.startsWith(destination, '/')) {
PageContextImpl pci = (PageContextImpl) pc;
ConfigWebImpl cwi = (ConfigWebImpl) pc.getConfig();
PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), destination, false, pci.useSpecialMappings(), true);
// Resource[] reses = cwi.getPhysicalResourcesX(pc,pc.getApplicationContext().getMappings(),destination,false,pci.useSpecialMappings(),true);
if (!ArrayUtil.isEmpty(sources)) {
for (int i = 0; i < sources.length; i++) {
if (sources[i].exists() || parentExists(sources[i])) {
res = sources[i].getResource();
if (res != null)
return res;
}
}
}
}
res = getRealResource(pc, destination, res);
if (res != null && (res.exists() || parentExists(res)))
return res;
throw new ExpressionException("parent directory " + res.getParent() + " for file " + destination + " doesn't exist");
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class ClusterWrap method set.
@Override
public Object set(Key key, Object value) throws PageException {
if (!core.checkValue(value))
throw new ExpressionException("object from type [" + Caster.toTypeName(value) + "] are not allowed in cluster scope");
ClusterEntry entry;
core.addEntry(entry = new ClusterEntryImpl(key, (Serializable) value, offset));
super.setEL(key, entry);
return value;
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class UndefinedImpl method get.
@Override
public Object get(Collection.Key key) throws PageException {
// print.e();
Object rtn;
if (checkArguments) {
rtn = local.get(key, NullSupportHelper.NULL());
if (rtn != NullSupportHelper.NULL())
return rtn;
rtn = argument.getFunctionArgument(key, NullSupportHelper.NULL());
if (rtn != NullSupportHelper.NULL()) {
if (debug)
debugCascadedAccess(pc, argument.getTypeAsString(), key);
return rtn;
}
}
// get data from queries
if (allowImplicidQueryCall && pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML && !qryStack.isEmpty()) {
rtn = qryStack.getDataFromACollection(pc, key, NullSupportHelper.NULL());
if (rtn != NullSupportHelper.NULL()) {
if (debug)
debugCascadedAccess(pc, "query", key);
if (!NullSupportHelper.full() && rtn == null)
return "";
return rtn;
}
}
// variable
rtn = variable.get(key, NullSupportHelper.NULL());
if (rtn != NullSupportHelper.NULL()) {
if (debug && checkArguments)
debugCascadedAccess(pc, variable, rtn, key);
return rtn;
}
// thread scopes
if (pc.hasFamily()) {
// ThreadTag.getThreadScope(pc, key, ThreadTag.LEVEL_CURRENT+ThreadTag.LEVEL_KIDS);
rtn = pc.getThreadScope(key, NullSupportHelper.NULL());
if (rtn != NullSupportHelper.NULL()) {
if (debug)
debugCascadedAccess(pc, "thread", key);
return rtn;
}
}
// get a scope value (only CFML is searching additional scopes)
if (pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML) {
for (int i = 0; i < scopes.length; i++) {
rtn = scopes[i].get(key, NullSupportHelper.NULL());
if (rtn != NullSupportHelper.NULL()) {
if (debug)
debugCascadedAccess(pc, scopes[i].getTypeAsString(), key);
return rtn;
}
}
}
if (pc.getConfig().debug())
throw new ExpressionException(ExceptionUtil.similarKeyMessage(this, key.getString(), "key", "keys", null, false));
throw new ExpressionException("variable [" + key.getString() + "] doesn't exist");
}
use of lucee.runtime.exp.ExpressionException 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.ExpressionException in project Lucee by lucee.
the class ArrayUtil method sum.
/**
* sum of all values of a array, only work when all values are numeric
* @param array Array
* @return sum of all values
* @throws ExpressionException
*/
public static double sum(Array array) throws ExpressionException {
if (array.getDimension() > 1)
throw new ExpressionException("can only get sum/avg from 1 dimensional arrays");
double rtn = 0;
int len = array.size();
// try {
for (int i = 1; i <= len; i++) {
rtn += _toDoubleValue(array, i);
}
/*}
catch (PageException e) {
throw new ExpressionException("exception while execute array operation: "+e.getMessage());
}*/
return rtn;
}
Aggregations