1 24 package org.ofbiz.minilang.method.envops; 25 26 import java.util.*; 27 28 import org.w3c.dom.*; 29 import org.ofbiz.base.util.*; 30 import org.ofbiz.minilang.*; 31 import org.ofbiz.minilang.method.*; 32 33 40 public class FirstFromList extends MethodOperation { 41 42 public static final String module = FirstFromList.class.getName(); 43 44 ContextAccessor entryAcsr; 45 ContextAccessor listAcsr; 46 47 public FirstFromList(Element element, SimpleMethod simpleMethod) { 48 super(element, simpleMethod); 49 this.entryAcsr = new ContextAccessor(element.getAttribute("entry-name")); 50 this.listAcsr = new ContextAccessor(element.getAttribute("list-name")); 51 } 52 53 public boolean exec(MethodContext methodContext) { 54 Object fieldVal = null; 55 56 if (listAcsr.isEmpty()) { 57 Debug.logWarning("No list-name specified in iterate tag, doing nothing", module); 58 return true; 59 } 60 61 List theList = (List) listAcsr.get(methodContext); 62 63 if (theList == null) { 64 if (Debug.infoOn()) Debug.logInfo("List not found with name " + listAcsr + ", doing nothing", module); 65 return true; 66 } 67 if (theList.size() == 0) { 68 if (Debug.verboseOn()) Debug.logVerbose("List with name " + listAcsr + " has zero entries, doing nothing", module); 69 return true; 70 } 71 72 entryAcsr.put(methodContext, theList.get(0)); 73 return true; 74 } 75 76 public String rawString() { 77 return "<first-from-list list-name=\"" + this.listAcsr + "\" entry-name=\"" + this.entryAcsr + "\"/>"; 78 } 79 public String expandedString(MethodContext methodContext) { 80 return this.rawString(); 82 } 83 } 84 | Popular Tags |