KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > webapps > fichotheque > ListCards


1 package org.jahia.webapps.fichotheque;
2
3 import java.util.*;
4 import java.sql.*;
5
6 import org.jahia.tools.*;
7 import org.jahia.tools.db.*;
8
9 /**
10  * Represents a list of cards
11  *
12  * @author Yann Gentil <a HREF="mailto:gentil@xo3.com">gentil@xo3.com</a>
13  * @version %I%, %G%
14  */

15
16 public class ListCards {
17     private static org.apache.log4j.Logger logger =
18         org.apache.log4j.Logger.getLogger(ListCards.class);
19
20     /** vector that contains all the cards of the list **/
21     private Vector cards = new Vector();
22
23     /**
24      * Create a list
25      */

26     public ListCards () {
27     }
28
29     /**
30      * Get the cards
31      *
32      * @return vector of cards
33      */

34     public void setCards (Vector card) {
35         this.cards = card;
36     }
37
38     /**
39      * Get the cards
40      *
41      * @return vector of cards
42      */

43     public Vector getCards () {
44         return this.cards;
45     }
46
47     /**
48      * Get the size of the list
49      *
50      * @return int
51      */

52     public int getSize () {
53         return this.cards.size();
54     }
55
56     /**
57      * Get the card_id of the next card in the list
58      *
59      * @param the current card id
60      * @return the next card id
61      */

62     public int getNextCardId (int current_cardID) {
63         int next_id = 0;
64
65         // if the next card does not exist in the list, return the first card id
66
if (this.cards.size() > 0) {
67             next_id = ( (Card)this.cards.get(0)).getId();
68         }
69
70         for (int i = 0; i < this.cards.size(); i++) {
71             // search the current card in the list
72
if ( ( (Card)this.cards.get(i)).getId() == current_cardID) {
73                 // if it's the last card of the list, do nothing
74
// the id returned is the id of the first card (initialised above)
75
if ( (i + 1) < this.cards.size()) {
76                     // get the next card id
77
next_id = ( (Card)this.cards.get(i + 1)).getId();
78                 }
79             }
80         }
81         return next_id;
82     }
83
84     /**
85      * Get the card_id of the previous card in the list
86      *
87      * @param the current card id
88      * @return the previous card id
89      */

90     public int getPreviousCardId (int current_cardID) {
91         int previous_id = 0;
92
93         // if the previous card does not exist in the list, return the last card id
94
if (this.cards.size() > 0) {
95             previous_id = ( (Card)this.cards.get(this.cards.size() - 1)).getId();
96         }
97
98         for (int i = 0; i < this.cards.size(); i++) {
99             // search the current card id
100
if ( ( (Card)this.cards.get(i)).getId() == current_cardID) {
101                 // if it's the first card of the list, do nothing
102
// the id returned is the id of the last card (initialised above)
103
if (i > 0) {
104                     // get the previous card id
105
previous_id = ( (Card)this.cards.get(i - 1)).getId();
106                 }
107             }
108         }
109         return previous_id;
110     }
111
112     /**
113      * Get the card_id of the current card in the list
114      *
115      * @param the current card id
116      * @return the next card id
117      */

118     public int getCurrentCardId (int current_cardID) {
119         int current_id = current_cardID;
120
121         if (this.cards.size() != 0) {
122             // if the current card does not exist in the list,
123
// return the first card id
124
current_id = ( (Card)this.cards.get(0)).getId();
125
126             for (int i = 0; i < this.cards.size(); i++) {
127                 // search the current card id
128
if ( ( (Card)this.cards.get(i)).getId() == current_cardID) {
129                     current_id = ( (Card)this.cards.get(i)).getId();
130                 }
131             }
132         }
133         return current_id;
134     }
135
136     /**
137      * Load the cards of the list
138      *
139      * @param cardLibraryName the name of the card library
140      * @param userRight the right that the user have
141      * @param query if the query is active,
142      * only the cards that correspond to the query will be listed
143      */

144     public void loadList (String JavaDoc contextId, String JavaDoc inJahia, String JavaDoc useMode,
145                           String JavaDoc remoteUser, String JavaDoc userRight, String JavaDoc sortFlag,
146                           String JavaDoc sortedBy) {
147         Vector list = new Vector();
148         logger.debug("userRight :" + userRight);
149         // Read each card corresponing to the query
150
try {
151             if (userRight.equals("manager")) {
152                 if (useMode.equals("user")) {
153                     if (inJahia.equals("true")) {
154                         list = AccessDB.loadListCard(remoteUser, contextId,
155                             sortFlag,
156                             sortedBy);
157                     } else {
158                         list = AccessDB.loadListCard(remoteUser, sortFlag,
159                             sortedBy);
160                     }
161                 } else {
162                     if (inJahia.equals("true")) {
163                         list = AccessDB.loadListCardSinUser(contextId, sortFlag,
164                             sortedBy);
165                     } else {
166                         list = AccessDB.loadListCardSinUser(sortFlag, sortedBy);
167                     }
168
169                 }
170             } else {
171                 String JavaDoc status = "Validated";
172                 if (useMode.equals("user")) {
173                     if (inJahia.equals("true")) {
174
175                         list = AccessDB.loadList(remoteUser, contextId, status,
176                                                  sortFlag,
177                                                  sortedBy);
178                     }
179
180                     else {
181                         list = AccessDB.loadList(remoteUser, status, sortFlag,
182                                                  sortedBy);
183
184                     }
185                 } else {
186                     if (inJahia.equals("true")) {
187
188                         list = AccessDB.loadListSinUser(contextId, status,
189                             sortFlag,
190                             sortedBy);
191                     }
192
193                     else {
194                         logger.debug("info passage " + status);
195                         list = AccessDB.loadListSinUser(status, sortFlag,
196                             sortedBy);
197
198                     }
199
200                 }
201             }
202             this.cards.clear();
203             if (list == null) {
204             } else {
205                 for (int i = 0; i < list.size(); i++) {
206
207                     Vector v = new Vector();
208                     Card crd = (Card) list.get(i);
209
210                     // set the cards in the list
211
v.add("x");
212                     v.add(crd.getLastName());
213                     v.add(crd.getFirstName());
214                     v.add(crd.getAbsenceType());
215                     v.add(crd.getFirstAbsenceDay());
216                     v.add(crd.getLastAbsenceDay());
217                     v.add(crd.getUser());
218                     v.add(crd.getContextId());
219                     v.add(crd.getStatus());
220
221                     crd.setFields(v);
222
223                     this.cards.add(crd);
224                 }
225
226             }
227         } catch (Exception JavaDoc e) {
228             logger.error("ListCards: load", e);
229         }
230
231     }
232
233 }
234
Popular Tags