1 25 26 package org.objectweb.jonas.webapp.taglib; 27 28 import java.io.IOException ; 29 import java.util.ArrayList ; 30 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 import javax.servlet.jsp.JspException ; 34 import javax.servlet.jsp.JspWriter ; 35 36 37 38 41 public class TitleContentTag extends WhereAreYouTag { 42 43 45 47 protected String m_Body = null; 48 49 private String image = null; 51 private String title = null; 52 private boolean usingParent = false; 53 private boolean tomThumb = false; 54 private boolean tomThumbIcons = false; 55 56 public String getImage() { 57 return image; 58 } 59 60 public void setImage(String image) { 61 this.image = image; 62 } 63 64 public String getTitle() { 65 return title; 66 } 67 68 public void setTitle(String title) { 69 this.title = title; 70 } 71 72 public boolean isUsingParent() { 73 return usingParent; 74 } 75 76 public void setUsingParent(boolean usingParent) { 77 this.usingParent = usingParent; 78 } 79 80 public boolean isTomThumb() { 81 return tomThumb; 82 } 83 84 public void setTomThumb(boolean tomThumb) { 85 this.tomThumb = tomThumb; 86 } 87 88 public boolean isTomThumbIcons() { 89 return tomThumbIcons; 90 } 91 92 public void setTomThumbIcons(boolean tomThumbIcons) { 93 this.tomThumbIcons = tomThumbIcons; 94 } 95 96 98 104 public int doEndTag() 105 throws JspException { 106 JspWriter out = pageContext.getOut(); 107 try { 108 render(out); 109 } 110 catch (IOException e) { 111 throw new JspException (e); 112 } 113 return (EVAL_PAGE); 114 } 115 116 public int doAfterBody() 117 throws JspException { 118 String sBody = bodyContent.getString(); 119 if (sBody != null) { 120 sBody = sBody.trim(); 121 if (sBody.length() > 0) { 122 this.m_Body = sBody; 123 } 124 } 125 return (SKIP_BODY); 126 } 127 128 131 public void release() { 132 this.image = null; 133 this.title = null; 134 m_Body = null; 135 } 136 137 139 protected void render(JspWriter out) 140 throws IOException , JspException { 141 String sImageDisplay = null; 142 String sTitleDisplay = null; 143 ArrayList alTomThumb = null; 144 146 if (isUsingWhere()) { 148 TreeControlNode oNode = getSelectedTreeControlNode(); 149 if (oNode != null) { 150 sImageDisplay = getImagesRoot() + "/" + oNode.getIcon(); 151 sTitleDisplay = oNode.getLabel(); 152 if (isUsingParent() == true) { 154 TreeControlNode oParent = oNode.getParent(); 155 if (oParent != null) { 156 sTitleDisplay = oParent.getLabel() + " : " + oNode.getLabel(); 157 } 158 } 159 if (isTomThumb() == true) { 161 alTomThumb = getTomThumbList(oNode); 162 } 163 } 164 } 165 if (image != null) { 167 sImageDisplay = image; 168 } 169 if (title != null) { 170 sTitleDisplay = title; 171 } 172 if (m_Body != null) { 173 sTitleDisplay = m_Body; 174 m_Body = null; 175 } 176 if ((sImageDisplay != null) || (sTitleDisplay != null)) { 178 String sTomThumb = null; 179 if (alTomThumb != null) { 181 if (alTomThumb.size() > 0) { 182 sTomThumb = renderTomThumb(alTomThumb); 183 } 184 } 185 if (sTomThumb != null) { 187 out.println( 188 "<table height=\"50\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"); 189 out.print("<tr valign=\"top\">"); 190 out.print("<td class=\"contentTitleTomThumb\" colspan=\"3\">"); 191 out.print(sTomThumb); 192 out.print("</td>"); 193 out.println("</tr>"); 194 } 195 else { 196 out.println( 198 "<table height=\"30\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"); 199 } 200 out.println("<tr valign=\"top\">"); 202 if (sImageDisplay != null) { 203 out.print("<td width=\"1%\" valign=\"top\" class=\"contentTitleImage\"><img SRC=\""); 204 out.print(sImageDisplay); 205 out.println("\" border=\"0\"></td>"); 206 out.println("<td width=\"1%\" valign=\"top\" class=\"contentTitleImage\"> </td>"); 207 } 208 if (sTitleDisplay != null) { 210 out.print("<td class=\"contentTitle\">"); 211 out.print(sTitleDisplay); 212 out.println("</td>"); 213 } 214 out.println("</tr>"); 215 out.println("</table>"); 216 } 217 } 218 219 protected String renderTomThumb(ArrayList p_TomThumb) { 220 StringBuffer sb = new StringBuffer (); 221 ItemTomThumb oThumb; 222 for (int i = p_TomThumb.size() - 1; i >= 0; i--) { 223 oThumb = (ItemTomThumb) p_TomThumb.get(i); 224 if (oThumb.getLink() != null) { 225 sb.append("<a HREF=\""); 226 sb.append(oThumb.getLink()); 227 sb.append("\" class=\"contentTitleTomThumb\">"); 228 if ((isTomThumbIcons()== true) && (oThumb.getIcon() != null)) { 229 sb.append("<img SRC=\""); 230 sb.append(getImagesRoot()); 231 sb.append("/"); 232 sb.append(oThumb.getIcon()); 233 sb.append("\" border=\"0\"> "); 234 } 235 sb.append(oThumb.getLabel()); 236 sb.append("</a>"); 237 } 238 else { 239 if ((isTomThumbIcons()== true) && (oThumb.getIcon() != null)) { 240 sb.append("<img SRC=\""); 241 sb.append(oThumb.getIcon()); 242 sb.append("\" border=\"0\"> "); 243 } 244 sb.append("<span class=\"contentTitleTomThumbNotLink\">"); 245 sb.append(oThumb.getLabel()); 246 sb.append("</span>"); 247 } 248 if (i > 0) { 249 sb.append(" > "); 250 } 251 } 252 return sb.toString(); 253 } 254 255 protected ArrayList getTomThumbList(TreeControlNode p_Node) { 256 TreeControlNode oParent; 257 ItemTomThumb oThumb; 258 259 TreeControlNode oNode = p_Node; 260 ArrayList alTomThumb = new ArrayList (); 261 do { 263 oParent = oNode.getParent(); 265 if (oParent != null) { 267 if (("ROOT-NODE".equalsIgnoreCase(oParent.getName()) == false) && (oParent.getLabel() != null)) { 269 oThumb = new ItemTomThumb(); 271 oThumb.setLabel(oParent.getLabel()); 272 oThumb.setIcon(oParent.getIcon()); 273 if (oParent.getAction() != null) { 274 oThumb.setLink(((HttpServletResponse ) pageContext.getResponse()).encodeURL((( 275 HttpServletRequest ) pageContext.getRequest()).getContextPath() + "/" 276 + oParent.getAction())); 277 } 278 alTomThumb.add(oThumb); 280 } 281 } 282 oNode = oParent; 284 } 285 while (oParent != null); 286 287 return alTomThumb; 288 } 289 290 class ItemTomThumb { 291 private String label = null; 292 private String link = null; 293 private String icon = null; 294 295 public ItemTomThumb() { 296 297 } 298 299 public ItemTomThumb(String p_Label, String p_Link, String p_Icon) { 300 setLabel(p_Label); 301 setLink(p_Link); 302 setIcon(p_Icon); 303 } 304 305 public String getLabel() { 306 return label; 307 } 308 309 public void setLabel(String label) { 310 this.label = label; 311 } 312 313 public String getLink() { 314 return link; 315 } 316 317 public void setLink(String link) { 318 this.link = link; 319 } 320 321 public String getIcon() { 322 return icon; 323 } 324 325 public void setIcon(String icon) { 326 this.icon = icon; 327 } 328 329 } 330 } 331 | Popular Tags |