Search in sources :

Example 6 with Scripting

use of com.haulmont.cuba.core.global.Scripting in project cuba by cuba-platform.

the class TimeBetweenQueryMacroHandler method getParam.

protected String getParam(String[] args, int idx, TimeZone timeZone) {
    String arg = args[idx].trim();
    String unit = args[3].trim();
    Matcher matcher = PARAM_PATTERN.matcher(arg);
    if (!matcher.find())
        throw new RuntimeException("Invalid macro argument: " + arg);
    int num = 0;
    try {
        String expr = matcher.group(2);
        if (!Strings.isNullOrEmpty(expr)) {
            Scripting scripting = AppBeans.get(Scripting.class);
            num = scripting.evaluateGroovy(expr, new Binding());
        }
    } catch (NumberFormatException e) {
        throw new RuntimeException("Invalid macro argument: " + arg, e);
    }
    Date date = computeDate(num, unit, timeZone);
    String paramName = args[0].trim().replace(".", "_") + "_" + count + "_" + idx;
    params.put(paramName, date);
    return paramName;
}
Also used : Binding(groovy.lang.Binding) Matcher(java.util.regex.Matcher) Scripting(com.haulmont.cuba.core.global.Scripting)

Example 7 with Scripting

use of com.haulmont.cuba.core.global.Scripting in project cuba by cuba-platform.

the class LookupFieldLoader method loadOptionsEnum.

@SuppressWarnings("unchecked")
protected void loadOptionsEnum(LookupField resultComponent, Element element) {
    String optionsEnumClass = element.attributeValue("optionsEnum");
    if (StringUtils.isNotEmpty(optionsEnumClass)) {
        Scripting scripting = AppBeans.get(Scripting.class);
        resultComponent.setOptionsEnum((Class<? extends EnumClass>) scripting.loadClass(optionsEnumClass));
    }
}
Also used : Scripting(com.haulmont.cuba.core.global.Scripting)

Aggregations

Scripting (com.haulmont.cuba.core.global.Scripting)7 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 ListEditor (com.haulmont.cuba.gui.components.ListEditor)1 ValidationException (com.haulmont.cuba.gui.components.ValidationException)1 ConditionParamBuilder (com.haulmont.cuba.gui.components.filter.ConditionParamBuilder)1 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)1 Binding (groovy.lang.Binding)1 Collection (java.util.Collection)1 Matcher (java.util.regex.Matcher)1 Nullable (javax.annotation.Nullable)1 Element (org.dom4j.Element)1