1 package de.jwi.jgallery.tags; 2 3 24 25 26 import java.util.Stack ; 27 28 import javax.servlet.ServletRequest ; 29 import javax.servlet.jsp.JspException ; 30 import javax.servlet.jsp.tagext.BodyTagSupport ; 31 32 37 public class IfTag extends BodyTagSupport 38 { 39 40 private String exists = null; 41 42 private String test = null; 43 44 boolean expressionResult; 45 46 public void setExists(String exists) 47 { 48 this.exists = exists; 49 } 50 51 public void setTest(String test) 52 { 53 this.test = test; 54 } 55 56 private void pushResult(boolean result) 57 { 58 ServletRequest request = pageContext.getRequest(); 59 Stack stack = (Stack ) request.getAttribute("ifThenStack"); 60 if (null == stack) 61 { 62 stack = new Stack (); 63 request.setAttribute("ifThenStack", stack); 64 } 65 stack.push(new Boolean (result)); 66 } 67 68 public int doStartTag() throws JspException 69 { 70 if (null != test) 71 { 72 if ("true".equals(test)) 73 { 74 pushResult(true); 75 return EVAL_BODY_INCLUDE; 76 } 77 else 78 { 79 pushResult(false); 80 return SKIP_BODY; 81 } 82 } 83 else if (null != exists) 84 { 85 if (exists.length()>0 ) 86 { 87 pushResult(true); 88 return EVAL_BODY_INCLUDE; 89 } 90 else 91 { 92 pushResult(false); 93 return SKIP_BODY; 94 } 95 96 } 97 else 98 { 99 throw new JspException ("illegal attribute for tag 'if'"); 100 } 101 } 102 } 103 | Popular Tags |