1 24 package org.ofbiz.minilang.operation; 25 26 import java.util.*; 27 import org.w3c.dom.*; 28 29 36 public class Copy extends SimpleMapOperation { 37 38 boolean replace = true; 39 boolean setIfNull = true; 40 String toField; 41 42 public Copy(Element element, SimpleMapProcess simpleMapProcess) { 43 super(element, simpleMapProcess); 44 toField = element.getAttribute("to-field"); 45 if (this.toField == null || this.toField.length() == 0) { 46 this.toField = this.fieldName; 47 } 48 49 replace = !"false".equals(element.getAttribute("replace")); 51 setIfNull = !"false".equals(element.getAttribute("set-if-null")); 53 } 54 55 public void exec(Map inMap, Map results, List messages, Locale locale, ClassLoader loader) { 56 Object fieldValue = inMap.get(fieldName); 57 58 if (fieldValue == null && !setIfNull) 59 return; 60 61 if (fieldValue instanceof java.lang.String ) { 62 if (((String ) fieldValue).length() == 0) { 63 if (setIfNull && (replace || !results.containsKey(toField))) { 64 results.put(toField, null); 65 } 66 return; 67 } 68 } 69 70 if (replace) { 71 results.put(toField, fieldValue); 72 } else { 74 if (results.containsKey(toField)) { } else { 76 results.put(toField, fieldValue); 77 } 79 } 80 } 81 } 82 | Popular Tags |