1 24 package org.ofbiz.minilang.method.envops; 25 26 import java.util.*; 27 28 import javolution.util.FastList; 29 30 import org.w3c.dom.*; 31 import org.ofbiz.base.util.*; 32 import org.ofbiz.base.util.collections.FlexibleMapAccessor; 33 import org.ofbiz.base.util.collections.MapComparator; 34 import org.ofbiz.minilang.*; 35 import org.ofbiz.minilang.method.*; 36 37 44 public class OrderMapList extends MethodOperation { 45 46 public static final String module = FieldToList.class.getName(); 47 48 protected ContextAccessor listAcsr; 49 protected List orderByAcsrList = FastList.newInstance(); 50 protected MapComparator mc; 51 52 public OrderMapList(Element element, SimpleMethod simpleMethod) { 53 super(element, simpleMethod); 54 listAcsr = new ContextAccessor(element.getAttribute("list-name")); 55 56 List orderByElementList = UtilXml.childElementList(element, "order-by"); 57 Iterator orderByElementIter = orderByElementList.iterator(); 58 while (orderByElementIter.hasNext()) { 59 Element orderByElement = (Element) orderByElementIter.next(); 60 this.orderByAcsrList.add(new FlexibleMapAccessor(orderByElement.getAttribute("field-name"))); 61 } 62 63 this.mc = new MapComparator(this.orderByAcsrList); 64 } 65 66 public boolean exec(MethodContext methodContext) { 67 Object fieldVal = null; 68 69 List orderList = (List) listAcsr.get(methodContext); 70 71 if (orderList == null) { 72 if (Debug.infoOn()) Debug.logInfo("List not found with name " + listAcsr + ", not ordering/sorting list.", module); 73 return true; 74 } 75 76 Collections.sort(orderList, mc); 77 78 return true; 79 } 80 81 public String rawString() { 82 return "<order-map-list list-name=\"" + this.listAcsr + "\"/>"; 83 } 84 public String expandedString(MethodContext methodContext) { 85 return this.rawString(); 87 } 88 } 89 | Popular Tags |