KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > modules > categories > PubStyleTreeBean


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

5
6 package com.raptus.owxv3.modules.categories;
7
8 import com.raptus.owxv3.api.*;
9 import java.util.*;
10
11 public class PubStyleTreeBean extends Object JavaDoc
12 {
13     /**
14      * global resources
15      */

16     com.raptus.owxv3.api.GlobalResources gres = new com.raptus.owxv3.api.GlobalResources();
17
18     /**
19      * our categories
20      */

21     java.util.Vector JavaDoc categories = new Vector();
22
23     /**
24      * owner
25      */

26     String JavaDoc owner;
27
28     /**
29      * Current locale
30      */

31     Locale locale;
32
33     /**
34      * Our category names
35      */

36     Vector categoryNames = new Vector();
37
38     /**
39      * our folder statuses (last/not last folder)
40      */

41     Vector folderStats = new Vector();
42
43     /**
44      * our folder status (opened/closed
45      */

46     Hashtable isOpened = new Hashtable();
47
48     /**
49      * return if the category with the specified ID is open or not
50      *
51      * @param id The category Id for which we want the info
52      * @return true if folder status is open ,false if not
53      */

54     public boolean isOpen(int id)
55     {
56         int i;
57
58         String JavaDoc v = (String JavaDoc)isOpened.get(""+id);
59         if(v!= null)
60         {
61             if(v.equals("true"))
62             {
63                 return true;
64             }
65             else
66             {
67                 return false;
68             }
69         }
70         else
71         {
72             return false;
73         }
74     }
75
76     /**
77      * set current locale
78      *
79      * @param l the Current locale
80      */

81     public void setLocale(Locale l)
82     {
83         this.locale = l;
84     }
85
86     /**
87      * return current locale
88      *
89      * @return Locale object represinting the current locale
90      */

91     public Locale getLocale()
92     {
93         return locale;
94     }
95
96     /**
97      * return the owner of this tree
98      *
99      * @return a String containing the owner.
100      */

101     public String JavaDoc getOwner()
102     {
103         return owner;
104     }
105
106     /**
107      * set the current owner
108      *
109      * @param owner the new owner
110      */

111     public void setOwner(String JavaDoc owner)
112     {
113         this.owner = owner;
114     }
115
116     /**
117      * return a Vector of categories
118      *
119      * @return a Vector of categories
120      */

121     public Vector getCategories()
122     {
123         return categories;
124     }
125
126     /*
127      * Update internal state of the bean
128      */

129     public void Update()
130     {
131         gres = new com.raptus.owxv3.api.GlobalResources();
132         categories = new Vector();
133         categoryNames = new Vector();
134         try
135         {
136             loadCategories();
137             loadCategoryNames();
138         }
139         catch(java.sql.SQLException JavaDoc ex)
140         {}
141     }
142
143     /**
144      * return category names
145      *
146      * @return a Vector of Strings cointaining the category names.
147      */

148     public Vector getCategoryNames()
149     {
150         return categoryNames;
151     }
152
153     /**
154      * load all categories
155      */

156     public void loadCategories() throws java.sql.SQLException JavaDoc
157     {
158         java.util.Vector JavaDoc v=gres.loadCategories(0,owner);
159         for (int i=0;i<v.size();i++)
160         {
161             GResCategory grcat=(GResCategory)v.elementAt(i);
162
163             categories.add(grcat);
164             if(i<v.size()-1)
165             {
166                 //if(isOpen(grcat.getRowID()))
167
//{
168
// folderStats.addElement(new String("folder_open"));
169
//}
170
//else
171
{
172                     folderStats.addElement(new String JavaDoc("folder_close"));
173                 }
174                 loadChildCategories(grcat.getRowID(), false);
175             }
176             else
177             {
178                 //if(isOpen(grcat.getRowID()))
179
//{
180
// folderStats.addElement(new String("folder_open_last"));
181
//}
182
//else
183
{
184                     folderStats.addElement(new String JavaDoc("folder_close_last"));
185                 }
186                 loadChildCategories(grcat.getRowID(), true);
187             }
188         }
189     }
190
191     /**
192      * load child categories for specified category
193      *
194      * @param id The ID of the category
195      * @param abslast true if is absolute last
196      */

197     protected void loadChildCategories(int id, boolean abslast) throws java.sql.SQLException JavaDoc
198     {
199         java.util.Vector JavaDoc child=gres.loadChildCategories(id,owner);
200         for (int i=0;i<child.size();i++)
201         {
202             com.raptus.owxv3.api.GResCategory grcat=(com.raptus.owxv3.api.GResCategory)child.elementAt(i);
203
204             categories.add(grcat);
205             if(i<child.size()-1)
206             {
207                 //if(isOpen(grcat.getRowID()))
208
//{
209
// folderStats.addElement(new String("folder_open"));
210
//}
211
//else
212
{
213                     folderStats.addElement(new String JavaDoc("folder_close"));
214                 }
215             }
216             else
217             {
218                 if(abslast)
219                 {
220                     //if(isOpen(grcat.getRowID()))
221
//{
222
// folderStats.addElement(new String("folder_open_last_end"));
223
//}
224
//else
225
{
226                         folderStats.addElement(new String JavaDoc("folder_close_last_end"));
227                     }
228                 }
229                 else
230                 {
231                     //if(isOpen(grcat.getRowID()))
232
//{
233
// folderStats.addElement(new String("folder_open_last"));
234
//}
235
//else
236
{
237                         folderStats.addElement(new String JavaDoc("folder_close_last"));
238                     }
239                 }
240             }
241             loadChildCategories(grcat.getRowID(), abslast);
242         }//enf for
243
}//end void
244

245
246     /**
247      * return folder status
248      *
249      * @return a Vector of folder statuses
250      */

251     public Vector getFolderStatus()
252     {
253         Vector folderStatsr = new Vector();
254         for(int i=0;i<categories.size();i++)
255         {
256             com.raptus.owxv3.api.GResCategory grcat=(com.raptus.owxv3.api.GResCategory)categories.elementAt(i);
257             String JavaDoc stat = (String JavaDoc)folderStats.elementAt(i);
258             if(this.isOpen(grcat.getRowID()))
259             {
260                 if(stat.equals("folder_close"))
261                 {
262                     folderStatsr.addElement("folder_open");
263                 }
264
265                 if(stat.equals("folder_close_last"))
266                 {
267                     folderStatsr.addElement("folder_open_last");
268                 }
269
270                 if(stat.equals("folder_close_last_end"))
271                 {
272                     folderStatsr.addElement("folder_open_last_end");
273                 }
274             }
275             else
276             {
277                 folderStatsr.addElement(stat);
278             }
279         }
280         return folderStatsr;
281     }
282
283     /**
284      * load category names
285      */

286     protected void loadCategoryNames() throws java.sql.SQLException JavaDoc
287     {
288         com.raptus.owxv3.api.GResCategory grcat=null;
289         int i;
290         for (i=0;i<categories.size();i++)
291         {
292             grcat=(com.raptus.owxv3.api.GResCategory)categories.elementAt(i);
293
294             if(grcat!=null)
295             {
296                 String JavaDoc catnames;
297                 catnames = gres.loadMessage(gres.getCategoryTableName(),grcat.getRowID(), CategoryConstants.RESCATFIELD_NAME,locale);
298                 categoryNames.add(catnames);
299             }
300             else
301             {
302                 categoryNames.add("This cat=null");
303             }
304         }
305     }//end loadCategoryNames
306

307     /**
308      * togle folder (category) status
309      *
310      * @param id The category ID to be toggled from open to close or from close to open.
311      */

312     public void togleFolder(int id)
313     {
314         int i;
315
316         if(isOpen(id))
317         {
318             isOpened.put(""+id, "false");
319         }
320         else
321         {
322             isOpened.put(""+id, "true");
323         }
324     }
325
326     /**
327      * return the name of parent categories for specified category, in english
328      *
329      * @param cat Category for which we want parent names
330      * @return a Vector of category names for all parent categories of this category.
331      */

332     public Vector getTree(GResCategory cat)
333     {
334         GlobalResources res = new GlobalResources();
335         try
336         {
337             return res.getTree(cat, new Locale("en","GB"));
338         }
339         catch(java.sql.SQLException JavaDoc ex)
340         {
341             return new Vector();
342         }
343     }
344
345
346 }
347
Popular Tags