1 52 53 package freemarker.ext.servlet; 54 55 import java.util.HashMap ; 56 import java.util.Map ; 57 58 import javax.servlet.ServletContext ; 59 import javax.servlet.http.HttpServletRequest ; 60 import javax.servlet.http.HttpSession ; 61 62 import freemarker.template.ObjectWrapper; 63 import freemarker.template.SimpleHash; 64 import freemarker.template.TemplateModel; 65 import freemarker.template.TemplateModelException; 66 67 81 class AllHttpScopesHashModel extends SimpleHash 82 { 83 private final ObjectWrapper wrapper; 84 private final ServletContext context; 85 private final HttpServletRequest request; 86 private final Map unlistedModels = new HashMap (); 87 88 AllHttpScopesHashModel(ObjectWrapper wrapper, ServletContext context, HttpServletRequest request) { 89 this.wrapper = wrapper; 90 this.context = context; 91 this.request = request; 92 } 93 94 101 void putUnlistedModel(String key, TemplateModel model) 102 { 103 unlistedModels.put(key, model); 104 } 105 106 public TemplateModel get(String key) throws TemplateModelException { 107 TemplateModel model = super.get(key); 109 if(model != null) { 110 return model; 111 } 112 113 model = (TemplateModel)unlistedModels.get(key); 115 if(model != null) { 116 return model; 117 } 118 119 Object obj = request.getAttribute(key); 121 if(obj != null) { 122 return wrapper.wrap(obj); 123 } 124 125 HttpSession session = request.getSession(false); 127 if(session != null) { 128 obj = session.getAttribute(key); 129 if(obj != null) { 130 return wrapper.wrap(obj); 131 } 132 } 133 134 obj = context.getAttribute(key); 136 if(obj != null) { 137 return wrapper.wrap(obj); 138 } 139 140 return wrapper.wrap(null); 142 } 143 } 144 | Popular Tags |