1 5 package com.opensymphony.webwork.views.jsp; 6 7 import com.opensymphony.webwork.util.FastByteArrayOutputStream; 8 import com.opensymphony.webwork.config.Configuration; 9 import com.opensymphony.xwork.util.OgnlValueStack; 10 11 import javax.servlet.jsp.tagext.TagSupport ; 12 import java.io.PrintWriter ; 13 14 15 18 public abstract class WebWorkTagSupport extends TagSupport { 19 public static final boolean ALT_SYNTAX = "true".equals(Configuration.getString("webwork.tag.altSyntax")); 20 21 public static String translateVariables(String expression, OgnlValueStack stack) { 22 while (true) { 23 int x = expression.indexOf("%{"); 24 int y = expression.indexOf("}", x); 25 26 if ((x != -1) && (y != -1)) { 27 String var = expression.substring(x + 2, y); 28 29 Object o = stack.findValue(var, String .class); 30 31 if (o != null) { 32 expression = expression.substring(0, x) + o + expression.substring(y + 1); 33 } else { 34 expression = expression.substring(0, x) + expression.substring(y + 1); 36 } 37 } else { 38 break; 39 } 40 } 41 42 return expression; 43 } 44 45 protected OgnlValueStack getStack() { 46 return TagUtils.getStack(pageContext); 47 } 48 49 protected String findString(String expr) { 50 return (String ) findValue(expr, String .class); 51 } 52 53 protected Object findValue(String expr) { 54 if (ALT_SYNTAX) { 55 if (expr.startsWith("%{") && expr.endsWith("}")) { 57 expr = expr.substring(2, expr.length() - 1); 58 } 59 } 60 61 return getStack().findValue(expr); 62 } 63 64 protected Object findValue(String expr, Class toType) { 65 if (ALT_SYNTAX && toType == String .class) { 66 return translateVariables(expr, getStack()); 67 } else { 68 if (ALT_SYNTAX) { 69 if (expr.startsWith("%{") && expr.endsWith("}")) { 71 expr = expr.substring(2, expr.length() - 1); 72 } 73 } 74 75 return getStack().findValue(expr, toType); 76 } 77 } 78 79 protected String toString(Throwable t) { 80 FastByteArrayOutputStream bout = new FastByteArrayOutputStream(); 81 PrintWriter wrt = new PrintWriter (bout); 82 t.printStackTrace(wrt); 83 wrt.close(); 84 85 return bout.toString(); 86 } 87 } 88 | Popular Tags |