1 5 package com.opensymphony.webwork.dispatcher; 6 7 import com.opensymphony.webwork.ServletActionContext; 8 import com.opensymphony.xwork.ActionContext; 9 import com.opensymphony.xwork.ActionInvocation; 10 import com.opensymphony.xwork.Result; 11 import com.opensymphony.xwork.util.OgnlValueStack; 12 import com.opensymphony.xwork.util.TextParseUtil; 13 14 import javax.servlet.http.HttpServletResponse ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.Map ; 18 19 20 25 public class HttpHeaderResult implements Result { 26 28 public static final String DEFAULT_PARAM = "status"; 29 30 32 protected boolean parse = true; 33 private Map headers; 34 private int status = -1; 35 36 38 43 public Map getHeaders() { 44 if (headers == null) { 45 headers = new HashMap (); 46 } 47 48 return headers; 49 } 50 51 57 public void setParse(boolean parse) { 58 this.parse = parse; 59 } 60 61 67 public void setStatus(int status) { 68 this.status = status; 69 } 70 71 78 public void execute(ActionInvocation invocation) throws Exception { 79 HttpServletResponse response = ServletActionContext.getResponse(); 80 81 if (status != -1) { 82 response.setStatus(status); 83 } 84 85 if (headers != null) { 86 OgnlValueStack stack = ActionContext.getContext().getValueStack(); 87 88 for (Iterator iterator = headers.entrySet().iterator(); 89 iterator.hasNext();) { 90 Map.Entry entry = (Map.Entry ) iterator.next(); 91 String value = (String ) entry.getValue(); 92 String finalValue = parse ? TextParseUtil.translateVariables(value, stack) : value; 93 response.addHeader((String ) entry.getKey(), finalValue); 94 } 95 } 96 } 97 } 98 | Popular Tags |