1 16 17 package org.springframework.web.servlet.tags; 18 19 import javax.servlet.jsp.JspException ; 20 import javax.servlet.jsp.JspTagException ; 21 import javax.servlet.jsp.tagext.TagSupport ; 22 import javax.servlet.jsp.tagext.TryCatchFinally ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 import org.springframework.web.servlet.support.JspAwareRequestContext; 28 import org.springframework.web.servlet.support.RequestContext; 29 30 48 public abstract class RequestContextAwareTag extends TagSupport implements TryCatchFinally { 49 50 53 public static final String REQUEST_CONTEXT_PAGE_ATTRIBUTE = 54 "org.springframework.web.servlet.tags.REQUEST_CONTEXT"; 55 56 57 58 protected final Log logger = LogFactory.getLog(getClass()); 59 60 61 private RequestContext requestContext; 62 63 64 70 public final int doStartTag() throws JspException { 71 this.requestContext = (RequestContext) this.pageContext.getAttribute(REQUEST_CONTEXT_PAGE_ATTRIBUTE); 72 try { 73 if (this.requestContext == null) { 74 this.requestContext = new JspAwareRequestContext(this.pageContext); 75 this.pageContext.setAttribute(REQUEST_CONTEXT_PAGE_ATTRIBUTE, this.requestContext); 76 } 77 return doStartTagInternal(); 78 } 79 catch (JspException ex) { 80 logger.error(ex.getMessage(), ex); 81 throw ex; 82 } 83 catch (RuntimeException ex) { 84 logger.error(ex.getMessage(), ex); 85 throw ex; 86 } 87 catch (Exception ex) { 88 logger.error(ex.getMessage(), ex); 89 throw new JspTagException (ex.getMessage()); 90 } 91 } 92 93 96 protected final RequestContext getRequestContext() { 97 return this.requestContext; 98 } 99 100 107 protected abstract int doStartTagInternal() throws Exception ; 108 109 110 public void doCatch(Throwable throwable) throws Throwable { 111 throw throwable; 112 } 113 114 public void doFinally() { 115 this.requestContext = null; 116 } 117 118 } 119 | Popular Tags |