1 24 package org.ofbiz.minilang.method.eventops; 25 26 import java.util.Map ; 27 28 import org.ofbiz.base.util.Debug; 29 import org.ofbiz.base.util.collections.FlexibleServletAccessor; 30 import org.ofbiz.minilang.SimpleMethod; 31 import org.ofbiz.minilang.method.ContextAccessor; 32 import org.ofbiz.minilang.method.MethodContext; 33 import org.ofbiz.minilang.method.MethodOperation; 34 import org.w3c.dom.Element ; 35 36 43 public class FieldToSession extends MethodOperation { 44 45 public static final String module = FieldToSession.class.getName(); 46 47 ContextAccessor mapAcsr; 48 ContextAccessor fieldAcsr; 49 FlexibleServletAccessor sessionAcsr; 50 51 public FieldToSession(Element element, SimpleMethod simpleMethod) { 52 super(element, simpleMethod); 53 mapAcsr = new ContextAccessor(element.getAttribute("map-name")); 54 fieldAcsr = new ContextAccessor(element.getAttribute("field-name")); 55 sessionAcsr = new FlexibleServletAccessor(element.getAttribute("session-name"), element.getAttribute("field-name")); 56 } 57 58 public boolean exec(MethodContext methodContext) { 59 if (methodContext.getMethodType() == MethodContext.EVENT) { 61 Object fieldVal = null; 62 if (!mapAcsr.isEmpty()) { 63 Map fromMap = (Map ) mapAcsr.get(methodContext); 64 if (fromMap == null) { 65 Debug.logWarning("Map not found with name " + mapAcsr, module); 66 return true; 67 } 68 fieldVal = fieldAcsr.get(fromMap, methodContext); 69 } else { 70 fieldVal = fieldAcsr.get(methodContext); 72 } 73 74 if (fieldVal == null) { 75 Debug.logWarning("Field value not found with name " + fieldAcsr + " in Map with name " + mapAcsr, module); 76 return true; 77 } 78 79 sessionAcsr.put(methodContext.getRequest().getSession(), fieldVal, methodContext.getEnvMap()); 80 } 81 return true; 82 } 83 84 public String rawString() { 85 return "<field-to-session field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>"; 87 } 88 public String expandedString(MethodContext methodContext) { 89 return this.rawString(); 91 } 92 } 93 | Popular Tags |