Search in sources :

Example 26 with MiniLangRuntimeException

use of org.apache.ofbiz.minilang.MiniLangRuntimeException in project ofbiz-framework by apache.

the class PropertyToField method exec.

@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
    String resource = resourceFse.expandString(methodContext.getEnvMap());
    String property = propertyFse.expandString(methodContext.getEnvMap());
    String value = null;
    if (noLocale) {
        value = EntityUtilProperties.getPropertyValue(resource, property, methodContext.getDelegator());
    } else {
        value = EntityUtilProperties.getMessage(resource, property, methodContext.getLocale(), methodContext.getDelegator());
    }
    value = FlexibleStringExpander.expandString(value, methodContext.getEnvMap());
    if (value.isEmpty()) {
        value = defaultFse.expandString(methodContext.getEnvMap());
    }
    List<? extends Object> argList = argListFma.get(methodContext.getEnvMap());
    if (argList != null) {
        try {
            value = MessageFormat.format(value, argList.toArray());
        } catch (IllegalArgumentException e) {
            throw new MiniLangRuntimeException("Exception thrown while formatting the property value: " + e.getMessage(), this);
        }
    }
    fieldFma.put(methodContext.getEnvMap(), value);
    return true;
}
Also used : MiniLangRuntimeException(org.apache.ofbiz.minilang.MiniLangRuntimeException)

Aggregations

MiniLangRuntimeException (org.apache.ofbiz.minilang.MiniLangRuntimeException)26 GenericValue (org.apache.ofbiz.entity.GenericValue)10 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)8 MiniLangException (org.apache.ofbiz.minilang.MiniLangException)8 Delegator (org.apache.ofbiz.entity.Delegator)5 MethodOperation (org.apache.ofbiz.minilang.method.MethodOperation)3 BreakElementException (org.apache.ofbiz.minilang.method.envops.Break.BreakElementException)3 ContinueElementException (org.apache.ofbiz.minilang.method.envops.Continue.ContinueElementException)3 SimpleMethod (org.apache.ofbiz.minilang.SimpleMethod)2 FieldObject (org.apache.ofbiz.minilang.method.FieldObject)2 MethodObject (org.apache.ofbiz.minilang.method.MethodObject)2 StringObject (org.apache.ofbiz.minilang.method.StringObject)2 Calendar (com.ibm.icu.util.Calendar)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 Timestamp (java.sql.Timestamp)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1