1 29 30 package com.caucho.config; 31 32 import com.caucho.el.ELParser; 33 import com.caucho.el.Expr; 34 import com.caucho.util.L10N; 35 import com.caucho.xml.QName; 36 37 import org.w3c.dom.Node ; 38 39 import javax.el.ELContext; 40 import javax.el.ELException; 41 42 public abstract class AttributeStrategy { 43 static final L10N L = new L10N(AttributeStrategy.class); 44 45 protected AttributeStrategy() 46 { 47 } 48 49 57 public void configure(NodeBuilder builder, 58 Object bean, 59 QName name, 60 Node node) 61 throws Exception 62 { 63 } 64 65 73 public void setAttribute(Object bean, QName name, Object value) 74 throws Exception 75 { 76 } 77 78 81 public static String evalString(String exprString) 82 throws ELException 83 { 84 if (exprString.indexOf("${") >= 0) { 85 ELContext env = Config.getEnvironment(); 86 87 ELParser parser = new ELParser(env, exprString); 88 parser.setCheckEscape(true); 89 Expr expr = parser.parse(); 90 91 return expr.evalString(env); 92 } 93 else 94 return exprString; 95 } 96 97 100 public static boolean evalBoolean(String exprString) 101 throws ELException 102 { 103 if (exprString.indexOf("${") >= 0) { 104 ELContext env = Config.getEnvironment(); 105 106 ELParser parser = new ELParser(env, exprString); 107 parser.setCheckEscape(true); 108 Expr expr = parser.parse(); 109 110 return expr.evalBoolean(env); 111 } 112 else 113 return Expr.toBoolean(exprString, null); 114 } 115 116 119 public static long evalLong(String exprString) 120 throws ELException 121 { 122 if (exprString.indexOf("${") >= 0) { 123 ELContext env = Config.getEnvironment(); 124 125 ELParser parser = new ELParser(env, exprString); 126 parser.setCheckEscape(true); 127 Expr expr = parser.parse(); 128 129 return expr.evalLong(env); 130 } 131 else 132 return Expr.toLong(exprString, null); 133 } 134 135 138 public static double evalDouble(String exprString) 139 throws ELException 140 { 141 if (exprString.indexOf("${") >= 0) { 142 ELContext env = Config.getEnvironment(); 143 144 ELParser parser = new ELParser(env, exprString); 145 parser.setCheckEscape(true); 146 Expr expr = parser.parse(); 147 148 return expr.evalDouble(env); 149 } 150 else 151 return Expr.toDouble(exprString, null); 152 } 153 154 157 public static Object evalObject(String exprString) 158 throws ELException 159 { 160 if (exprString.indexOf("${") >= 0) { 161 ELContext env = Config.getEnvironment(); 162 163 ELParser parser = new ELParser(env, exprString); 164 parser.setCheckEscape(true); 165 Expr expr = parser.parse(); 166 167 if (expr != null) 168 return expr.evalObject(env); 169 else 170 return exprString; 171 } 172 else 173 return exprString; 174 } 175 } 176 | Popular Tags |