KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > libtags > TreeBrowserTag


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.libtags;
7
8 import java.io.IOException JavaDoc;
9 import java.util.*;
10
11 import javax.servlet.http.*;
12 import javax.servlet.jsp.*;
13 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
14
15 import org.apache.struts.Globals;
16 import org.apache.struts.action.Action;
17 import org.apache.struts.util.*;
18
19 import com.raptus.owxv3.LoggingManager;
20 import com.raptus.owxv3.api.*;
21 import com.raptus.owxv3.api.components.*;
22 import com.raptus.owxv3.modules.base.*;
23 import com.raptus.owxv3.modules.categories.*;
24
25 /**
26  * <hr>
27  * <table width="100%" border="0">
28  * <tr>
29  * <td width="24%"><b>Filename</b></td><td width="76%">TreeBrowserTag.java</td>
30  * </tr>
31  * <tr>
32  * <td width="24%"><b>Author</b></td><td width="76%">Guy Zuercher</td>
33  * </tr>
34  * <tr>
35  * <td width="24%"><b>Date</b></td><td width="76%">13th of March 2003</td>
36  * </tr>
37  * </table>
38  * <hr>
39  * <table width="100%" border="0">
40  * <tr>
41  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
42  * </tr>
43  * </table>
44  * <hr>
45  */

46 public class TreeBrowserTag extends TagSupport JavaDoc
47 {
48     /**
49      * required: the style to render the browser.
50      * Possible values are:
51      *
52      * "css"
53      * "pics" (* pic names are required)
54      */

55     private String JavaDoc treeStyle = "pics";
56     public String JavaDoc getStyle() { return treeStyle; }
57     public void setStyle(String JavaDoc ts) { this.treeStyle = ts; }
58
59     /**
60      * optional: name the beanName in scope session!
61      */

62     private String JavaDoc treeBeanName = "mod_base_publics_index2";
63     public String JavaDoc getBeanname() { return treeBeanName; }
64     public void setBeanname(String JavaDoc bn) { this.treeBeanName = bn; }
65     
66     /* ************************************************************************ */
67     /* optional getters and setters */
68     /* ************************************************************************ */
69
70     private String JavaDoc cat_linkpfx = "catlink";
71     public String JavaDoc getCatlinkpfx() { return cat_linkpfx; }
72     public void setCatlinkpfx(String JavaDoc v) { this.cat_linkpfx = v; }
73
74     private String JavaDoc cat_parapfx = "cat";
75     public String JavaDoc getCatparapfx() { return cat_parapfx; }
76     public void setCatparapfx(String JavaDoc v) { this.cat_parapfx = v; }
77
78     private String JavaDoc pic_close = null;
79     public String JavaDoc getPicclose() { return pic_close; }
80     public void setPicclose(String JavaDoc v) { this.pic_close = v; }
81     
82     private String JavaDoc pic_open = null;
83     public String JavaDoc getPicopen() { return pic_open; }
84     public void setPicopen(String JavaDoc v) { this.pic_open = v; }
85
86     private String JavaDoc pic_firstopen = null;
87     public String JavaDoc getPicfirstopen() { return pic_firstopen; }
88     public void setPicfirstopen(String JavaDoc v) { this.pic_firstopen = v; }
89
90     private String JavaDoc pic_firstempty = null;
91     public String JavaDoc getPicfirstempty() { return pic_firstempty; }
92     public void setPicfirstempty(String JavaDoc v) { this.pic_firstempty = v; }
93
94     private String JavaDoc pic_firstclose = null;
95     public String JavaDoc getPicfirstclose() { return pic_firstclose; }
96     public void setPicfirstclose(String JavaDoc v) { this.pic_firstclose = v; }
97
98     private String JavaDoc pic_lastopen = null;
99     public String JavaDoc getPiclastopen() { return pic_lastopen; }
100     public void setPiclastopen(String JavaDoc v) { this.pic_lastopen = v; }
101
102     private String JavaDoc pic_lastempty = null;
103     public String JavaDoc getPiclastempty() { return pic_lastempty; }
104     public void setPiclastempty(String JavaDoc v) { this.pic_lastempty = v; }
105
106     private String JavaDoc pic_lastclose = null;
107     public String JavaDoc getPiclastclose() { return pic_lastclose; }
108     public void setPiclastclose(String JavaDoc v) { this.pic_lastclose = v; }
109
110     private String JavaDoc pic_l = null;
111     public String JavaDoc getPicl() { return pic_l; }
112     public void setPicl(String JavaDoc v) { this.pic_l = v; }
113
114     private String JavaDoc pic_t = null;
115     public String JavaDoc getPict() { return pic_t; }
116     public void setPict(String JavaDoc v) { this.pic_t = v; }
117
118     private String JavaDoc pic_bar = null;
119     public String JavaDoc getPicbar() { return pic_bar; }
120     public void setPicbar(String JavaDoc v) { this.pic_bar = v; }
121
122     private String JavaDoc pic_blank = null;
123     public String JavaDoc getPicblank() { return pic_blank; }
124     public void setPicblank(String JavaDoc v) { this.pic_blank = v; }
125     
126     private String JavaDoc picWidth = "19";
127     public String JavaDoc getPicwidthr() { return picWidth; }
128     public void setPicwidth(String JavaDoc v) { this.picWidth = v; }
129
130     private String JavaDoc picHeight = "19";
131     public String JavaDoc getPicheight() { return picHeight; }
132     public void setPicheight(String JavaDoc v) { this.picHeight = v; }
133         
134     /**
135      * Start rendering the tree browser
136      */

137     public int doStartTag() throws JspException
138     {
139         try
140         {
141             if(treeStyle.equalsIgnoreCase("pics") || treeStyle.equalsIgnoreCase("pic"))
142                 renderPicBasedTreeBrowser();
143             else if(treeStyle.equalsIgnoreCase("css"))
144                 renderCssBasedTreeBrowser();
145             else if(treeStyle.equalsIgnoreCase("sbb"))
146                 renderSbbBasedTreeBrowser();
147             else
148                 LoggingManager.log("Unknown tree style specified.", this);
149         }
150         catch(IOException JavaDoc e) {
151             LoggingManager.log("IOException occured during rendering. " + e.getMessage(), this);
152         }
153         
154         return (SKIP_BODY);
155     }
156     
157     /**
158      * Evaluate the remainder of the current page normally.
159      *
160      * @exception JspException if a JSP exception occurs
161      */

162     public int doEndTag() throws JspException
163     {
164         return (EVAL_PAGE);
165     }
166     
167     /**
168      *
169      */

170     protected void renderCssBasedTreeBrowser() throws JspException, IOException JavaDoc
171     {
172         HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
173         HttpSession session = request.getSession();
174         JspWriter out = pageContext.getOut();
175         
176         CategoryPagedBean treeBean = (CategoryPagedBean) session.getAttribute(treeBeanName);
177         if(treeBean == null)
178         {
179             LoggingManager.log("FAILED to find the treeBean!", this);
180             return;
181         }
182
183         Vector categs = treeBean.getCategories(); // vector contains GResCategory instances
184
Vector catnam = treeBean.getCategoryNames(); // vector contains PairOfObjects with (GResCategory, String)
185
Vector stats = treeBean.getFolderStatus(); // vector contains String instances
186
String JavaDoc currentcat = treeBean.getSelCatID(); // current selected category
187
String JavaDoc url = treeBean.getURL() + "?";
188         Hashtable paramValues = treeBean.getValues(); // ???
189
String JavaDoc key = null;
190         String JavaDoc active = "";
191         GResCategory cats[] = new GResCategory[ categs.size() ];
192
193         // create a Locale instance to query the MessageResources
194
Locale locale = null;
195         String JavaDoc loc = request.getParameter("locale");
196         if(loc != null)
197         {
198             if(loc.indexOf("_") > 0)
199                 locale = new java.util.Locale JavaDoc(loc. substring(0, loc.indexOf("_")), loc.substring(loc.indexOf("_") + 1) );
200             else
201                 locale = new java.util.Locale JavaDoc(loc,"");
202         }
203         else
204             locale = (Locale) session.getAttribute(Globals.LOCALE_KEY);
205
206         // query MessageResources for Locale specific Strings
207
MessageResources mr = MessageResources.getMessageResources(com.raptus.owxv3.Constants.OWXRESOURCES);
208         String JavaDoc selcategoryalt = mr.getMessage(locale,"publics.category.alt.selectcat");
209         String JavaDoc opencloseiconalt = mr.getMessage(locale,"publics.category.alt.openclosefolder");
210
211         if(categs.size() != catnam.size())
212         {
213             out.println("Not enough categ names!<br>");
214             out.flush();
215         }
216         if(categs.size() != stats.size())
217         {
218             out.println("Not enough status values!<br>");
219             out.flush();
220         }
221
222         // strip unneeded parameters from the url
223
for(Enumeration e = paramValues.keys(); e.hasMoreElements() ; )
224         {
225             key = (String JavaDoc) e.nextElement();
226             if(!key.equals("selcatid") && !key.equals("catid") && !key.equals("first") )
227                 url = url + key + "=" + java.net.URLEncoder.encode( (String JavaDoc)paramValues.get(key) ) + "&";
228         }
229
230         // fillup browser vector
231
for(int i = 0; i < categs.size(); i++)
232             cats[i] = (GResCategory) categs.elementAt(i);
233
234         // main loop
235
for(int i = 0; i < cats.length; i++)
236         {
237             GResCategory cat = (GResCategory) categs.elementAt(i);
238             if(cat == null)
239                 continue; // on main loop
240

241             // determine if this is the currently selected category
242
if(cat.getCategoryID().equals(currentcat))
243                 active = "-active";
244             else
245                 active = "";
246             
247             out.println("<!-- Category/Style-Css: " + cat.getCategoryID() + " Level: " + cat.getLevel() + " Name: " + (String JavaDoc) catnam.elementAt(i) + " Selected: " + currentcat + " -->");
248             out.println("<a HREF='" + url + "selcatid=" + cat.getCategoryID() +
249                         "' title='" + selcategoryalt +
250                         "' class='" + cat_linkpfx + cat.getLevel() + active + "'><p class='" + cat_parapfx + cat.getLevel() + active + "'> " +
251                         (String JavaDoc) catnam.elementAt(i) + " </p></a>");
252             
253         } // main loop through categories
254

255     }
256     
257     /**
258      *
259      */

260     protected void renderPicBasedTreeBrowser() throws JspException, IOException JavaDoc
261     {
262         HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
263         HttpSession session = request.getSession();
264         JspWriter out = pageContext.getOut();
265         
266         CategoryPagedBean treeBean = (CategoryPagedBean) session.getAttribute(treeBeanName);
267         if(treeBean == null)
268         {
269             LoggingManager.log("FAILED to find the treeBean!", this);
270             return;
271         }
272
273         Vector categs = treeBean.getCategories(); // vector contains GResCategory instances
274
Vector catnam = treeBean.getCategoryNames(); // vector contains PairOfObjects with (GResCategory, String)
275
Vector stats = treeBean.getFolderStatus(); // vector contains String instances
276
String JavaDoc currentcat = treeBean.getSelCatID(); // current selected category
277
String JavaDoc url = treeBean.getURL() + "?";
278         Hashtable paramValues = treeBean.getValues(); // ???
279
String JavaDoc key = null;
280         String JavaDoc active = "";
281         GResCategory cats[] = new GResCategory[ categs.size() ];
282
283         // create a Locale instance to query the MessageResources
284
Locale locale = null;
285         String JavaDoc loc = request.getParameter("locale");
286         if(loc != null)
287         {
288             if(loc.indexOf("_") > 0)
289                 locale = new java.util.Locale JavaDoc(loc. substring(0, loc.indexOf("_")), loc.substring(loc.indexOf("_") + 1) );
290             else
291                 locale = new java.util.Locale JavaDoc(loc,"");
292         }
293         else
294             locale = (Locale) session.getAttribute(Globals.LOCALE_KEY);
295
296         // query MessageResources for Locale specific Strings
297
MessageResources mr = MessageResources.getMessageResources(com.raptus.owxv3.Constants.OWXRESOURCES);
298         String JavaDoc selcategoryalt = mr.getMessage(locale,"publics.category.alt.selectcat");
299         String JavaDoc opencloseiconalt = mr.getMessage(locale,"publics.category.alt.openclosefolder");
300
301         if(pic_close == null) pic_close = RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.image.close");
302         if(pic_open == null) pic_open = RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.image.open");
303         if(pic_firstopen == null) pic_firstopen = RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.image.firstopen");
304         if(pic_firstempty == null) pic_firstempty = RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.image.firstempty");
305         if(pic_firstclose == null) pic_firstclose = RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.image.firstclose");
306         if(pic_lastopen == null) pic_lastopen = RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.image.lastopen");
307         if(pic_lastempty == null) pic_lastempty = RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.image.lastempty");
308         if(pic_lastclose == null) pic_lastclose = RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.image.lastclose");
309         if(pic_l == null) pic_l = RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.image.l");
310         if(pic_t == null) pic_t = RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.image.t");
311         if(pic_bar == null) pic_bar = RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.image.bar");
312         if(pic_blank == null) pic_blank = RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.image.blank");
313         
314         String JavaDoc wstr = "border=0 align='absmiddle' alt='" + opencloseiconalt + "' width='" + picWidth + "' height='" + picHeight + "'";
315         String JavaDoc wstr2 = "border=0 align='absmiddle' width='" + picWidth + "' height='" + picHeight + "'";
316         String JavaDoc img_close = "<img SRC='" + pic_close + "'"+wstr+">&nbsp;";
317         String JavaDoc img_open = "<img SRC='" + pic_open + "'"+wstr+">&nbsp;";
318         String JavaDoc img_firstopen = "<img SRC='" + pic_firstopen + "'"+wstr+">&nbsp;";
319         String JavaDoc img_firstempty = "<img SRC='" + pic_firstempty + "'"+wstr2+">&nbsp;";
320         String JavaDoc img_firstclose = "<img SRC='" + pic_firstclose + "'"+wstr+">&nbsp;";
321         String JavaDoc img_lastopen = "<img SRC='" + pic_lastopen + "'"+wstr+">&nbsp;";
322         String JavaDoc img_lastempty = "<img SRC='" + pic_lastempty + "'"+wstr2+">&nbsp;";
323         String JavaDoc img_lastclose = "<img SRC='" + pic_lastclose + "'"+wstr+">&nbsp;";
324         String JavaDoc img_l ="<img SRC='" + pic_l + "'"+wstr+">";
325         String JavaDoc img_t = "<img SRC='" + pic_t + "'"+wstr+">";
326         String JavaDoc img_bar = "<img SRC='" + pic_bar + "'"+wstr+">";
327         String JavaDoc img_blank = "<img width=19 height=19 SRC='" + pic_blank + "'" + wstr + ">";
328
329         if(categs.size() != catnam.size())
330         {
331             out.println("Not enough categ names!<br>");
332             out.flush();
333         }
334         if(categs.size() != stats.size())
335         {
336             out.println("Not enough status values!<br>");
337             out.flush();
338         }
339
340         // strip unneeded parameters from the url
341
for(Enumeration e = paramValues.keys(); e.hasMoreElements() ; )
342         {
343             key = (String JavaDoc) e.nextElement();
344             if(!key.equals("selcatid") && !key.equals("catid") && !key.equals("first") )
345                 url = url + key + "=" + java.net.URLEncoder.encode( (String JavaDoc)paramValues.get(key) ) + "&";
346         }
347
348         // fillup browser vector
349
for(int i = 0; i < categs.size(); i++)
350             cats[i] = (GResCategory) categs.elementAt(i);
351
352         // main loop
353
for(int i = 0; i < cats.length; i++)
354         {
355             GResCategory cat = (GResCategory) categs.elementAt(i);
356             if(cat == null)
357                 continue; // on main loop
358

359             // determine if this is the currently selected category
360
if(cat.getCategoryID().equals(currentcat))
361                 active = "-active";
362             else
363                 active = "";
364             
365             // prepare indention of category links
366
GResCategory c = cat; // start with
367
Vector res = null; // free old data
368
res = new Vector(); // indention
369
for(int l = 0; l < cat.getLevel(); l++)
370             {
371                 int parentid = c.getParent();
372                 String JavaDoc stat = "";
373
374                 // get parent
375
for(int j = 0; j < cats.length; j++)
376                 {
377                     if(cats[j].getRowID() == parentid)
378                     {
379                         stat = (String JavaDoc) stats.elementAt(j);
380                         if( stat.equals("folder_open_last") || stat.equals("folder_open_last_end") )
381                             res.addElement(img_blank);
382                         else
383                             res.addElement(img_bar);
384
385                         // start searching parent's parent
386
c = cats[j];
387                         break;
388                     }
389                 }
390             } // cat levels
391

392             // determine if this line is the last in the current category level
393
boolean lastlevel = false;
394             if( (i + 1) == cats.length)
395             {
396                 lastlevel = true;
397             }
398             else
399             {
400                 if( cats[i+1].getLevel() <= cat.getLevel() )
401                     lastlevel = true;
402             }
403
404             // print out the indention
405
out.println("<!-- Category: " + cat.getCategoryID() + " Level: " + cat.getLevel() + " Name: " + (String JavaDoc) catnam.elementAt(i) + " Selected: " + currentcat + " -->");
406             for(int j = res.size()-2; j >= 0; j--)
407                 out.println( (String JavaDoc) res.elementAt(j) );
408                        
409             // process floder status 1
410
if( ((String JavaDoc) stats.elementAt(i)).equals("folder_open") )
411             {
412                 if(!lastlevel)
413                 {
414                     out.println("<a HREF='"+url+"catid="+cat.getCategoryID()+"&selcatid="+currentcat+"'>");
415                     if(cat.getLevel()>0 )
416                     {
417                         if(cats[i+1].getLevel() != cat.getLevel())
418                             out.println(img_t+img_open);
419                         else
420                             out.println(img_t+img_lastopen);
421                     }
422                     else
423                         out.println(img_firstopen);
424                     out.println("</a>");
425                 }
426                 else
427                 {
428                     if(cat.getLevel()>0)
429                         out.println(img_t+img_lastempty);
430                     else
431                         out.println(img_firstempty);
432                 }
433                 out.println("<a HREF='" + url + "selcatid=" + cat.getCategoryID() + "' " +
434                             "class='" + cat_linkpfx + cat.getLevel() + active + "' " +
435                             "title='" + selcategoryalt + "'>" +
436                             (String JavaDoc)catnam.elementAt(i)+"</a><br>");
437             }
438
439             // process floder status 2
440
if(((String JavaDoc)stats.elementAt(i)).equals("folder_close"))
441             {
442                 if(!lastlevel)
443                 {
444                     out.println("<a HREF='"+url+"catid="+cat.getCategoryID()+"&selcatid="+currentcat+"'>");
445                     if(cat.getLevel() >0)
446                         out.println(img_t+img_close);
447                     else
448                         out.println(img_firstclose);
449                     out.println("</a>");
450                 }
451                 else
452                 {
453                     if(cat.getLevel()>0)
454                         out.println(img_t+img_lastempty);
455                     else
456                         out.println(img_firstempty);
457                 }
458                 out.println("<a HREF='" + url + "selcatid=" + cat.getCategoryID() + "' " +
459                             "class='" + cat_linkpfx + cat.getLevel() + active + "' " +
460                             "title='" + selcategoryalt + "'>" +
461                             (String JavaDoc)catnam.elementAt(i)+"</a><br>");
462                 i = skipSubFolders(i+1, categs, cat);
463                 continue;
464             }
465
466             // process floder status 3
467
if( ((String JavaDoc)stats.elementAt(i)).equals("folder_open_last") ||
468                 ((String JavaDoc)stats.elementAt(i)).equals("folder_open_last_end") )
469             {
470                 if(!lastlevel)
471                 {
472                     out.println("<a HREF='"+url+"catid="+cat.getCategoryID()+"&selcatid="+currentcat+"'>");
473                     if(cat.getLevel() >0 )
474                     {
475                         if(i<cats.length-1)
476                         {
477                             if(cats[i+1].getLevel()<cat.getLevel())
478                                 out.println(img_l+img_lastopen);
479                             else
480                                 out.println(img_l+img_open);
481                        }
482                        else
483                             out.println(img_l+img_lastopen);
484                     }
485                     else
486                         out.println(img_open);
487
488                     out.println("</a>");
489                 }
490                 else
491                 {
492                     if(cat.getLevel()>0)
493                         out.println(img_l+img_lastempty);
494                     else
495                         out.println(img_firstempty);
496                 }
497
498                 out.println("<a HREF='" + url + "selcatid=" + cat.getCategoryID() + "' " +
499                             "class='" + cat_linkpfx + cat.getLevel() + active + "' " +
500                             "title='" + selcategoryalt + "'>" +
501                             (String JavaDoc)catnam.elementAt(i)+"</a><br>");
502             }
503
504             // process floder status 4
505
if( ((String JavaDoc)stats.elementAt(i)).equals("folder_close_last") ||
506                 ((String JavaDoc)stats.elementAt(i)).equals("folder_close_last_end") )
507             {
508                 if(!lastlevel)
509                 {
510                     out.println("<a HREF='"+url+"catid="+cat.getCategoryID()+"&selcatid="+currentcat+"'>");
511                     if(cat.getLevel() >0)
512                         out.println(img_l+img_close);
513                     else
514                         out.println(img_l+img_close);
515
516                     out.println("</a>");
517                 }
518                 else
519                 {
520                     if(cat.getLevel()>0)
521                         out.println(img_l+img_lastempty);
522                     else
523                         out.println(img_firstempty);
524                 }
525
526                 out.println("<a HREF='" + url + "selcatid=" + cat.getCategoryID() + "' " +
527                             "class='" + cat_linkpfx + cat.getLevel() + active + "' " +
528                             "title='" + selcategoryalt + "'>" +
529                             (String JavaDoc)catnam.elementAt(i)+"</a><br>");
530                 i = skipSubFolders(i+1, categs, cat);
531                 continue;
532             }
533         } // main loop through categories
534

535     }
536     
537     /**
538      * this is based on the standard PicBasedTreeBrowser, but with some
539      * differences, as follows.
540      *
541      * - on 1st level cats are always open and cannot be closed
542      * - on 2nd level multiple cats are always open/closeable (-/+)
543      * - on 3rd level and higher cats are always open and cannot be closed
544      * - when entering the 1st and 2nd level cats are visible
545      */

546     protected void renderSbbBasedTreeBrowser() throws JspException, IOException JavaDoc
547     {
548         HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
549         HttpSession session = request.getSession();
550         JspWriter out = pageContext.getOut();
551         
552         CategoryPagedBean treeBean = (CategoryPagedBean) session.getAttribute(treeBeanName);
553         if(treeBean == null)
554         {
555             LoggingManager.log("FAILED to find the treeBean!", this);
556             return;
557         }
558
559         Vector categs = treeBean.getCategories(); // vector contains GResCategory instances
560
Vector catnam = treeBean.getCategoryNames(); // vector contains PairOfObjects with (GResCategory, String)
561
Vector stats = treeBean.getFolderStatus(); // vector contains String instances
562
String JavaDoc currentcat = treeBean.getSelCatID(); // current selected category
563
String JavaDoc url = treeBean.getURL() + "?";
564         Hashtable paramValues = treeBean.getValues(); // ???
565
String JavaDoc key = null;
566         String JavaDoc active = "";
567         GResCategory cats[] = new GResCategory[ categs.size() ];
568
569         // create a Locale instance to query the MessageResources
570
Locale locale = null;
571         String JavaDoc loc = request.getParameter("locale");
572         if(loc != null)
573         {
574             if(loc.indexOf("_") > 0)
575                 locale = new java.util.Locale JavaDoc(loc. substring(0, loc.indexOf("_")), loc.substring(loc.indexOf("_") + 1) );
576             else
577                 locale = new java.util.Locale JavaDoc(loc,"");
578         }
579         else
580             locale = (Locale) session.getAttribute(Globals.LOCALE_KEY);
581
582         // query MessageResources for Locale specific Strings
583
MessageResources mr = MessageResources.getMessageResources(com.raptus.owxv3.Constants.OWXRESOURCES);
584         String JavaDoc selcategoryalt = mr.getMessage(locale,"publics.category.alt.selectcat");
585         String JavaDoc opencloseiconalt = mr.getMessage(locale,"publics.category.alt.openclosefolder");
586
587         String JavaDoc wstr = "border=0 align='absmiddle' alt='" + opencloseiconalt + "' width='" + picWidth + "' height='" + picHeight + "'";
588         String JavaDoc img_plus = "<img SRC='" + RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.treesbb.plus") + "'"+wstr+">";
589         String JavaDoc img_minus = "<img SRC='" + RequestUtils.message(pageContext, Action.MESSAGES_KEY, Globals.LOCALE_KEY, "owx.api.components.fc_categories.treesbb.minus") + "'"+wstr+">";
590
591         if(categs.size() != catnam.size())
592         {
593             out.println("Not enough categ names!<br>");
594             out.flush();
595         }
596         if(categs.size() != stats.size())
597         {
598             out.println("Not enough status values!<br>");
599             out.flush();
600         }
601
602         // strip unneeded parameters from the url
603
for(Enumeration e = paramValues.keys(); e.hasMoreElements() ; )
604         {
605             key = (String JavaDoc) e.nextElement();
606             if(!key.equals("selcatid") && !key.equals("catid") && !key.equals("first") )
607                 url = url + key + "=" + java.net.URLEncoder.encode( (String JavaDoc)paramValues.get(key) ) + "&";
608         }
609
610         // fillup browser vector
611
for(int i = 0; i < categs.size(); i++)
612             cats[i] = (GResCategory) categs.elementAt(i);
613
614         // main loop
615
for(int i = 0; i < cats.length; i++)
616         {
617             GResCategory cat = (GResCategory) categs.elementAt(i);
618             if(cat == null)
619                 continue; // on main loop
620

621             // determine if this is the currently selected category
622
if(cat.getCategoryID().equals(currentcat))
623                 active = "-active";
624             else
625                 active = "";
626             
627             // all other category levels than 1
628
if(cat.getLevel() != 1)
629             {
630                 out.println("<!-- Category/Style-Sbb: " + cat.getCategoryID() + " Level: " + cat.getLevel() + " Name: " + (String JavaDoc) catnam.elementAt(i) + " Selected: " + currentcat + " -->");
631                 out.println("<table class='kat-tab'><tr>");
632                 out.println("<td class='kat-img'></td><td class='kat-name'>");
633                 out.println("<a HREF='" + url + "selcatid=" + cat.getCategoryID() +
634                             "' title='" + selcategoryalt +
635                             "' class='" + cat_linkpfx + cat.getLevel() + active + "'><p class='" + cat_parapfx + cat.getLevel() + active + "'> " +
636                             (String JavaDoc) catnam.elementAt(i) + " </p></a>");
637                 out.println("</td></tr></table>");
638
639                 continue; // with next category
640
}
641
642             // determine if this line is the last in the current category level
643
boolean lastlevel = false;
644             if( (i + 1) == cats.length)
645             {
646                 lastlevel = true;
647             }
648             else
649             {
650                 if( cats[i+1].getLevel() <= cat.getLevel() )
651                     lastlevel = true;
652             }
653                               
654             // process floder status 1
655
if( ((String JavaDoc) stats.elementAt(i)).equals("folder_open") )
656             {
657                 out.println("<table class='kat-tab'><tr>");
658                 if(!lastlevel)
659                 {
660                     out.println("<td class='kat-img'>");
661                     out.println("<a HREF='"+url+"catid="+cat.getCategoryID()+"&selcatid="+currentcat+"'>");
662                     out.println(img_minus);
663                     out.println("</a></td>");
664                 }
665                 else
666                 {
667                     out.println("<td class='kat-img'>");
668 // out.println(img_minus);
669
out.println("&nbsp;");
670                     out.println("</td>");
671                 }
672                 
673                 out.println("<td class='kat-name'>");
674                 out.println("<a HREF='" + url + "selcatid=" + cat.getCategoryID() + "' " +
675                             "title='" + selcategoryalt + "' " +
676                             "class='" + cat_linkpfx + cat.getLevel() + active + "'>" +
677                             "<p class='" + cat_parapfx + cat.getLevel() + active + "'>" +
678                             (String JavaDoc) catnam.elementAt(i) + "</a></p>");
679                 out.println("</td></tr></table>");
680             }
681
682             // process floder status 2
683
if(((String JavaDoc)stats.elementAt(i)).equals("folder_close"))
684             {
685                 out.println("<table class='kat-tab'><tr>");
686                 if(!lastlevel)
687                 {
688                     out.println("<td class='kat-img'>");
689                     out.println("<a HREF='" + url + "catid=" + cat.getCategoryID()+"&selcatid="+currentcat+"'>");
690                     out.println(img_plus);
691                     out.println("</a></td>");
692                 }
693                 else
694                 {
695                     out.println("<td class='kat-img'>");
696 // out.println(img_plus);
697
out.println("&nbsp;");
698                     out.println("</td>");
699                 }
700
701                 out.println("<td class='kat-name'>");
702                 out.println("<a HREF='" + url + "selcatid=" + cat.getCategoryID() + "' " +
703                             "title='" + selcategoryalt + "' " +
704                             "class='" + cat_linkpfx + cat.getLevel() + active + "'>" +
705                             "<p class='" + cat_parapfx + cat.getLevel() + active + "'>" +
706                             (String JavaDoc) catnam.elementAt(i) + "</a></p>");
707                 out.println("</td></tr></table>");
708                 
709                 i = skipSubFolders(i+1, categs, cat);
710                 continue;
711             }
712
713             // process floder status 3
714
if( ((String JavaDoc)stats.elementAt(i)).equals("folder_open_last") ||
715                 ((String JavaDoc)stats.elementAt(i)).equals("folder_open_last_end") )
716             {
717                 out.println("<table class='kat-tab'><tr>");
718                 if(!lastlevel)
719                 {
720                     out.println("<td class='kat-img'>");
721                     out.println("<a HREF='"+url+"catid="+cat.getCategoryID()+"&selcatid="+currentcat+"'>");
722                     out.println(img_minus);
723                     out.println("</a></td>");
724                 }
725                 else
726                 {
727                     out.println("<td class='kat-img'>");
728 // out.println(img_minus);
729
out.println("&nbsp;");
730                     out.println("</td>");
731                 }
732
733                 out.println("<td class='kat-name'>");
734                 out.println("<a HREF='" + url + "selcatid=" + cat.getCategoryID() + "' " +
735                             "title='" + selcategoryalt + "' " +
736                             "class='" + cat_linkpfx + cat.getLevel() + active + "'>" +
737                             "<p class='" + cat_parapfx + cat.getLevel() + active + "'>" +
738                             (String JavaDoc) catnam.elementAt(i) + "</a></p>");
739                 out.println("</td></tr></table>");
740
741             }
742
743             // process floder status 4
744
if( ((String JavaDoc)stats.elementAt(i)).equals("folder_close_last") ||
745                 ((String JavaDoc)stats.elementAt(i)).equals("folder_close_last_end") )
746             {
747                 out.println("<table class='kat-tab'><tr>");
748                 if(!lastlevel)
749                 {
750                     out.println("<td class='kat-img'>");
751                     out.println("<a HREF='"+url+"catid="+cat.getCategoryID()+"&selcatid="+currentcat+"'>");
752                     out.println(img_plus);
753                     out.println("</a></td>");
754                 }
755                 else
756                 {
757                     out.println("<td class='kat-img'>");
758 // out.println(img_plus);
759
out.println("&nbsp;");
760                     out.println("</td>");
761                 }
762
763                 out.println("<td class='kat-name'>");
764                 out.println("<a HREF='" + url + "selcatid=" + cat.getCategoryID() + "' " +
765                             "title='" + selcategoryalt + "' " +
766                             "class='" + cat_linkpfx + cat.getLevel() + active + "'>" +
767                             "<p class='" + cat_parapfx + cat.getLevel() + active + "'>" +
768                             (String JavaDoc) catnam.elementAt(i) + "</a></p>");
769                 out.println("</td></tr></table>");
770
771                 i = skipSubFolders(i+1, categs, cat);
772                 continue;
773             }
774         } // main loop through categories
775

776     }
777     
778     /**
779      * skips subfolders in current category level
780      */

781     protected int skipSubFolders(int j, Vector categs, GResCategory cat)
782     {
783         while(true)
784         {
785             if(j >= categs.size())
786                 break;
787
788             GResCategory cat1 = (GResCategory)categs.elementAt(j);
789             if(cat1 == null)
790                 break;
791             
792             if(cat1.getLevel() <= cat.getLevel())
793                 break;
794             
795             j++;
796         }
797         
798         return(j-1);
799     }
800     
801 }
802
803 // eof
804
Popular Tags