KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
11  * Represents a card given its id, the specific table name, a vector with the fields values and a vector with the fields names
12  *
13  * @author Yann Gentil <a HREF="mailto:gentil@xo3.com">gentil@xo3.com</a>
14  * @version %I%, %G%
15  */

16
17 public class Card
18 {
19   private static org.apache.log4j.Logger logger =
20       org.apache.log4j.Logger.getLogger(Card.class);
21     /** The id of the card **/
22     private int id;
23     /** The name of the card library **/
24     private String JavaDoc cardLibraryName;
25     /** The values of the card's fields **/
26     private Vector fields = new Vector();
27     /** The names of the card's fields **/
28     private Vector fieldsName = new Vector();
29     private String JavaDoc firstName;
30     private String JavaDoc absenceType;
31     private String JavaDoc firstAbsenceDay;
32     private String JavaDoc lastAbsenceDay;
33     private String JavaDoc user;
34     private String JavaDoc contextId;
35     private String JavaDoc status;
36     private String JavaDoc lastName;
37
38
39     /**
40      * Create a new card
41      */

42     public Card()
43     {
44     }
45
46     /**
47      * Create a new card with id and fields
48      *
49      * @param id the id of the card
50      * @param fields a vector that contains the values of the fields
51      * @param fieldsName a vector that contains the names of the fields
52      */

53     public Card(int id, Vector fields, Vector fieldsName)
54     {
55         this.id = id;
56         this.fields = fields;
57         this.fieldsName = fieldsName;
58     }
59
60
61     /**
62      * Load a card from DB
63      *
64      * @param id the card id to read in database
65      * @param cardLibrary name the name of the card library
66      */

67     public Card(int id, String JavaDoc cardLibraryName)
68     {
69         this.id = id;
70         this.cardLibraryName = cardLibraryName;
71         this.loadFields();
72     }
73
74
75     /**
76      * Set the card id
77      *
78      * @param id
79      */

80     public void setId(int id)
81     {
82         this.id = id;
83     }
84
85     /**
86      * Get the card id
87      *
88      * @return id
89      */

90      public int getId()
91      {
92         return this.id;
93      }
94
95
96     /**
97      * Set the card fields
98      *
99      * @param fields the fields values of the card
100      */

101     public void setFields(Vector fields)
102     {
103         this.fields = fields;
104     }
105
106
107     /**
108      * Set the card fields names
109      *
110      * @param fieldsNames the names of the card's fields
111      */

112     public void setFieldsName(Vector fieldsNames)
113     {
114         this.fieldsName = fieldsNames;
115     }
116
117
118     /**
119      * Set the card library name
120      *
121      * @param name the card library name
122      */

123     public void setCardLibraryName(String JavaDoc name)
124     {
125         this.cardLibraryName = name;
126     }
127
128
129     /**
130      * Get the card fields
131      *
132      * @return fields vector that contains the values of the card's fields
133      */

134     public Vector getFields()
135     {
136         return this.fields;
137     }
138
139
140     /**
141      * Get the card fieldsName
142      *
143      * @return fields vector that contains the names of the card's fields
144      */

145     public Vector getFieldsName()
146     {
147         return this.fieldsName;
148     }
149
150
151     /**
152      * Get the cardLibrary Name
153      *
154      * @return cardLibraryName
155      */

156     public String JavaDoc getCardLibraryName()
157     {
158         return this.cardLibraryName;
159     }
160
161
162
163     /**
164      * Method filter
165      * Filter special caracters
166      *
167      * @param input String to filter
168      * @return a filtered string
169      */

170     public static String JavaDoc filter(String JavaDoc input)
171     {
172         StringBuffer JavaDoc filtered = new StringBuffer JavaDoc ( input.length() );
173         char c;
174
175         for ( int i = 0 ; i < input.length(); i++ )
176         {
177             c = input.charAt(i);
178             if ( c == '\'' ) {
179                 filtered.append( "&#39;" );
180             } else if ( c== '"' ) {
181                 filtered.append( "&#34;" );
182             } else {
183                 filtered.append(c);
184             }
185         }
186         return (filtered.toString());
187     }
188
189
190     /**
191      * Load the fields of this card
192      *
193      */

194     public void loadFields() {
195       // select the right card in DB
196
try {
197
198         ResultSet rs;
199         boolean flag = true;
200         Card crd = AccessDB.findCard(this.id);
201         //rs = AccessDB.execSql("select * from "+ cardLibraryName
202
// + " where card_id=" + this.id );
203
Vector cards = new Vector();
204         if(crd!=null) {
205
206         }
207         else {
208           // if there isn't a card after, try from beginning
209

210           cards = AccessDB.findNextCards(this.id);
211
212           // rs = AccessDB.execSql("select * from "+ cardLibraryName
213
// + " where card_id>=" + this.id );
214

215           if (cards.size() == 0) {
216             flag = false;
217
218           }
219           else {
220
221             crd = (Card) cards.get(0);
222
223           }
224
225         }
226
227         if (flag) {
228
229           this.id = crd.getId();
230
231           // get the names of the fields
232
// ResultSetMetaData rsmd = rs.getMetaData();
233
//int numberofColumns = rsmd.getColumnCount();
234
this.fieldsName.add("CARD_ID");
235           this.fieldsName.add("NAME");
236           this.fieldsName.add("FIRSTNAME");
237           this.fieldsName.add("ABSENCETYPE");
238           this.fieldsName.add("FIRSTABSENCEDAY");
239           this.fieldsName.add("LASTABSENCEDAY");
240           this.fieldsName.add("USER");
241           this.fieldsName.add("CONTEXTID");
242           this.fieldsName.add("STATUS");
243           this.fields.add(String.valueOf(this.id));
244           this.fields.add(crd.getLastName());
245           this.fields.add(crd.getFirstName());
246           this.fields.add(crd.getAbsenceType());
247           this.fields.add(crd.getFirstAbsenceDay());
248           this.fields.add(crd.getLastAbsenceDay());
249           this.fields.add(crd.getUser());
250           this.fields.add(crd.getContextId());
251           this.fields.add(crd.getStatus());
252
253           // set the card's fields
254

255         }
256       }
257       catch (Exception JavaDoc e) {
258         logger.error("Card: load", e);
259       }
260     }
261
262     public String JavaDoc getContextId() {
263       return contextId;
264     }
265
266     public void setContextId(String JavaDoc contextId) {
267       this.contextId = contextId;
268     }
269
270     public String JavaDoc getFirstAbsenceDay() {
271       return firstAbsenceDay;
272     }
273
274     public void setFirstAbsenceDay(String JavaDoc firstAbsenceDay) {
275       this.firstAbsenceDay = firstAbsenceDay;
276     }
277
278     public String JavaDoc getFirstName() {
279       return firstName;
280     }
281
282     public void setFirstName(String JavaDoc firstName) {
283       this.firstName = firstName;
284     }
285
286     public String JavaDoc getLastAbsenceDay() {
287       return lastAbsenceDay;
288     }
289
290     public void setLastAbsenceDay(String JavaDoc lastAbsenceDay) {
291       this.lastAbsenceDay = lastAbsenceDay;
292     }
293
294     public String JavaDoc getStatus() {
295       return status;
296     }
297
298     public void setStatus(String JavaDoc status) {
299       this.status = status;
300   }
301   public String JavaDoc getUser() {
302     return user;
303   }
304   public void setUser(String JavaDoc user) {
305     this.user = user;
306   }
307   public String JavaDoc getAbsenceType() {
308     return absenceType;
309   }
310   public void setAbsenceType(String JavaDoc absenceType) {
311     this.absenceType = absenceType;
312   }
313   public String JavaDoc getLastName() {
314     return lastName;
315   }
316   public void setLastName(String JavaDoc lastName) {
317     this.lastName = lastName;
318   }
319
320
321 }
322
Popular Tags