1 17 18 package com.finalist.jag.taglib; 19 20 21 22 import com.finalist.jag.*; 23 import com.finalist.jag.taglib.util.RequestUtil; 24 25 import java.util.*; 26 27 28 35 public class CounterTag extends TagBodySupport { 36 37 38 private String name = null; 39 40 41 private String odd = "false"; 42 43 44 private String output = null; 45 46 47 protected boolean body = false; 48 49 50 protected int counter = 0; 51 52 54 61 public String getName() { 62 return (this.name); 63 } 64 65 72 public void setName(String name) { 73 this.name = name; 74 } 75 76 83 public String getOdd() { 84 return (this.odd); 85 } 86 87 94 public void setOdd(String odd) { 95 this.odd = odd; 96 } 97 98 105 public String getOutput() { 106 return (this.output); 107 } 108 109 116 public void setOutput(String output) { 117 this.output = output; 118 } 119 128 public int doStartTag() throws JagException { 129 130 SessionContext session = getPageContext().getSessionContext(); 131 132 try { 133 String s = (String ) getPageContext().getAttribute(name); 134 int n = new Integer (s).intValue(); 135 136 body = n % 2 == 1; 137 138 if (odd != null && odd.equalsIgnoreCase("false")) { 139 body = !body; 140 } 141 142 if (output != null && output.equalsIgnoreCase("true")) { 143 getWriter().print(s); 144 } 145 } catch (Exception e) { 146 new JagException(e.getMessage()); 147 } 148 149 return (EVAL_PAGE); 150 } 151 152 161 public int doAfterBodyTag() throws JagException { 162 163 return (body && (counter++ < 1)) 164 ? (EVAL_BODY_TAG) 165 : (SKIP_BODY); 166 } 167 } 168 | Popular Tags |