use of org.apache.ofbiz.minilang.MiniLangRuntimeException in project ofbiz-framework by apache.
the class Iterate method exec.
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
if (listFma.isEmpty()) {
if (Debug.verboseOn()) {
Debug.logVerbose("Collection not found, doing nothing: " + this, module);
}
return true;
}
Object oldEntryValue = entryFma.get(methodContext.getEnvMap());
Object objList = listFma.get(methodContext.getEnvMap());
if (objList instanceof EntityListIterator) {
try (EntityListIterator eli = (EntityListIterator) objList) {
GenericValue theEntry;
while ((theEntry = eli.next()) != null) {
entryFma.put(methodContext.getEnvMap(), theEntry);
try {
for (MethodOperation methodOperation : subOps) {
if (!methodOperation.exec(methodContext)) {
return false;
}
}
} catch (MiniLangException e) {
if (e instanceof BreakElementException) {
break;
}
if (e instanceof ContinueElementException) {
continue;
}
throw e;
}
}
} catch (GenericEntityException e) {
throw new MiniLangRuntimeException("Error with entityListIterator: " + e.getMessage(), this);
}
} else if (objList instanceof Collection<?>) {
Collection<Object> theCollection = UtilGenerics.checkCollection(objList);
if (theCollection.size() == 0) {
if (Debug.verboseOn()) {
Debug.logVerbose("Collection has zero entries, doing nothing: " + this, module);
}
return true;
}
for (Object theEntry : theCollection) {
entryFma.put(methodContext.getEnvMap(), theEntry);
try {
for (MethodOperation methodOperation : subOps) {
if (!methodOperation.exec(methodContext)) {
return false;
}
}
} catch (MiniLangException e) {
if (e instanceof BreakElementException) {
break;
}
if (e instanceof ContinueElementException) {
continue;
}
throw e;
}
}
} else if (objList instanceof Iterator<?>) {
Iterator<Object> theIterator = UtilGenerics.cast(objList);
if (!theIterator.hasNext()) {
if (Debug.verboseOn()) {
Debug.logVerbose("Iterator has zero entries, doing nothing: " + this, module);
}
return true;
}
while (theIterator.hasNext()) {
Object theEntry = theIterator.next();
entryFma.put(methodContext.getEnvMap(), theEntry);
try {
for (MethodOperation methodOperation : subOps) {
if (!methodOperation.exec(methodContext)) {
return false;
}
}
} catch (MiniLangException e) {
if (e instanceof BreakElementException) {
break;
}
if (e instanceof ContinueElementException) {
continue;
}
throw e;
}
}
} else {
if (Debug.verboseOn()) {
Debug.logVerbose("Cannot iterate over a " + objList == null ? "null object" : objList.getClass().getName() + ", doing nothing: " + this, module);
}
return true;
}
entryFma.put(methodContext.getEnvMap(), oldEntryValue);
return true;
}
use of org.apache.ofbiz.minilang.MiniLangRuntimeException in project ofbiz-framework by apache.
the class IterateMap method exec.
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
if (mapFma.isEmpty()) {
throw new MiniLangRuntimeException("No map specified.", this);
}
Object oldKey = keyFma.get(methodContext.getEnvMap());
Object oldValue = valueFma.get(methodContext.getEnvMap());
if (oldKey != null) {
if (Debug.verboseOn()) {
Debug.logVerbose("In iterate-map the key had a non-null value before entering the loop for the operation: " + this, module);
}
}
if (oldValue != null) {
if (Debug.verboseOn()) {
Debug.logVerbose("In iterate-map the value had a non-null value before entering the loop for the operation: " + this, module);
}
}
Map<? extends Object, ? extends Object> theMap = mapFma.get(methodContext.getEnvMap());
if (theMap == null) {
if (Debug.verboseOn()) {
Debug.logVerbose("Map not found with name " + mapFma + ", doing nothing: " + this, module);
}
return true;
}
if (theMap.size() == 0) {
if (Debug.verboseOn()) {
Debug.logVerbose("Map with name " + mapFma + " has zero entries, doing nothing: " + this, module);
}
return true;
}
for (Map.Entry<? extends Object, ? extends Object> theEntry : theMap.entrySet()) {
keyFma.put(methodContext.getEnvMap(), theEntry.getKey());
valueFma.put(methodContext.getEnvMap(), theEntry.getValue());
try {
for (MethodOperation methodOperation : subOps) {
if (!methodOperation.exec(methodContext)) {
return false;
}
}
} catch (MiniLangException e) {
if (e instanceof BreakElementException) {
break;
}
if (e instanceof ContinueElementException) {
continue;
}
throw e;
}
}
return true;
}
use of org.apache.ofbiz.minilang.MiniLangRuntimeException in project ofbiz-framework by apache.
the class Loop method exec.
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
String countStr = this.countFse.expandString(methodContext.getEnvMap());
int count = 0;
try {
count = Double.valueOf(countStr).intValue();
} catch (NumberFormatException e) {
throw new MiniLangRuntimeException("Error while converting \"" + countStr + "\" to a number: " + e.getMessage(), this);
}
if (count < 0) {
throw new MiniLangRuntimeException("Unable to execute loop operation because the count is negative: " + countStr, this);
}
for (int i = 0; i < count; i++) {
this.fieldFma.put(methodContext.getEnvMap(), i);
try {
for (MethodOperation methodOperation : subOps) {
if (!methodOperation.exec(methodContext)) {
return false;
}
}
} catch (MiniLangException e) {
if (e instanceof BreakElementException) {
break;
}
if (e instanceof ContinueElementException) {
continue;
}
throw e;
}
}
return true;
}
use of org.apache.ofbiz.minilang.MiniLangRuntimeException in project ofbiz-framework by apache.
the class StringToList method exec.
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
String valueStr = stringFse.expandString(methodContext.getEnvMap());
List<? extends Object> argList = argListFma.get(methodContext.getEnvMap());
if (argList != null) {
try {
valueStr = MessageFormat.format(valueStr, argList.toArray());
} catch (IllegalArgumentException e) {
throw new MiniLangRuntimeException("Exception thrown while formatting the string attribute: " + e.getMessage(), this);
}
}
Object value;
if (UtilValidate.isNotEmpty(this.messageFieldName)) {
value = new MessageString(valueStr, this.messageFieldName, true);
} else {
value = valueStr;
}
List<Object> toList = listFma.get(methodContext.getEnvMap());
if (toList == null) {
toList = new LinkedList<Object>();
listFma.put(methodContext.getEnvMap(), toList);
}
toList.add(value);
return true;
}
use of org.apache.ofbiz.minilang.MiniLangRuntimeException in project ofbiz-framework by apache.
the class WebappPropertyToField method exec.
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
if (methodContext.getMethodType() == MethodContext.EVENT) {
String resource = resourceFse.expandString(methodContext.getEnvMap());
ServletContext servletContext = (ServletContext) methodContext.getRequest().getAttribute("servletContext");
URL propsUrl = null;
try {
propsUrl = servletContext.getResource(resource);
} catch (java.net.MalformedURLException e) {
throw new MiniLangRuntimeException("Exception thrown while finding properties file " + resource + ": " + e.getMessage(), this);
}
if (propsUrl == null) {
throw new MiniLangRuntimeException("Properties file " + resource + " not found.", this);
}
String property = propertyFse.expandString(methodContext.getEnvMap());
String fieldVal = UtilProperties.getPropertyValue(propsUrl, property);
if (fieldVal == null) {
fieldVal = defaultFse.expandString(methodContext.getEnvMap());
}
fieldFma.put(methodContext.getEnvMap(), fieldVal);
}
return true;
}
Aggregations