1 5 package com.opensymphony.webwork.views.freemarker; 6 7 import freemarker.template.ObjectWrapper; 8 import freemarker.template.SimpleHash; 9 import freemarker.template.TemplateModel; 10 import freemarker.template.TemplateModelException; 11 12 import javax.servlet.ServletContext ; 13 import javax.servlet.http.HttpServletRequest ; 14 import javax.servlet.http.HttpSession ; 15 16 import com.opensymphony.xwork.util.OgnlValueStack; 17 18 19 26 public class ScopesHashModel extends SimpleHash { 27 29 private HttpServletRequest request; 30 private ObjectWrapper objectWraper; 31 private ServletContext servletContext; 32 private OgnlValueStack stack; 33 34 36 public ScopesHashModel(ObjectWrapper objectWrapper, ServletContext context, HttpServletRequest request, OgnlValueStack stack) { 37 super(objectWrapper); 38 this.servletContext = context; 39 this.request = request; 40 this.stack = stack; 41 } 42 43 45 public TemplateModel get(String key) throws TemplateModelException { 46 TemplateModel model = super.get(key); 48 49 if (model != null) { 50 return model; 51 } 52 53 54 if (stack != null) { 55 Object obj = stack.findValue(key); 56 57 if (obj != null) { 58 return wrap(obj); 59 } 60 } 61 62 if (request != null) { 63 Object obj = request.getAttribute(key); 65 66 if (obj != null) { 67 return wrap(obj); 68 } 69 70 HttpSession session = request.getSession(false); 72 73 if (session != null) { 74 obj = session.getAttribute(key); 75 76 if (obj != null) { 77 return wrap(obj); 78 } 79 } 80 } 81 82 if (servletContext != null) { 83 Object obj = servletContext.getAttribute(key); 85 86 if (obj != null) { 87 return wrap(obj); 88 } 89 } 90 91 return null; 92 } 93 } 94 | Popular Tags |