1 package org.roller.presentation.tags; 2 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.apache.struts.taglib.logic.IterateTag; 6 7 import java.io.IOException ; 8 9 import javax.servlet.jsp.JspException ; 10 import javax.servlet.jsp.JspWriter ; 11 import javax.servlet.jsp.tagext.Tag ; 12 13 14 39 public class RowTag extends org.apache.struts.taglib.html.BaseHandlerTag 40 { 41 private static Log mLogger = LogFactory.getFactory() 43 .getInstance(RowTag.class); 44 protected final static String QUOTE = "\""; 45 46 49 protected String oddColor = null; 50 51 54 protected String evenColor = null; 55 56 59 protected String oddStyleClass = null; 60 61 64 protected String evenStyleClass = null; 65 66 69 protected String align = null; 70 71 74 protected String valign = null; 75 76 80 public String getOddColor() 81 { 82 return (this.oddColor); 83 } 84 85 90 public void setOddColor(String color) 91 { 92 this.oddColor = color; 93 } 94 95 99 public String getEvenColor() 100 { 101 return (this.evenColor); 102 } 103 104 109 public void setEvenColor(String color) 110 { 111 this.evenColor = color; 112 } 113 114 118 public String getOddStyleClass() 119 { 120 return (this.oddStyleClass); 121 } 122 123 128 public void setOddStyleClass(String styleClass) 129 { 130 this.oddStyleClass = styleClass; 131 } 132 133 137 public String getEvenStyleClass() 138 { 139 return (this.evenStyleClass); 140 } 141 142 147 public void setEvenStyleClass(String styleClass) 148 { 149 this.evenStyleClass = styleClass; 150 } 151 152 156 public String getAlign() 157 { 158 return (this.align); 159 } 160 161 166 public void setAlign(String align) 167 { 168 this.align = align; 169 } 170 171 175 public String getValign() 176 { 177 return (this.valign); 178 } 179 180 185 public void setValign(String valign) 186 { 187 this.valign = valign; 188 } 189 190 192 197 public int doStartTag() throws JspException 198 { 199 return EVAL_BODY_BUFFERED; 201 } 202 203 208 public int doEndTag() throws JspException 209 { 210 StringBuffer buffer = new StringBuffer (); 211 212 213 buffer.append("<tr"); 215 216 217 prepareAttributes(buffer); 219 220 buffer.append(">"); 221 222 if (bodyContent != null) 224 { 225 buffer.append(bodyContent.getString().trim()); 226 } 227 228 buffer.append("</tr>"); 229 230 JspWriter writer = pageContext.getOut(); 232 233 try 234 { 235 writer.print(buffer.toString()); 236 } 237 catch (IOException e) 238 { 239 mLogger.error("ERROR in tag", e); 240 throw new JspException ("Exception in RowTag doEndTag():" + 241 e.toString()); 242 } 243 244 return EVAL_PAGE; 245 } 246 247 250 protected void prepareAttributes(StringBuffer buffer) 251 { 252 boolean evenNumber = ((getRowNumber() % 2) == 0) 254 ? true : false; 255 256 257 buffer.append(prepareBgcolor(evenNumber)); 259 260 261 buffer.append(prepareClass(evenNumber)); 263 264 265 buffer.append(prepareAttribute("align", align)); 267 268 269 buffer.append(prepareAttribute("valign", valign)); 271 272 273 buffer.append(prepareEventHandlers()); 275 276 try 277 { 278 buffer.append(prepareStyles()); 280 } 281 catch (Exception e) 282 { 283 mLogger.error("Unexpected exception", e); 284 } 285 } 286 287 290 protected String prepareAttribute(String attribute, String value) 291 { 292 return (value == null) 293 ? "" : " " + attribute + "=" + QUOTE + value + QUOTE; 294 } 295 296 303 protected String prepareBgcolor(boolean evenNumber) 304 { 305 if (evenNumber) 306 { 307 return prepareAttribute("bgcolor", evenColor); 308 } 309 else 310 { 311 return prepareAttribute("bgcolor", oddColor); 312 } 313 } 314 315 322 protected String prepareClass(boolean evenNumber) 323 { 324 if (evenNumber) 325 { 326 return prepareAttribute("class", evenStyleClass); 327 } 328 else 329 { 330 return prepareAttribute("class", oddStyleClass); 331 } 332 } 333 334 337 protected int getRowNumber() 338 { 339 Tag tag = findAncestorWithClass(this, IterateTag.class); 341 342 if (tag == null) 343 { 344 return 1; 345 } 346 347 IterateTag iterator = (IterateTag) tag; 349 350 return iterator.getIndex() + 1; 352 } 353 354 357 public void release() 358 { 359 super.release(); 360 361 oddColor = null; 362 evenColor = null; 363 oddStyleClass = null; 364 evenStyleClass = null; 365 align = null; 366 valign = null; 367 } 368 } | Popular Tags |