use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class LocaleFactory method getLocale.
/**
* @param strLocale
* @return return locale match to String
* @throws ExpressionException
*/
public static Locale getLocale(String strLocale) throws ExpressionException {
String strLocaleLC = strLocale.toLowerCase().trim();
Locale l = locales.get(strLocaleLC);
if (l != null)
return l;
l = localeAlias.get(strLocaleLC);
if (l != null)
return l;
Matcher matcher = localePattern2.matcher(strLocaleLC);
if (matcher.find()) {
int len = matcher.groupCount();
if (len == 2) {
String lang = matcher.group(1).trim();
String country = matcher.group(2).trim();
Locale locale = new Locale(lang, country);
try {
locale.getISO3Language();
setLocalAlias(strLocaleLC, locale);
return locale;
} catch (Exception e) {
}
}
}
matcher = localePattern3.matcher(strLocaleLC);
if (matcher.find()) {
int len = matcher.groupCount();
if (len == 3) {
String lang = matcher.group(1).trim();
String country = matcher.group(2).trim();
String variant = matcher.group(3).trim();
Locale locale = new Locale(lang, country, variant);
try {
locale.getISO3Language();
setLocalAlias(strLocaleLC, locale);
return locale;
} catch (Exception e) {
}
}
}
matcher = localePattern.matcher(strLocaleLC);
if (matcher.find()) {
int len = matcher.groupCount();
if (len == 3) {
String lang = matcher.group(1).trim();
String country = matcher.group(3);
if (country != null)
country = country.trim();
Object objLocale = null;
if (country != null)
objLocale = locales.get(lang.toLowerCase() + " (" + (country.toLowerCase()) + ")");
else
objLocale = locales.get(lang.toLowerCase());
if (objLocale != null)
return (Locale) objLocale;
Locale locale;
if (country != null)
locale = new Locale(lang.toUpperCase(), country.toLowerCase());
else
locale = new Locale(lang);
try {
locale.getISO3Language();
} catch (Exception e) {
if (strLocale.indexOf('-') != -1)
return getLocale(strLocale.replace('-', '_'));
throw new ExpressionException("unsupported Locale [" + strLocale + "]", "supported Locales are:" + getSupportedLocalesAsString());
}
setLocalAlias(strLocaleLC, locale);
return locale;
}
}
throw new ExpressionException("can't cast value (" + strLocale + ") to a Locale", "supported Locales are:" + getSupportedLocalesAsString());
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class VT method getMatchingValueAndType.
private VT getMatchingValueAndType(FunctionLibFunctionArg flfa, FunctionValue[] fvalues, String[] names) throws ExpressionException {
String flfan = flfa.getName();
// first search if a argument match
for (int i = 0; i < names.length; i++) {
if (names[i] != null && names[i].equalsIgnoreCase(flfan)) {
return new VT(fvalues[i].getValue(), flfa.getTypeAsString(), i);
}
}
// then check if a alias match
String alias = flfa.getAlias();
if (!StringUtil.isEmpty(alias)) {
for (int i = 0; i < names.length; i++) {
if (names[i] != null && lucee.runtime.type.util.ListUtil.listFindNoCase(alias, names[i], ",") != -1) {
return new VT(fvalues[i].getValue(), flfa.getTypeAsString(), i);
}
}
}
// if not required return the default value
if (!flfa.getRequired()) {
String defaultValue = flfa.getDefaultValue();
String type = flfa.getTypeAsString().toLowerCase();
if (defaultValue == null) {
if (type.equals("boolean") || type.equals("bool"))
return new VT(Boolean.FALSE, type, -1);
if (type.equals("number") || type.equals("numeric") || type.equals("double"))
return new VT(Constants.DOUBLE_ZERO, type, -1);
return new VT(null, type, -1);
}
return new VT(defaultValue, type, -1);
}
ExpressionException ee = new InterpreterException("missing required argument [" + flfan + "] for function [" + flfa.getFunction().getName() + "]");
UDFUtil.addFunctionDoc(ee, flfa.getFunction());
throw ee;
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class GetFunctionData method _call.
private static Struct _call(PageContext pc, String strFunctionName, int dialect) throws PageException {
FunctionLib[] flds;
flds = ((ConfigImpl) pc.getConfig()).getFLDs(dialect);
FunctionLibFunction function = null;
for (int i = 0; i < flds.length; i++) {
function = flds[i].getFunction(strFunctionName.toLowerCase());
if (function != null)
break;
}
if (function == null)
throw new ExpressionException("function [" + strFunctionName + "] is not a built in function");
// CFML Based Function
Class clazz = null;
try {
clazz = function.getFunctionClassDefinition().getClazz();
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
if (clazz == lucee.runtime.functions.system.CFFunction.class) {
return cfmlBasedFunction(pc, function);
}
return javaBasedFunction(function);
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class GetTagData method _call.
private static Struct _call(PageContext pc, String nameSpace, String strTagName, int dialect) throws PageException {
TagLib[] tlds;
tlds = ((ConfigImpl) pc.getConfig()).getTLDs(dialect);
TagLib tld = null;
TagLibTag tag = null;
for (int i = 0; i < tlds.length; i++) {
tld = tlds[i];
if (tld.getNameSpaceAndSeparator().equalsIgnoreCase(nameSpace)) {
tag = tld.getTag(strTagName.toLowerCase());
if (tag != null)
break;
}
}
if (tag == null)
throw new ExpressionException("tag [" + nameSpace + strTagName + "] is not a built in tag");
// CFML Based Function
Class clazz = null;
try {
clazz = tag.getTagClassDefinition().getClazz();
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
if (clazz == CFTagCore.class) {
PageContextImpl pci = (PageContextImpl) pc;
boolean prior = pci.useSpecialMappings(true);
try {
return cfmlBasedTag(pc, tld, tag);
} finally {
pci.useSpecialMappings(prior);
}
}
return javaBasedTag(tld, tag);
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class ValueList method toColumn.
protected static QueryColumn toColumn(PageContext pc, String strQueryColumn) throws PageException {
// if(strQueryColumn.indexOf('.')<1)
// throw new ExpressionException("invalid query column definition ["+strQueryColumn+"]");
VariableReference ref = ((PageContextImpl) pc).getVariableReference(strQueryColumn);
if (ref.getParent() instanceof Scope)
throw new ExpressionException("invalid query column definition [" + strQueryColumn + "]");
Query query = Caster.toQuery(ref.getParent());
return query.getColumn(ref.getKey());
}
Aggregations