1 package com.opensymphony.webwork.components; 2 3 import com.opensymphony.webwork.util.TokenHelper; 4 import com.opensymphony.xwork.util.OgnlValueStack; 5 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 import java.util.Map ; 9 10 15 public class Token extends UIBean { 16 final public static String TEMPLATE = "token"; 17 18 public Token(OgnlValueStack stack, HttpServletRequest request, HttpServletResponse response) { 19 super(stack, request, response); 20 } 21 22 protected String getDefaultTemplate() { 23 return TEMPLATE; 24 } 25 26 32 protected void evaluateExtraParams() { 33 super.evaluateExtraParams(); 34 35 String tokenName; 36 Map parameters = getParameters(); 37 38 if (parameters.containsKey("name")) { 39 tokenName = (String ) parameters.get("name"); 40 } else { 41 if (name == null) { 42 tokenName = TokenHelper.DEFAULT_TOKEN_NAME; 43 } else { 44 tokenName = findString(name); 45 46 if (tokenName == null) { 47 tokenName = name; 48 } 49 } 50 51 addParameter("name", tokenName); 52 } 53 54 String token = buildToken(tokenName); 55 addParameter("token", token); 56 addParameter("tokenNameField", TokenHelper.TOKEN_NAME_FIELD); 57 } 58 59 63 public String getTokenNameField() { 64 return TokenHelper.TOKEN_NAME_FIELD; 65 } 66 67 private String buildToken(String name) { 68 Map context = stack.getContext(); 69 Object myToken = context.get(name); 70 71 if (myToken == null) { 72 myToken = TokenHelper.setToken(name, request); 73 context.put(name, myToken); 74 } 75 76 return myToken.toString(); 77 } 78 } 79 | Popular Tags |