1 24 package org.ofbiz.minilang.method.envops; 25 26 import java.text.*; 27 import java.util.*; 28 29 import org.w3c.dom.*; 30 31 import org.ofbiz.base.util.*; 32 import org.ofbiz.minilang.*; 33 import org.ofbiz.minilang.method.*; 34 35 42 public class StringToList extends MethodOperation { 43 44 public static final String module = StringToList.class.getName(); 45 46 String string; 47 ContextAccessor listAcsr; 48 ContextAccessor argListAcsr; 49 String messageFieldName; 50 51 public StringToList(Element element, SimpleMethod simpleMethod) { 52 super(element, simpleMethod); 53 string = element.getAttribute("string"); 54 listAcsr = new ContextAccessor(element.getAttribute("list-name")); 55 argListAcsr = new ContextAccessor(element.getAttribute("arg-list-name")); 56 messageFieldName = element.getAttribute("message-field-name"); 57 } 58 59 public boolean exec(MethodContext methodContext) { 60 String valueStr = methodContext.expandString(string); 61 if (!argListAcsr.isEmpty()) { 62 List argList = (List) argListAcsr.get(methodContext); 63 if (argList != null && argList.size() > 0) { 64 valueStr = MessageFormat.format(valueStr, argList.toArray()); 65 } 66 } 67 68 Object value; 69 if (this.messageFieldName != null && this.messageFieldName.length() > 0) { 70 value = new MessageString(valueStr, this.messageFieldName, true); 71 } else { 72 value = valueStr; 73 } 74 75 List toList = (List) listAcsr.get(methodContext); 76 if (toList == null) { 77 if (Debug.verboseOn()) Debug.logVerbose("List not found with name " + listAcsr + ", creating new List", module); 78 toList = new LinkedList(); 79 listAcsr.put(methodContext, toList); 80 } 81 toList.add(value); 82 83 return true; 84 } 85 86 public String rawString() { 87 return "<string-to-list string=\"" + this.string + "\" list-name=\"" + this.listAcsr + "\"/>"; 89 } 90 public String expandedString(MethodContext methodContext) { 91 return this.rawString(); 93 } 94 } 95 | Popular Tags |