1 5 package com.opensymphony.workflow.util; 6 7 import com.opensymphony.module.propertyset.PropertySet; 8 9 import com.opensymphony.provider.BeanProvider; 10 import com.opensymphony.provider.bean.DefaultBeanProvider; 11 12 import java.util.Map ; 13 14 15 20 public class ScriptVariableParser { 21 23 private static BeanProvider beanProvider = new DefaultBeanProvider(); 24 25 27 public static Object getVariableFromMaps(String var, Map transientVars, PropertySet ps) { 28 int firstDot = var.indexOf('.'); 29 String actualVar = var; 30 31 if (firstDot != -1) { 32 actualVar = var.substring(0, firstDot); 33 } 34 35 Object o = transientVars.get(actualVar); 36 37 if (o == null) { 38 o = ps.getAsActualType(actualVar); 39 } 40 41 if (firstDot != -1) { 42 o = beanProvider.getProperty(o, var.substring(firstDot + 1)); 43 } 44 45 return o; 46 } 47 48 54 public static Object translateVariables(String s, Map transientVars, PropertySet ps) { 55 String temp = s.trim(); 56 57 if (temp.startsWith("${") && temp.endsWith("}") && (temp.indexOf('$', 1) == -1)) { 58 String var = temp.substring(2, temp.length() - 1); 60 61 return getVariableFromMaps(var, transientVars, ps); 62 } else { 63 while (true) { 65 int x = s.indexOf("${"); 66 int y = s.indexOf("}", x); 67 68 if ((x != -1) && (y != -1)) { 69 String var = s.substring(x + 2, y); 70 String t = null; 71 Object o = getVariableFromMaps(var, transientVars, ps); 72 73 if (o != null) { 74 t = o.toString(); 75 } 76 77 if (t != null) { 78 s = s.substring(0, x) + t + s.substring(y + 1); 79 } else { 80 s = s.substring(0, x) + s.substring(y + 1); 82 } 83 } else { 84 break; 85 } 86 } 87 88 return s; 89 } 90 } 91 } 92 | Popular Tags |