KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > taglib > TitleContentTag


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: TitleContentTag.java,v 1.12 2004/03/19 14:31:50 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.taglib;
27
28 import java.io.IOException JavaDoc;
29 import java.util.ArrayList JavaDoc;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33 import javax.servlet.jsp.JspException JavaDoc;
34 import javax.servlet.jsp.JspWriter JavaDoc;
35
36
37
38 /**
39  * @author Michel-Ange ANTON
40  */

41 public class TitleContentTag extends WhereAreYouTag {
42
43 // ----------------------------------------------------- Constants
44

45 // ----------------------------------------------------- Instance Variables
46

47     protected String JavaDoc m_Body = null;
48
49 // ------------------------------------------------------------- Properties
50
private String JavaDoc image = null;
51     private String JavaDoc title = null;
52     private boolean usingParent = false;
53     private boolean tomThumb = false;
54     private boolean tomThumbIcons = false;
55
56     public String JavaDoc getImage() {
57         return image;
58     }
59
60     public void setImage(String JavaDoc image) {
61         this.image = image;
62     }
63
64     public String JavaDoc getTitle() {
65         return title;
66     }
67
68     public void setTitle(String JavaDoc 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 // --------------------------------------------------------- Public Methods
97

98     /**
99      * Render this instant actions control.
100      *
101      * @return Constant EVAL_PAGE
102      * @exception JspException if a processing error occurs
103      */

104     public int doEndTag()
105         throws JspException JavaDoc {
106         JspWriter JavaDoc out = pageContext.getOut();
107         try {
108             render(out);
109         }
110         catch (IOException JavaDoc e) {
111             throw new JspException JavaDoc(e);
112         }
113         return (EVAL_PAGE);
114     }
115
116     public int doAfterBody()
117         throws JspException JavaDoc {
118         String JavaDoc 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     /**
129      * Release all state information set by this tag.
130      */

131     public void release() {
132         this.image = null;
133         this.title = null;
134         m_Body = null;
135     }
136
137 // -------------------------------------------------------- Protected Methods
138

139     protected void render(JspWriter JavaDoc out)
140         throws IOException JavaDoc, JspException JavaDoc {
141         String JavaDoc sImageDisplay = null;
142         String JavaDoc sTitleDisplay = null;
143         ArrayList JavaDoc alTomThumb = null;
144         //String sThumbDisplay = null;
145

146         // Prepare WhereAreYou infos
147
if (isUsingWhere()) {
148             TreeControlNode oNode = getSelectedTreeControlNode();
149             if (oNode != null) {
150                 sImageDisplay = getImagesRoot() + "/" + oNode.getIcon();
151                 sTitleDisplay = oNode.getLabel();
152                 // Prepare label of parent node
153
if (isUsingParent() == true) {
154                     TreeControlNode oParent = oNode.getParent();
155                     if (oParent != null) {
156                         sTitleDisplay = oParent.getLabel() + " : " + oNode.getLabel();
157                     }
158                 }
159                 // Prepare Tom Thumb list
160
if (isTomThumb() == true) {
161                     alTomThumb = getTomThumbList(oNode);
162                 }
163             }
164         }
165         // Prepare parameters
166
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         // Display
177
if ((sImageDisplay != null) || (sTitleDisplay != null)) {
178             String JavaDoc sTomThumb = null;
179             // Build Tom Thumb display
180
if (alTomThumb != null) {
181                 if (alTomThumb.size() > 0) {
182                     sTomThumb = renderTomThumb(alTomThumb);
183                 }
184             }
185             // Display Tom Thumb
186
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                 // No Tom Thumb to display
197
out.println(
198                     "<table height=\"30\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
199             }
200             // Display icon
201
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\">&nbsp;</td>");
207             }
208             // Display title
209
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 JavaDoc renderTomThumb(ArrayList JavaDoc p_TomThumb) {
220         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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 JavaDoc getTomThumbList(TreeControlNode p_Node) {
256         TreeControlNode oParent;
257         ItemTomThumb oThumb;
258
259         TreeControlNode oNode = p_Node;
260         ArrayList JavaDoc alTomThumb = new ArrayList JavaDoc();
261         // Loop on each parent
262
do {
263             // Get parent
264
oParent = oNode.getParent();
265             // Verify parent exist
266
if (oParent != null) {
267                 // Verify parent is not empty or root node
268
if (("ROOT-NODE".equalsIgnoreCase(oParent.getName()) == false) && (oParent.getLabel() != null)) {
269                     // Get Thumb infos
270
oThumb = new ItemTomThumb();
271                     oThumb.setLabel(oParent.getLabel());
272                     oThumb.setIcon(oParent.getIcon());
273                     if (oParent.getAction() != null) {
274                         oThumb.setLink(((HttpServletResponse JavaDoc) pageContext.getResponse()).encodeURL(((
275                             HttpServletRequest JavaDoc) pageContext.getRequest()).getContextPath() + "/"
276                             + oParent.getAction()));
277                     }
278                     // Add to thumb's list
279
alTomThumb.add(oThumb);
280                 }
281             }
282             // Next parent
283
oNode = oParent;
284         }
285         while (oParent != null);
286
287         return alTomThumb;
288     }
289
290     class ItemTomThumb {
291         private String JavaDoc label = null;
292         private String JavaDoc link = null;
293         private String JavaDoc icon = null;
294
295         public ItemTomThumb() {
296
297         }
298
299         public ItemTomThumb(String JavaDoc p_Label, String JavaDoc p_Link, String JavaDoc p_Icon) {
300             setLabel(p_Label);
301             setLink(p_Link);
302             setIcon(p_Icon);
303         }
304
305         public String JavaDoc getLabel() {
306             return label;
307         }
308
309         public void setLabel(String JavaDoc label) {
310             this.label = label;
311         }
312
313         public String JavaDoc getLink() {
314             return link;
315         }
316
317         public void setLink(String JavaDoc link) {
318             this.link = link;
319         }
320
321         public String JavaDoc getIcon() {
322             return icon;
323         }
324
325         public void setIcon(String JavaDoc icon) {
326             this.icon = icon;
327         }
328
329     }
330 }
331
Popular Tags