TitleContentTag.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: TitleContentTag.java,v 1.12 2004/03/19 14:31:50 sauthieg Exp $
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 // ----------------------------------------------------- Constants
00044 
00045 // ----------------------------------------------------- Instance Variables
00046 
00047     protected String m_Body = null;
00048 
00049 // ------------------------------------------------------------- Properties
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 // --------------------------------------------------------- Public Methods
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 // -------------------------------------------------------- Protected Methods
00138 
00139     protected void render(JspWriter out)
00140         throws IOException, JspException {
00141         String sImageDisplay = null;
00142         String sTitleDisplay = null;
00143         ArrayList alTomThumb = null;
00144         //String sThumbDisplay = null;
00145 
00146         // Prepare WhereAreYou infos
00147         if (isUsingWhere()) {
00148             TreeControlNode oNode = getSelectedTreeControlNode();
00149             if (oNode != null) {
00150                 sImageDisplay = getImagesRoot() + "/" + oNode.getIcon();
00151                 sTitleDisplay = oNode.getLabel();
00152                 // Prepare label of parent node
00153                 if (isUsingParent() == true) {
00154                     TreeControlNode oParent = oNode.getParent();
00155                     if (oParent != null) {
00156                         sTitleDisplay = oParent.getLabel() + " : " + oNode.getLabel();
00157                     }
00158                 }
00159                 // Prepare Tom Thumb list
00160                 if (isTomThumb() == true) {
00161                     alTomThumb = getTomThumbList(oNode);
00162                 }
00163             }
00164         }
00165         // Prepare parameters
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         // Display
00177         if ((sImageDisplay != null) || (sTitleDisplay != null)) {
00178             String sTomThumb = null;
00179             // Build Tom Thumb display
00180             if (alTomThumb != null) {
00181                 if (alTomThumb.size() > 0) {
00182                     sTomThumb = renderTomThumb(alTomThumb);
00183                 }
00184             }
00185             // Display Tom Thumb
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                 // No Tom Thumb to display
00197                 out.println(
00198                     "<table height=\"30\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
00199             }
00200             // Display icon
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\">&nbsp;</td>");
00207             }
00208             // Display title
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         // Loop on each parent
00262         do {
00263             // Get parent
00264             oParent = oNode.getParent();
00265             // Verify parent exist
00266             if (oParent != null) {
00267                 // Verify parent is not empty or root node
00268                 if (("ROOT-NODE".equalsIgnoreCase(oParent.getName()) == false) && (oParent.getLabel() != null)) {
00269                     // Get Thumb infos
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                     // Add to thumb's list
00279                     alTomThumb.add(oThumb);
00280                 }
00281             }
00282             // Next parent
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 }

Generated on Tue Feb 15 15:05:34 2005 for JOnAS by  doxygen 1.3.9.1