1 17 18 package com.finalist.jag.taglib; 19 20 21 import com.finalist.jag.*; 22 import com.finalist.jag.taglib.util.RequestUtil; 23 24 import java.util.*; 25 26 27 34 public class EqualTag extends TagBodySupport { 35 36 37 private String name = null; 38 39 40 private String property = null; 41 42 43 protected String parameter = null; 44 45 46 private String sensitive = null; 47 48 49 protected boolean equal = false; 50 51 52 protected int counter = 0; 53 54 protected String variable; 55 56 58 65 public String getName() { 66 return (this.name); 67 } 68 69 76 public void setName(String name) { 77 this.name = name; 78 } 79 80 87 public String getProperty() { 88 return (this.property); 89 } 90 91 98 public void setProperty(String property) { 99 this.property = property; 100 } 101 102 109 public String getParameter() { 110 return (this.parameter); 111 } 112 113 120 public void setParameter(String parameter) { 121 this.parameter = parameter; 122 } 123 124 125 public String getSensitive() { 126 return (this.sensitive); 127 } 128 129 public void setSensitive(String sensitive) { 130 this.sensitive = sensitive; 131 } 132 133 public String getVariable() { 134 return variable; 135 } 136 137 public void setVariable(String variable) { 138 this.variable = variable; 139 } 140 141 142 151 public int doStartTag() throws JagException { 152 153 String value = RequestUtil.lookupString(getPageContext(), name, property); 154 if (value == null) { 155 value = (String ) getPageContext().getAttribute(name); 156 } 157 158 if (value == null) { 159 value = ""; 160 } 161 162 if (sensitive != null && sensitive.equals("true")) { 163 value = value.toLowerCase(); 164 parameter = parameter.toLowerCase(); 165 } 166 167 if (variable != null) { 168 Object variableValue = getPageContext().getAttribute(variable); 169 170 if (variableValue == null) { 171 equal = false; 172 } else { 173 equal = (variableValue instanceof String ) ? 174 value.equals(((String ) variableValue)) : 175 ((Set) variableValue).contains(value); 176 } 177 178 } else { 179 StringTokenizer tokens = new StringTokenizer(parameter, ", "); 180 while (tokens.hasMoreTokens()) { 181 String token = tokens.nextToken().trim(); 182 equal = token.equals(value); 183 if (equal) { 184 break; 185 } 186 } 187 } 188 return (EVAL_PAGE); 189 } 190 191 200 public int doAfterBodyTag() throws JagException { 201 return (equal && (counter++ < 1)) ? (EVAL_BODY_TAG) : (SKIP_BODY); 202 } 203 } 204 205 206 | Popular Tags |