1 24 package org.ofbiz.minilang.method.callops; 25 26 import java.io.Serializable ; 27 28 import org.w3c.dom.*; 29 import org.ofbiz.base.util.*; 30 31 import org.ofbiz.minilang.method.*; 32 33 40 public class FlexibleMessage implements Serializable { 41 42 public static final String module = FlexibleMessage.class.getName(); 43 44 String message = null; 45 String propertyResource = null; 46 boolean isProperty = false; 47 48 public FlexibleMessage(Element element, String defaultProperty) { 49 String resAttr = null; 50 String propAttr = null; 51 String elVal = null; 52 53 if (element != null) { 54 resAttr = element.getAttribute("resource"); 55 propAttr = element.getAttribute("property"); 56 elVal = UtilXml.elementValue(element); 57 } 58 59 if (resAttr != null && resAttr.length() > 0) { 60 propertyResource = resAttr; 61 message = propAttr; 62 isProperty = true; 63 } else if (elVal != null && elVal.length() > 0) { 64 message = elVal; 65 isProperty = false; 66 } else { 67 propertyResource = "DefaultMessages"; 69 message = defaultProperty; 70 isProperty = true; 71 } 72 } 73 74 public String getMessage(ClassLoader loader, MethodContext methodContext) { 75 String message = methodContext.expandString(this.message); 76 String propertyResource = methodContext.expandString(this.propertyResource); 77 78 if (!isProperty && message != null) { 80 return message; 82 } else if (isProperty && propertyResource != null && message != null) { 83 String propMsg = UtilProperties.getMessage(propertyResource, message, methodContext.getEnvMap(), methodContext.getLocale()); 86 87 if (propMsg == null) { 89 return "In Simple Map Processing property message could not be found in resource [" + propertyResource + "] with name [" + message + "]. "; 90 } else { 91 return propMsg; 92 } 93 } else { 94 Debug.logInfo("[FlexibleMessage.getMessage] No message found, returning empty string", module); 95 return ""; 96 } 97 } 98 } 99 | Popular Tags |