Search in sources :

Example 61 with ExpressionException

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());
}
Also used : Locale(java.util.Locale) Matcher(java.util.regex.Matcher) ExpressionException(lucee.runtime.exp.ExpressionException) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 62 with ExpressionException

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;
}
Also used : InterpreterException(lucee.runtime.interpreter.InterpreterException) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 63 with ExpressionException

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);
}
Also used : FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) FunctionLib(lucee.transformer.library.function.FunctionLib) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 64 with ExpressionException

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);
}
Also used : TagLibTag(lucee.transformer.library.tag.TagLibTag) TagLib(lucee.transformer.library.tag.TagLib) PageContextImpl(lucee.runtime.PageContextImpl) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 65 with ExpressionException

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());
}
Also used : VariableReference(lucee.runtime.type.ref.VariableReference) Scope(lucee.runtime.type.scope.Scope) Query(lucee.runtime.type.Query) PageContextImpl(lucee.runtime.PageContextImpl) ExpressionException(lucee.runtime.exp.ExpressionException)

Aggregations

ExpressionException (lucee.runtime.exp.ExpressionException)136 Element (org.w3c.dom.Element)24 Key (lucee.runtime.type.Collection.Key)15 SecurityException (lucee.runtime.exp.SecurityException)13 ArrayList (java.util.ArrayList)12 Struct (lucee.runtime.type.Struct)12 List (java.util.List)11 Collection (lucee.runtime.type.Collection)11 Entry (java.util.Map.Entry)10 Node (org.w3c.dom.Node)10 Resource (lucee.commons.io.res.Resource)9 Iterator (java.util.Iterator)8 PageException (lucee.runtime.exp.PageException)8 Map (java.util.Map)7 CasterException (lucee.runtime.exp.CasterException)7 NodeList (org.w3c.dom.NodeList)7 PageContextImpl (lucee.runtime.PageContextImpl)6 PageSource (lucee.runtime.PageSource)5 Casting (lucee.runtime.interpreter.ref.cast.Casting)5 ArrayImpl (lucee.runtime.type.ArrayImpl)5