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 StringToField extends MethodOperation { 43 44 public static final String module = StringToField.class.getName(); 45 46 String string; 47 ContextAccessor mapAcsr; 48 ContextAccessor fieldAcsr; 49 ContextAccessor argListAcsr; 50 String messageFieldName; 51 52 public StringToField(Element element, SimpleMethod simpleMethod) { 53 super(element, simpleMethod); 54 string = element.getAttribute("string"); 55 mapAcsr = new ContextAccessor(element.getAttribute("map-name")); 56 fieldAcsr = new ContextAccessor(element.getAttribute("field-name")); 57 argListAcsr = new ContextAccessor(element.getAttribute("arg-list-name")); 58 messageFieldName = element.getAttribute("message-field-name"); 59 } 60 61 public boolean exec(MethodContext methodContext) { 62 String valueStr = methodContext.expandString(string); 63 64 if (!argListAcsr.isEmpty()) { 65 List argList = (List) argListAcsr.get(methodContext); 66 if (argList != null && argList.size() > 0) { 67 valueStr = MessageFormat.format(valueStr, argList.toArray()); 68 } 69 } 70 71 Object value; 72 if (this.messageFieldName != null && this.messageFieldName.length() > 0) { 73 value = new MessageString(valueStr, this.messageFieldName, true); 74 } else { 75 value = valueStr; 76 } 77 78 if (!mapAcsr.isEmpty()) { 79 Map toMap = (Map) mapAcsr.get(methodContext); 80 81 if (toMap == null) { 82 if (Debug.verboseOn()) Debug.logVerbose("Map not found with name " + mapAcsr + ", creating new map", module); 83 toMap = new HashMap(); 84 mapAcsr.put(methodContext, toMap); 85 } 86 fieldAcsr.put(toMap, value, methodContext); 87 } else { 88 fieldAcsr.put(methodContext, value); 89 } 90 91 return true; 92 } 93 94 public String rawString() { 95 return "<string-to-field string=\"" + this.string + "\" field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>"; 97 } 98 public String expandedString(MethodContext methodContext) { 99 return this.rawString(); 101 } 102 } 103 | Popular Tags |