1 52 53 package freemarker.ext.jsp; 54 55 import javax.servlet.jsp.PageContext ; 56 57 import freemarker.ext.beans.BeansWrapper; 58 import freemarker.template.TemplateHashModel; 59 import freemarker.template.TemplateModel; 60 import freemarker.template.TemplateModelException; 61 62 class JspContextModel 63 implements 64 TemplateHashModel 65 { 66 public static final int ANY_SCOPE = -1; 67 public static final int PAGE_SCOPE = PageContext.PAGE_SCOPE; 68 public static final int REQUEST_SCOPE = PageContext.REQUEST_SCOPE; 69 public static final int SESSION_SCOPE = PageContext.SESSION_SCOPE; 70 public static final int APPLICATION_SCOPE = PageContext.APPLICATION_SCOPE; 71 72 private final PageContext pageContext; 73 private final int scope; 74 75 public JspContextModel(PageContext pageContext, int scope) 76 { 77 this.pageContext = pageContext; 78 this.scope = scope; 79 } 80 81 public TemplateModel get(String key) throws TemplateModelException 82 { 83 Object bean = scope == ANY_SCOPE ? pageContext.findAttribute(key) : pageContext.getAttribute(key, scope); 84 return BeansWrapper.getDefaultInstance().wrap(bean); 85 } 86 87 public boolean isEmpty() 88 { 89 return false; 90 } 91 } 92 | Popular Tags |