1 24 package org.ofbiz.minilang.method.eventops; 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 RequestParametersToList extends MethodOperation { 41 42 public static final String module = RequestParametersToList.class.getName(); 43 44 ContextAccessor listAcsr; 45 String requestName; 46 47 public RequestParametersToList(Element element, SimpleMethod simpleMethod) { 48 super(element, simpleMethod); 49 requestName = element.getAttribute("request-name"); 50 listAcsr = new ContextAccessor(element.getAttribute("list-name"), requestName); 51 } 52 53 public boolean exec(MethodContext methodContext) { 54 Object listVal = null; 55 if (methodContext.getMethodType() == MethodContext.EVENT) { 57 listVal = methodContext.getRequest().getParameterValues(requestName); 58 if (listVal == null) { 59 Debug.logWarning("Request parameter values not found with name " + requestName, module); 60 } 61 } 62 63 if (listVal == null) { 65 listVal = new ArrayList(); 66 } else if (listVal instanceof String []) { 67 listVal = UtilMisc.toListArray((String []) listVal); 68 } 69 70 List toList = (List) listAcsr.get(methodContext); 71 72 if (toList == null) { 73 if (Debug.verboseOn()) Debug.logVerbose("List not found with name " + listAcsr + ", creating new list", module); 74 toList = new ArrayList(); 75 listAcsr.put(methodContext, toList); 76 } 77 78 toList.addAll((Collection) listVal); 79 return true; 80 } 81 82 public String rawString() { 83 return "<request-parameters-to-list request-name=\"" + this.requestName + "\" list-name=\"" + this.listAcsr + "\"/>"; 84 } 85 public String expandedString(MethodContext methodContext) { 86 return this.rawString(); 88 } 89 } 90 | Popular Tags |