1 21 22 package org.opensubsystems.core.www; 23 24 import java.util.Stack ; 25 26 import javax.servlet.jsp.JspException ; 27 28 38 public class BlockElementTag extends PageElementCacheTag 39 { 40 42 45 public static final String CURRENT_ELEMENT_ID = "currentelementid"; 46 47 50 public static final String DIV_BLOCK_ELEMENT = "div"; 51 52 55 public static final String SPAN_BLOCK_ELEMENT = "span"; 56 57 59 62 private static final long serialVersionUID = -5162089287834734148L; 63 64 67 protected String m_strCssclass; 68 69 72 protected String m_strStyle; 73 74 77 protected String m_strType; 78 79 82 protected String m_strIdSuffix; 83 84 90 protected String m_strRelatedIds; 91 92 95 private String m_strOriginalId; 96 97 100 private boolean m_bIdStored; 101 102 104 110 public BlockElementTag( 111 String strCssclass, 112 String strType 113 ) 114 { 115 super(); 116 117 m_strCssclass = strCssclass; 119 m_strStyle = ""; 120 m_strType = strType; 121 m_strIdSuffix = ""; 122 m_bIdStored = false; 123 m_strRelatedIds = null; 127 } 128 129 131 134 public int doStartTag( 135 ) throws JspException 136 { 137 StringBuffer sbHtml = new StringBuffer (); 138 139 adjustId(); 140 141 if ((m_strType == null) || (m_strType.length() == 0)) 142 { 143 m_strType = DIV_BLOCK_ELEMENT; 144 } 145 146 sbHtml.append("<"); 148 sbHtml.append(m_strType); 149 sbHtml.append(" "); 150 if ((m_strId != null) && (m_strId.length() > 0)) 151 { 152 sbHtml.append(" id=\""); 153 sbHtml.append(m_strId); 154 if ((m_strIdSuffix != null) && (m_strIdSuffix.length() > 0)) 155 { 156 sbHtml.append(m_strIdSuffix); 157 } 158 sbHtml.append("\""); 159 } 160 if ((m_strCssclass != null) && (m_strCssclass.length() > 0)) 161 { 162 sbHtml.append(" class=\""); 163 sbHtml.append(m_strCssclass); 164 sbHtml.append("\""); 165 } 166 if ((m_strStyle != null) && (m_strStyle.length() > 0)) 167 { 168 sbHtml.append(" style=\""); 169 sbHtml.append(m_strStyle); 170 sbHtml.append("\""); 171 } 172 sbHtml.append(">"); 173 174 pushCurrentId(); 175 TagUtils.write(pageContext, sbHtml.toString()); 176 177 return (EVAL_BODY_INCLUDE); 178 } 179 180 183 public int doEndTag( 184 ) throws JspException 185 { 186 StringBuffer sbHtml = new StringBuffer (); 188 189 sbHtml.append("</"); 190 sbHtml.append(m_strType); 191 sbHtml.append(">"); 192 193 popCurrentId(); 194 TagUtils.write(pageContext, sbHtml.toString()); 195 196 restoreId(); 197 198 return (EVAL_PAGE); 199 } 200 201 204 public String getCssclass( 205 ) 206 { 207 return m_strCssclass; 208 } 209 210 213 public String getType( 214 ) 215 { 216 return m_strType; 217 } 218 219 222 public String getStyle() 223 { 224 return m_strStyle; 225 } 226 227 230 public void setCssclass( 231 String strCssclass 232 ) 233 { 234 m_strCssclass = strCssclass; 235 } 236 237 240 public void setType( 241 String strType 242 ) 243 { 244 m_strType = strType; 245 } 246 247 250 public void setStyle( 251 String style 252 ) 253 { 254 m_strStyle = style; 255 } 256 257 261 public String getRelatedids( 262 ) 263 { 264 return m_strRelatedIds; 265 } 266 267 271 public void setRelatedids( 272 String strRelatedIds 273 ) 274 { 275 m_strRelatedIds = strRelatedIds; 276 } 277 278 282 public void setRelatedids( 283 boolean bRelatedIds 284 ) 285 { 286 m_strRelatedIds = Boolean.toString(bRelatedIds); 287 } 288 289 292 public boolean isRelatedIdsTag( 293 ) 294 { 295 return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strRelatedIds)) 296 || ("1".equals(m_strRelatedIds))); 297 } 298 299 301 305 protected void pushCurrentId( 306 ) 307 { 308 Object objTemp; 309 Stack ids; 310 311 if ((m_strId != null) && (m_strId.length() > 0) && (!m_bIdStored)) 312 { 313 objTemp = pageContext.getAttribute(CURRENT_ELEMENT_ID); 315 if (objTemp == null) 316 { 317 ids = new Stack (); 318 pageContext.setAttribute(CURRENT_ELEMENT_ID, ids); 319 } 320 else 321 { 322 ids = (Stack )objTemp; 323 } 324 ids.push(m_strId); 325 m_bIdStored = true; 326 } 327 } 328 329 335 protected void popCurrentId( 336 ) throws JspException 337 { 338 Object objTemp; 339 Stack ids; 340 341 if (m_bIdStored) 342 { 343 objTemp = pageContext.getAttribute(CURRENT_ELEMENT_ID); 345 if (objTemp == null) 346 { 347 throw new JspException ("Cannot find element " + CURRENT_ELEMENT_ID 348 + " in page context even though it should be there."); 349 } 350 else 351 { 352 ids = (Stack )objTemp; 353 } 354 ids.pop(); 355 m_bIdStored = false; 356 } 357 } 358 359 366 protected String getCurrentId( 367 ) 368 { 369 Object objTemp; 370 Stack ids; 371 String strCurrentId = ""; 372 373 objTemp = pageContext.getAttribute(CURRENT_ELEMENT_ID); 375 if (objTemp != null) 376 { 377 ids = (Stack )objTemp; 378 if (!ids.empty()) 379 { 380 strCurrentId = (String )ids.peek(); 381 } 382 } 383 384 return strCurrentId; 385 } 386 387 391 protected void setStoredId( 392 boolean bIdStored 393 ) 394 { 395 m_bIdStored = bIdStored; 396 } 397 398 404 protected void adjustId( 405 ) 406 { 407 if ((m_strRelatedIds != null) && (isRelatedIdsTag())) 408 { 409 StringBuffer buffer = new StringBuffer (getCurrentId()); 410 411 buffer.append(m_strId); 412 413 m_strOriginalId = m_strId; 414 m_strId = buffer.toString(); 415 } 416 } 417 418 421 protected void restoreId( 422 ) 423 { 424 if (m_strOriginalId != null) 425 { 426 m_strId = m_strOriginalId; 427 } 428 } 429 } 430 | Popular Tags |