1 13 package com.tonbeller.wcf.pagestack; 14 15 import java.util.Iterator ; 16 17 import javax.servlet.http.HttpServletRequest ; 18 import javax.servlet.jsp.JspTagException ; 19 import javax.servlet.jsp.jstl.core.LoopTagSupport; 20 import javax.servlet.jsp.jstl.fmt.LocaleSupport; 21 22 import com.tonbeller.tbutils.res.Resources; 23 import com.tonbeller.wcf.controller.RequestContext; 24 import com.tonbeller.wcf.expr.ExprUtils; 25 import com.tonbeller.wcf.token.RequestToken; 26 27 30 public class PageStackTag extends LoopTagSupport { 31 String page; 32 String pageId; 33 String title; 34 String key; 35 boolean clear; 36 String bundle; 37 38 Iterator iter; 39 40 protected void prepare() throws JspTagException { 41 String s = makeTitle(); 42 PageStack stack = PageStack.instance(pageContext.getSession()); 43 if (clear) 44 stack.clear(); 45 if (page != null && s != null) { 46 String path = addContextPath(page); 47 Page curPg = new Page(pageId, path, page, s); 48 curPg.setRequestToken(RequestToken.instance(pageContext.getSession())); 49 stack.setCurrentPage(curPg); 50 } 51 iter = stack.iterator(); 52 } 53 54 private String addContextPath(String path) { 55 if (path.startsWith("/")) { 57 HttpServletRequest hsr = (HttpServletRequest ) pageContext.getRequest(); 58 path = hsr.getContextPath() + path; 59 } 60 return path; 61 } 62 63 protected Object next() throws JspTagException { 64 return iter.next(); 65 } 66 67 protected boolean hasNext() throws JspTagException { 68 return iter.hasNext(); 69 } 70 71 private String makeTitle() { 72 if (key == null) 74 return eval(title); 75 76 if (bundle != null) { 78 RequestContext context = RequestContext.instance(); 79 Resources res = context.getResources(bundle); 80 return res.getOptionalString(key, key); 81 } 82 83 return LocaleSupport.getLocalizedMessage(pageContext, key); 85 } 86 87 public void setTitle(String title) { 88 this.title = title; 89 } 90 91 public void setClear(boolean clear) { 92 this.clear = clear; 93 } 94 95 public void setPage(String page) { 96 this.page = page; 97 } 98 99 public void setPageId(String pageId) { 100 this.pageId = pageId; 101 } 102 103 public void setKey(String key) { 104 this.key = key; 105 } 106 107 public void setBundle(String bundle) { 108 this.bundle = bundle; 109 } 110 111 private String eval(String el) { 112 if (ExprUtils.isExpression(el)) 113 return String.valueOf(ExprUtils.getModelReference(pageContext, el)); 114 return el; 115 } 116 117 } | Popular Tags |