use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class CFImportTag method initFile.
@Override
public void initFile() throws PageException {
ConfigWeb config = pageContext.getConfig();
// = appendix+'.'+config.getCFMLExtension();
String[] filenames = CustomTagUtil.getFileNames(config, getAppendix());
String strRealPathes = attributesScope.remove("__custom_tag_path").toString();
String[] realPathes = ListUtil.listToStringArray(strRealPathes, File.pathSeparatorChar);
for (int i = 0; i < realPathes.length; i++) {
if (!StringUtil.endsWith(realPathes[i], '/'))
realPathes[i] = realPathes[i] + "/";
}
// MUSTMUST use cache like regular ct
// page source
PageSource ps;
for (int rp = 0; rp < realPathes.length; rp++) {
for (int fn = 0; fn < filenames.length; fn++) {
ps = ((PageContextImpl) pageContext).getRelativePageSourceExisting(realPathes[rp] + filenames[fn]);
if (ps != null) {
source = new InitFile(pageContext, ps, filenames[fn]);
return;
}
}
}
// EXCEPTION
// message
StringBuffer msg = new StringBuffer("could not find template [");
msg.append(CustomTagUtil.getDisplayName(config, getAppendix()));
msg.append("] in the following directories [");
msg.append(strRealPathes.replace(File.pathSeparatorChar, ','));
msg.append(']');
throw new ExpressionException(msg.toString());
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class Cookie method doStartTag.
@Override
public int doStartTag() throws PageException {
Key key = KeyImpl.getInstance(name);
String appName = Login.getApplicationName(pageContext.getApplicationContext());
boolean isAppName = false;
if (KeyConstants._CFID.equalsIgnoreCase(key) || KeyConstants._CFTOKEN.equalsIgnoreCase(key) || (isAppName = key.equals(appName))) {
ApplicationContext ac = pageContext.getApplicationContext();
if (ac instanceof ApplicationContextSupport) {
ApplicationContextSupport acs = (ApplicationContextSupport) ac;
CookieData data = isAppName ? acs.getAuthCookie() : acs.getSessionCookie();
if (data != null && data.isDisableUpdate())
throw new ExpressionException("customize " + key + " is disabled!");
}
}
pageContext.cookieScope().setCookie(key, value, expires, secure, path, domain, httponly, preservecase, encode);
return SKIP_BODY;
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class ArrayUtil method swap.
/**
* swap to values of the array
* @param array
* @param left left value to swap
* @param right right value to swap
* @throws ExpressionException
*/
public static void swap(Array array, int left, int right) throws ExpressionException {
int len = array.size();
if (len == 0)
throw new ExpressionException("array is empty");
if (left < 1 || left > len)
throw new ExpressionException("invalid index [" + left + "]", "valid indexes are from 1 to " + len);
if (right < 1 || right > len)
throw new ExpressionException("invalid index [" + right + "]", "valid indexes are from 1 to " + len);
try {
Object leftValue = array.get(left, null);
Object rightValue = array.get(right, null);
array.setE(left, rightValue);
array.setE(right, leftValue);
} catch (PageException e) {
throw new ExpressionException("can't swap values of array", e.getMessage());
}
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class ArrayUtil method max.
/**
* the greatest value, of all values inside the array, only work when all values are numeric
* @param array
* @return the greatest value
* @throws PageException
*/
public static double max(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 median.
/**
* median value of all items in the arrays, only works when all values are numeric
*
* @param array
* @return
* @throws ExpressionException
*/
public static double median(Array array) throws ExpressionException {
int len = array.size();
if (len == 0)
return 0;
if (array.getDimension() > 1)
throw new ExpressionException("Median() can only be calculated for one dimensional arrays");
double[] arr = new double[len];
for (int i = 0; i < len; i++) arr[i] = _toDoubleValue(array, i + 1);
Arrays.sort(arr);
double result = arr[len / 2];
if (len % 2 == 0) {
return (result + arr[(len - 2) / 2]) / 2;
}
return result;
}
Aggregations