00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 package org.objectweb.jonas.webapp.taglib;
00027
00028 import java.io.IOException;
00029 import java.util.ArrayList;
00030
00031 import javax.servlet.http.HttpServletRequest;
00032 import javax.servlet.http.HttpServletResponse;
00033 import javax.servlet.jsp.JspException;
00034 import javax.servlet.jsp.JspWriter;
00035
00036
00037
00041 public class TitleContentTag extends WhereAreYouTag {
00042
00043
00044
00045
00046
00047 protected String m_Body = null;
00048
00049
00050 private String image = null;
00051 private String title = null;
00052 private boolean usingParent = false;
00053 private boolean tomThumb = false;
00054 private boolean tomThumbIcons = false;
00055
00056 public String getImage() {
00057 return image;
00058 }
00059
00060 public void setImage(String image) {
00061 this.image = image;
00062 }
00063
00064 public String getTitle() {
00065 return title;
00066 }
00067
00068 public void setTitle(String title) {
00069 this.title = title;
00070 }
00071
00072 public boolean isUsingParent() {
00073 return usingParent;
00074 }
00075
00076 public void setUsingParent(boolean usingParent) {
00077 this.usingParent = usingParent;
00078 }
00079
00080 public boolean isTomThumb() {
00081 return tomThumb;
00082 }
00083
00084 public void setTomThumb(boolean tomThumb) {
00085 this.tomThumb = tomThumb;
00086 }
00087
00088 public boolean isTomThumbIcons() {
00089 return tomThumbIcons;
00090 }
00091
00092 public void setTomThumbIcons(boolean tomThumbIcons) {
00093 this.tomThumbIcons = tomThumbIcons;
00094 }
00095
00096
00097
00104 public int doEndTag()
00105 throws JspException {
00106 JspWriter out = pageContext.getOut();
00107 try {
00108 render(out);
00109 }
00110 catch (IOException e) {
00111 throw new JspException(e);
00112 }
00113 return (EVAL_PAGE);
00114 }
00115
00116 public int doAfterBody()
00117 throws JspException {
00118 String sBody = bodyContent.getString();
00119 if (sBody != null) {
00120 sBody = sBody.trim();
00121 if (sBody.length() > 0) {
00122 this.m_Body = sBody;
00123 }
00124 }
00125 return (SKIP_BODY);
00126 }
00127
00131 public void release() {
00132 this.image = null;
00133 this.title = null;
00134 m_Body = null;
00135 }
00136
00137
00138
00139 protected void render(JspWriter out)
00140 throws IOException, JspException {
00141 String sImageDisplay = null;
00142 String sTitleDisplay = null;
00143 ArrayList alTomThumb = null;
00144
00145
00146
00147 if (isUsingWhere()) {
00148 TreeControlNode oNode = getSelectedTreeControlNode();
00149 if (oNode != null) {
00150 sImageDisplay = getImagesRoot() + "/" + oNode.getIcon();
00151 sTitleDisplay = oNode.getLabel();
00152
00153 if (isUsingParent() == true) {
00154 TreeControlNode oParent = oNode.getParent();
00155 if (oParent != null) {
00156 sTitleDisplay = oParent.getLabel() + " : " + oNode.getLabel();
00157 }
00158 }
00159
00160 if (isTomThumb() == true) {
00161 alTomThumb = getTomThumbList(oNode);
00162 }
00163 }
00164 }
00165
00166 if (image != null) {
00167 sImageDisplay = image;
00168 }
00169 if (title != null) {
00170 sTitleDisplay = title;
00171 }
00172 if (m_Body != null) {
00173 sTitleDisplay = m_Body;
00174 m_Body = null;
00175 }
00176
00177 if ((sImageDisplay != null) || (sTitleDisplay != null)) {
00178 String sTomThumb = null;
00179
00180 if (alTomThumb != null) {
00181 if (alTomThumb.size() > 0) {
00182 sTomThumb = renderTomThumb(alTomThumb);
00183 }
00184 }
00185
00186 if (sTomThumb != null) {
00187 out.println(
00188 "<table height=\"50\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
00189 out.print("<tr valign=\"top\">");
00190 out.print("<td class=\"contentTitleTomThumb\" colspan=\"3\">");
00191 out.print(sTomThumb);
00192 out.print("</td>");
00193 out.println("</tr>");
00194 }
00195 else {
00196
00197 out.println(
00198 "<table height=\"30\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
00199 }
00200
00201 out.println("<tr valign=\"top\">");
00202 if (sImageDisplay != null) {
00203 out.print("<td width=\"1%\" valign=\"top\" class=\"contentTitleImage\"><img src=\"");
00204 out.print(sImageDisplay);
00205 out.println("\" border=\"0\"></td>");
00206 out.println("<td width=\"1%\" valign=\"top\" class=\"contentTitleImage\"> </td>");
00207 }
00208
00209 if (sTitleDisplay != null) {
00210 out.print("<td class=\"contentTitle\">");
00211 out.print(sTitleDisplay);
00212 out.println("</td>");
00213 }
00214 out.println("</tr>");
00215 out.println("</table>");
00216 }
00217 }
00218
00219 protected String renderTomThumb(ArrayList p_TomThumb) {
00220 StringBuffer sb = new StringBuffer();
00221 ItemTomThumb oThumb;
00222 for (int i = p_TomThumb.size() - 1; i >= 0; i--) {
00223 oThumb = (ItemTomThumb) p_TomThumb.get(i);
00224 if (oThumb.getLink() != null) {
00225 sb.append("<a href=\"");
00226 sb.append(oThumb.getLink());
00227 sb.append("\" class=\"contentTitleTomThumb\">");
00228 if ((isTomThumbIcons()== true) && (oThumb.getIcon() != null)) {
00229 sb.append("<img src=\"");
00230 sb.append(getImagesRoot());
00231 sb.append("/");
00232 sb.append(oThumb.getIcon());
00233 sb.append("\" border=\"0\"> ");
00234 }
00235 sb.append(oThumb.getLabel());
00236 sb.append("</a>");
00237 }
00238 else {
00239 if ((isTomThumbIcons()== true) && (oThumb.getIcon() != null)) {
00240 sb.append("<img src=\"");
00241 sb.append(oThumb.getIcon());
00242 sb.append("\" border=\"0\"> ");
00243 }
00244 sb.append("<span class=\"contentTitleTomThumbNotLink\">");
00245 sb.append(oThumb.getLabel());
00246 sb.append("</span>");
00247 }
00248 if (i > 0) {
00249 sb.append(" > ");
00250 }
00251 }
00252 return sb.toString();
00253 }
00254
00255 protected ArrayList getTomThumbList(TreeControlNode p_Node) {
00256 TreeControlNode oParent;
00257 ItemTomThumb oThumb;
00258
00259 TreeControlNode oNode = p_Node;
00260 ArrayList alTomThumb = new ArrayList();
00261
00262 do {
00263
00264 oParent = oNode.getParent();
00265
00266 if (oParent != null) {
00267
00268 if (("ROOT-NODE".equalsIgnoreCase(oParent.getName()) == false) && (oParent.getLabel() != null)) {
00269
00270 oThumb = new ItemTomThumb();
00271 oThumb.setLabel(oParent.getLabel());
00272 oThumb.setIcon(oParent.getIcon());
00273 if (oParent.getAction() != null) {
00274 oThumb.setLink(((HttpServletResponse) pageContext.getResponse()).encodeURL(((
00275 HttpServletRequest) pageContext.getRequest()).getContextPath() + "/"
00276 + oParent.getAction()));
00277 }
00278
00279 alTomThumb.add(oThumb);
00280 }
00281 }
00282
00283 oNode = oParent;
00284 }
00285 while (oParent != null);
00286
00287 return alTomThumb;
00288 }
00289
00290 class ItemTomThumb {
00291 private String label = null;
00292 private String link = null;
00293 private String icon = null;
00294
00295 public ItemTomThumb() {
00296
00297 }
00298
00299 public ItemTomThumb(String p_Label, String p_Link, String p_Icon) {
00300 setLabel(p_Label);
00301 setLink(p_Link);
00302 setIcon(p_Icon);
00303 }
00304
00305 public String getLabel() {
00306 return label;
00307 }
00308
00309 public void setLabel(String label) {
00310 this.label = label;
00311 }
00312
00313 public String getLink() {
00314 return link;
00315 }
00316
00317 public void setLink(String link) {
00318 this.link = link;
00319 }
00320
00321 public String getIcon() {
00322 return icon;
00323 }
00324
00325 public void setIcon(String icon) {
00326 this.icon = icon;
00327 }
00328
00329 }
00330 }