View Javadoc

1   /*Copyright (C) 2004-... Stephane Gauchet for Hyphonem
2   
3    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
4   
5    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6   
7    You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8    
9    Written by St�phane Gauchet
10   mail me at : sgauchet@free.fr
11   */
12  package fr.hyphonem.conges;
13  
14  import java.io.File;
15  import java.io.FileInputStream;
16  import java.io.FileWriter;
17  import java.io.IOException;
18  import java.io.Writer;
19  import java.text.SimpleDateFormat;
20  import java.util.Date;
21  import java.util.Enumeration;
22  import java.util.Hashtable;
23  import java.util.Iterator;
24  import java.util.List;
25  import java.util.Vector;
26  import java.util.logging.Logger;
27  
28  import javax.xml.parsers.DocumentBuilder;
29  import javax.xml.parsers.DocumentBuilderFactory;
30  
31  import org.apache.commons.jxpath.JXPathContext;
32  import org.apache.commons.jxpath.JXPathException;
33  import org.apache.xml.serialize.OutputFormat;
34  import org.apache.xml.serialize.XMLSerializer;
35  import org.w3c.dom.Document;
36  import org.w3c.dom.Element;
37  import org.w3c.dom.Node;
38  import org.w3c.dom.NodeList;
39  import org.xml.sax.SAXParseException;
40  
41  import fr.hyphonem.conges.data.CalendarData;
42  import fr.hyphonem.conges.data.EmployeeData;
43  import fr.hyphonem.conges.data.EmployeeIdCalData;
44  import fr.hyphonem.conges.data.NationalDayData;
45  import fr.hyphonem.conges.data.ParamsData;
46  import fr.hyphonem.conges.data.PendingEventData;
47  import fr.hyphonem.conges.data.PeriodData;
48  import fr.hyphonem.conges.data.ReasonData;
49  import fr.hyphonem.conges.data.UserData;
50  
51  /**
52   * @author Stephane Gauchet pour Hyphonem
53   * 
54   * give access to data stored in XML files
55   */
56  public class AccessDataXMLImpl implements AccessData {
57  
58  	private EmployeeData ed;
59  
60  	private CalendarData cd;
61  
62  	private String dataDirPath;
63  
64  	private String fromDate;
65  
66  	private String toDate;
67  
68  	/**
69  	 * Constructor for AccessDataFileImpl
70  	 */
71  	public AccessDataXMLImpl() {
72  		super();
73  	}
74  
75  	/**
76  	 * Constructor for AccessDataFileImpl with an Employee,
77  	 * pathToDirOfXMLDataFiles and begin and end dates
78  	 * 
79  	 * @param ed
80  	 * @param dataDirPath
81  	 * @param fromDate
82  	 * @param toDate
83  	 */
84  	public AccessDataXMLImpl(EmployeeData ed, String dataDirPath,
85  			String fromDate, String toDate) {
86  		super();
87  		this.ed = ed;
88  		this.dataDirPath = dataDirPath;
89  		this.fromDate = fromDate;
90  		this.toDate = toDate;
91  	}
92  
93  	/**
94  	 * Constructor for AccessDataFileImpl with an Employee, a calendarData and
95  	 * pathToDirOfXMLDataFiles and begin and end dates
96  	 * 
97  	 * @param ed
98  	 * @param cd
99  	 * @param dataDirPath
100 	 * @param fromDate
101 	 * @param toDate
102 	 */
103 	public AccessDataXMLImpl(EmployeeData ed, CalendarData cd,
104 			String dataDirPath, String fromDate, String toDate) {
105 		super();
106 		this.ed = ed;
107 		this.cd = cd;
108 		this.dataDirPath = dataDirPath;
109 		this.fromDate = fromDate;
110 		this.toDate = toDate;
111 	}
112 
113 	/**
114 	 * Constructor for AccessDataFileImpl with pathToDirOfXMLDataFiles
115 	 * 
116 	 * @param dataPath
117 	 */
118 	public AccessDataXMLImpl(String dataPath) {
119 		super();
120 		dataDirPath = dataPath;
121 	}
122 
123 	/**
124 	 * @return CalendarData
125 	 */
126 	public CalendarData getCd() {
127 		return cd;
128 	}
129 
130 	/**
131 	 * @return String
132 	 */
133 	public String getDataDirPath() {
134 		return dataDirPath;
135 	}
136 
137 	/**
138 	 * @return String
139 	 */
140 	public EmployeeData getEd() {
141 		return ed;
142 	}
143 
144 	/**
145 	 * @return String
146 	 */
147 	public String getFromDate() {
148 		return fromDate;
149 	}
150 
151 	/**
152 	 * @return String
153 	 */
154 	public String getToDate() {
155 		return toDate;
156 	}
157 
158 	/**
159 	 * @param data
160 	 */
161 	public void setCd(CalendarData data) {
162 		cd = data;
163 	}
164 
165 	/**
166 	 * @param string
167 	 */
168 	public void setDataDirPath(String string) {
169 		dataDirPath = string;
170 	}
171 
172 	/**
173 	 * @param data
174 	 */
175 	public void setEd(EmployeeData data) {
176 		ed = data;
177 	}
178 
179 	/**
180 	 * @param string
181 	 */
182 	public void setFromDate(String string) {
183 		fromDate = string;
184 	}
185 
186 	/**
187 	 * @param string
188 	 */
189 	public void setToDate(String string) {
190 		toDate = string;
191 	}
192 
193 	/**
194 	 * read from data all CalendarData
195 	 * 
196 	 * @param employee -
197 	 *            EmployeeData
198 	 * @return Vector of CalendarData
199 	 * @throws Exception
200 	 * @see AccessData
201 	 */
202 	public Vector readCalendarData(EmployeeData employee) throws Exception {
203 		// System.out.println("d�but AccessDataXMLImpl readCalendarData");
204 		Vector vCalendarData = new Vector();
205 
206 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
207 		DocumentBuilder constructeur = usine.newDocumentBuilder();
208 		Document document;
209 
210 		String fileName = employee.getPrenom().toUpperCase() + "_"
211 				+ employee.getNom().toUpperCase() + ".xml";
212 
213 		String pathFileName = dataDirPath + File.separator + fileName;
214 		File employeeDataFile = new File(pathFileName);
215 
216 		if (employeeDataFile.exists()) {
217 			document = constructeur.parse(employeeDataFile);
218 			// DEBUT JXPath
219 			JXPathContext context = JXPathContext.newContext(document);
220 			List nodeList = context.selectNodes("/absences/absence");
221 			Iterator iter = nodeList.iterator();
222 			while (iter.hasNext()) {
223 
224 				Element absence = (Element) iter.next();
225 				// System.out.println("longueur = "+absences.getLength());
226 				CalendarData cd = new CalendarData();
227 				context = JXPathContext.newContext(absence);
228 				cd.setId((String) context.getValue("/id"));
229 				cd.setDatedeb((String) context.getValue("/beginDate"));
230 				cd.setDatefin((String) context.getValue("/endDate"));
231 				cd.setCbmatin(Boolean.parseBoolean((String) context
232 						.getValue("/morning")));
233 				cd.setCbaprem(Boolean.parseBoolean((String) context
234 						.getValue("/afternoon")));
235 				cd.setRaison((String) context.getValue("/reason"));
236 				// FIN JXPath
237 
238 				// System.out.println("cd="+cd.getId());
239 				if (cd.getId() != null) {
240 					String deb = cd.getDatedeb();
241 					String fin = cd.getDatefin();
242 					Date ddeb = new SimpleDateFormat("dd/MM/yyyy").parse(deb);
243 					Date dfin = new SimpleDateFormat("dd/MM/yyyy").parse(fin);
244 
245 					if (fromDate != null && toDate != null) {
246 						Date first = new SimpleDateFormat("dd/MM/yyyy")
247 								.parse(fromDate);
248 						Date last = new SimpleDateFormat("dd/MM/yyyy")
249 								.parse(toDate);
250 
251 						boolean ok = false;
252 						if (ddeb.compareTo(first) >= 0
253 								&& ddeb.compareTo(last) <= 0) {
254 							if (dfin.compareTo(first) >= 0
255 									&& dfin.compareTo(last) <= 0) {
256 								ok = true;
257 							} else if (dfin.compareTo(first) < 0) {
258 								ok = false;
259 							} else if (dfin.compareTo(last) > 0) {
260 								ok = true;
261 								cd.setDatefin(toDate);
262 							} else if (ddeb.compareTo(first) < 0) {
263 								if (dfin.compareTo(first) >= 0
264 										&& dfin.compareTo(last) <= 0) {
265 									ok = true;
266 									cd.setDatedeb(fromDate);
267 								} else if (dfin.compareTo(first) < 0) {
268 									ok = false;
269 								} else if (dfin.compareTo(last) > 0) {
270 									ok = true;
271 									cd.setDatefin(toDate);
272 									cd.setDatedeb(fromDate);
273 								}
274 							}
275 						}
276 
277 						if (ok) {
278 							cd.setEmployee(employee);
279 							vCalendarData.add(cd);
280 						}
281 					}
282 				}
283 			}
284 		}
285 
286 		// System.out.println("fin AccessDataXMLImpl readCalendarData");
287 		return vCalendarData;
288 	}
289 
290 	/**
291 	 * write a calendarData in data
292 	 * 
293 	 * @param cd -
294 	 *            CalendarData
295 	 * @param modif -
296 	 *            boolean
297 	 * @throws Exception
298 	 * @see AccessData
299 	 */
300 	public void writeCalendarData(CalendarData cd, boolean modif)
301 			throws Exception {
302 		writeCalendarData(cd, modif, false);
303 	}
304 
305 	/**
306 	 * write a calendarData in data with delete parameter
307 	 * 
308 	 * @param cd -
309 	 *            CalendarData
310 	 * @param modif -
311 	 *            boolean
312 	 * @param delete -
313 	 *            boolean
314 	 * @throws Exception
315 	 * @see AccessData
316 	 */
317 	public void writeCalendarData(CalendarData cd, boolean modif, boolean delete)
318 			throws Exception {
319 
320 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
321 		DocumentBuilder constructeur = usine.newDocumentBuilder();
322 		Document doc;
323 		// System.out.println("1");
324 		String fileName = cd.getEmployee().getPrenom().toUpperCase() + "_"
325 				+ cd.getEmployee().getNom().toUpperCase() + ".xml";
326 		String pathFileName = dataDirPath + File.separator + fileName;
327 		// System.out.println("file="+pathFileName);
328 		File employeeDataFile = new File(pathFileName);
329 		// System.out.println("2");
330 		Node root;
331 		if (employeeDataFile != null && employeeDataFile.exists()) {
332 			doc = constructeur.parse(employeeDataFile);
333 			// noeud absences root
334 			root = doc.getFirstChild();
335 		} else {
336 			doc = constructeur.newDocument();
337 			root = doc.createElement("absences");
338 			doc.appendChild(root);
339 		}
340 		// ce test ne sert plus à rien, meme 2 demies journées de meme raison
341 		// posées séparément doivent rester séparées
342 		// if(!delete)
343 		// {
344 		// //cette boucle sert � g�rer un cas pas facile en xml
345 		// // si un enregistrement est deja cree sur une demi journee
346 		// //et que l'on cree ou on modifie un autre enreg sur l autre demi
347 		// journee
348 		// // il faut d abord supprimer le premier enreg
349 		// // si evidemment il est en doublon ou si la raison est la meme
350 		// Vector deletableElements = new Vector();
351 		// JXPathContext context = JXPathContext.newContext(doc);
352 		// List nodeList =
353 		// context.selectNodes("/absences/absence[beginDate=\""+cd.getDatedeb()+"\"]");
354 		// Iterator iter = nodeList.iterator();
355 		// while(iter.hasNext())
356 		// {
357 		// Element absence = (Element) iter.next();
358 		//			
359 		// if(cd.isCbmatin() && cd.isCbaprem())
360 		// {
361 		// deletableElements.add(absence);
362 		// modif=false;
363 		// delete=false;
364 		// //bref on crée un nouvel enregistrement
365 		// }
366 		// else
367 		// {
368 		// context=JXPathContext.newContext(absence);
369 		// String morning = (String) context.getValue("/morning");
370 		// if(new Boolean(morning).booleanValue()==cd.isCbmatin())
371 		// {
372 		// deletableElements.add(absence);
373 		// modif=false;
374 		// delete=false;
375 		// }
376 		// else
377 		// {
378 		// String afternoon = (String) context.getValue("/afternoon");
379 		// if(new Boolean(afternoon).booleanValue()==cd.isCbaprem())
380 		// {
381 		// deletableElements.add(absence);
382 		// modif=false;
383 		// delete=false;
384 		// //bref on cr�e un nouvel enregistrement
385 		// }
386 		// else
387 		// {
388 		// String reason = (String) context.getValue("/reason");
389 		// if(reason.equals(cd.getRaison()))
390 		// {
391 		// deletableElements.add(absence);
392 		// if(!cd.isCbaprem())
393 		// cd.setCbaprem(true);
394 		// else
395 		// if(!cd.isCbmatin())
396 		// cd.setCbmatin(true);
397 		// modif=false;
398 		// delete=false;
399 		// //bref on cr�e un nouvel enregistrement
400 		// }
401 		// else
402 		// {
403 		// //do nothing
404 		// }
405 		// }
406 		// }
407 		// }
408 		// }
409 		// for(Enumeration enumeration = deletableElements.elements();
410 		// enumeration.hasMoreElements();)
411 		// {
412 		// Element elm = (Element) enumeration.nextElement();
413 		// elm.getParentNode().removeChild(elm);
414 		// }
415 		// }
416 		// mettre le cd dans un DOM & ecrire le fichier
417 		if (delete) {
418 			JXPathContext context = JXPathContext.newContext(doc);
419 			List nodeList = context.selectNodes("/absences/absence[id=\""
420 					+ cd.getId() + "\"]");
421 			Iterator iter = nodeList.iterator();
422 			while (iter.hasNext()) {
423 				Element absence = (Element) iter.next();
424 				absence.getParentNode().removeChild(absence);
425 			}
426 		} else {
427 			// creation du noeud absence
428 			Element nodePrincipal = doc.createElement("absence");
429 
430 			// creation du noeud beginDate
431 			Element nodeid = doc.createElement("id");
432 			nodeid.appendChild(doc.createTextNode(cd.getId()));
433 			// creation du noeud beginDate
434 			Element nodebd = doc.createElement("beginDate");
435 			nodebd.appendChild(doc.createTextNode(cd.getDatedeb()));
436 			// creation du noeud endDate
437 			Element nodeed = doc.createElement("endDate");
438 			nodeed.appendChild(doc.createTextNode(cd.getDatefin()));
439 			// creation du noeud morning
440 			Element nodem = doc.createElement("morning");
441 			nodem.appendChild(doc.createTextNode("" + cd.isCbmatin()));
442 			// creation du noeud afternoon
443 			Element nodea = doc.createElement("afternoon");
444 			nodea.appendChild(doc.createTextNode("" + cd.isCbaprem()));
445 			// creation du noeud reason
446 			Element noder = doc.createElement("reason");
447 			noder.appendChild(doc.createTextNode(cd.getRaison()));
448 
449 			// System.out.println("4");
450 			nodePrincipal.appendChild(nodeid);
451 			nodePrincipal.appendChild(nodebd);
452 			nodePrincipal.appendChild(nodeed);
453 			nodePrincipal.appendChild(nodem);
454 			nodePrincipal.appendChild(nodea);
455 			nodePrincipal.appendChild(noder);
456 
457 			root.appendChild(nodePrincipal);
458 
459 			// System.out.println("value =
460 			// "+noder.getFirstChild().getNodeValue());
461 		}
462 		// System.out.println("5");
463 		writeToXML(doc, pathFileName, "");
464 		// System.out.println("6");
465 	}
466 
467 	/**
468 	 * write DOM in XML file
469 	 * 
470 	 * @param doc -
471 	 *            Document input DOM document
472 	 * @param outputName -
473 	 *            String output file name
474 	 * @param encType -
475 	 *            String encoding type value "UTF" for UTF-8 other value for
476 	 *            ISO-8859-1 (default)
477 	 * @throws Exception
478 	 */
479 	public void writeToXML(Document doc, String outputName, String encType)
480 			throws Exception {
481 		OutputFormat outf = new OutputFormat();
482 		outf.setIndent(0);
483 		outf.setIndenting(true);
484 		if (encType.equals("UTF")) {
485 			outf.setEncoding("UTF-8");
486 		} else {
487 			outf.setEncoding("ISO-8859-1");
488 		}
489 
490 		try {
491 			Writer xmlOut = new FileWriter(outputName);
492 
493 			XMLSerializer xmls = new XMLSerializer(xmlOut, outf);
494 			xmls.serialize(doc);
495 		} catch (IOException e) {
496 			System.out
497 					.println("conflit de concurrence d'acc�s sur le fichier : "
498 							+ outputName);
499 			throw e;
500 		} catch (Exception e) {
501 			throw e;
502 		}
503 	}
504 
505 	/**
506 	 * search a user with login and password parameters
507 	 * 
508 	 * @param login
509 	 * @param password
510 	 * @return UserData
511 	 * @throws Exception
512 	 * @see AccessData
513 	 */
514 	public UserData searchUser(String login, String password) throws Exception {
515 		// System.out.println("debut AccessDataXMLImpl readUsers");
516 
517 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
518 		DocumentBuilder constructeur = usine.newDocumentBuilder();
519 		Document document;
520 
521 		String fileName = "users.xml";
522 		String pathFileName = dataDirPath + File.separator + fileName;
523 		File userFile = new File(pathFileName);
524 
525 		UserData ud = null;
526 
527 		if (userFile.exists()) {
528 			document = constructeur.parse(userFile);
529 
530 			// DEBUT JXPath
531 			JXPathContext context = JXPathContext.newContext(document);
532 			String xpath = "/users/user[login=\"" + login
533 					+ "\" and password=\"" + password + "\"]";
534 			Element user = (Element) context.selectSingleNode(xpath);
535 			context = JXPathContext.newContext(user);
536 			ud = new UserData();
537 			ud.setLogin((String) context.getValue("login"));
538 			ud.setPassword((String) context.getValue("password"));
539 			ud.setEmail((String) context.getValue("email"));
540 			ud.setEmployee(Boolean.parseBoolean((String) context
541 					.getValue("employee")));
542 			ud.setModif(Boolean
543 					.parseBoolean((String) context.getValue("modif")));
544 			ud.setNom((String) context.getValue("nom"));
545 			ud.setPrenom((String) context.getValue("prenom"));
546 			ud.setTeam((String) context.getValue("team"));
547 			// FIN JXPATH
548 		} else {
549 			ud = null;
550 		}
551 
552 		// System.out.println("fin AccessDataXMLImpl readUsers");
553 
554 		return ud;
555 	}
556 
557 	/**
558 	 * read all employees from data
559 	 * 
560 	 * @return Vector of EmployeeData
561 	 * @throws Exception
562 	 */
563 	public Vector readEmployees() throws Exception {
564 		// System.out.println("debut AccessDataXMLImpl readEmployees");
565 		Vector employees = new Vector();
566 
567 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
568 		DocumentBuilder constructeur = usine.newDocumentBuilder();
569 		Document document;
570 
571 		String fileName = "employees.xml";
572 		String pathFileName = dataDirPath + File.separator + fileName;
573 		File employeesFile = new File(pathFileName);
574 
575 		if (employeesFile.exists()) {
576 			document = constructeur.parse(employeesFile);
577 			// DEBUT JXPath
578 			JXPathContext context = JXPathContext.newContext(document);
579 			List nodeList = context.selectNodes("/employees/employee");
580 			Iterator iter = nodeList.iterator();
581 			while (iter.hasNext()) {
582 				EmployeeData ed = new EmployeeData();
583 				Element employee = (Element) iter.next();
584 				context = JXPathContext.newContext(employee);
585 				ed.setPays((String) context.getValue("/pays"));
586 				ed.setNom((String) context.getValue("/nom"));
587 				ed.setPrenom((String) context.getValue("/prenom"));
588 				ed.setTeam((String) context.getValue("/team"));
589 				try {
590 					ed.setEntryDate((String) context.getValue("/entryDate"));
591 				} catch (JXPathException e) {
592 					ed.setEntryDate("");
593 				}
594 				try {
595 					ed.setDayoff1(Boolean.parseBoolean((String) context
596 							.getValue("/dayoff1")));
597 				} catch (JXPathException e) {
598 					ed.setDayoff1(false);
599 				}
600 				try {
601 					ed.setDayoff2(Boolean.parseBoolean((String) context
602 							.getValue("/dayoff2")));
603 				} catch (JXPathException e) {
604 					ed.setDayoff2(false);
605 				}
606 				try {
607 					ed.setDayoff3(Boolean.parseBoolean((String) context
608 							.getValue("/dayoff3")));
609 				} catch (JXPathException e) {
610 					ed.setDayoff3(false);
611 				}
612 				try {
613 					ed.setDayoff4(Boolean.parseBoolean((String) context
614 							.getValue("/dayoff4")));
615 				} catch (JXPathException e) {
616 					ed.setDayoff4(false);
617 				}
618 				try {
619 					ed.setDayoff5(Boolean.parseBoolean((String) context
620 							.getValue("/dayoff5")));
621 				} catch (JXPathException e) {
622 					ed.setDayoff5(false);
623 				}
624 				try {
625 					ed.setDayoff6(Boolean.parseBoolean((String) context
626 							.getValue("/dayoff6")));
627 				} catch (JXPathException e) {
628 					// samedi est un dayoff par défaut
629 					ed.setDayoff6(true);
630 				}
631 				try {
632 					ed.setDayoff7(Boolean.parseBoolean((String) context
633 							.getValue("/dayoff7")));
634 				} catch (JXPathException e) {
635 					// dimanche est un dayoff par défaut
636 					ed.setDayoff7(true);
637 				}
638 
639 				employees.add(ed);
640 			}
641 			// FIN JXPath
642 		}
643 
644 		// System.out.println("fin AccessDataXMLImpl readEmployees");
645 		return employees;
646 
647 	}
648 
649 	/**
650 	 * write a user in data
651 	 * 
652 	 * @param user
653 	 * @throws Exception
654 	 */
655 	public void writeUser(UserData user) throws Exception {
656 		writeUser(user, false, false);
657 	}
658 
659 	/**
660 	 * write a user with delete and modif parameters
661 	 * 
662 	 * @param user -
663 	 *            UserData
664 	 * @param modif -
665 	 *            boolean
666 	 * @param delete -
667 	 *            boolean
668 	 * @throws Exception
669 	 */
670 	public void writeUser(UserData user, boolean modif, boolean delete)
671 			throws Exception {
672 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
673 		DocumentBuilder constructeur = usine.newDocumentBuilder();
674 		Document doc;
675 		// System.out.println("1");
676 		String fileName = "users.xml";
677 		String pathFileName = dataDirPath + File.separator + fileName;
678 		// System.out.println("file="+pathFileName);
679 		File usersFile = new File(pathFileName);
680 		// System.out.println("2");
681 		Node root;
682 		if (usersFile != null && usersFile.exists()) {
683 			doc = constructeur.parse(usersFile);
684 			// noeud users root
685 			root = doc.getFirstChild();
686 			if (modif) {
687 
688 				JXPathContext context = JXPathContext.newContext(doc);
689 				List nodeList = context.selectNodes("/users/user[login=\""
690 						+ user.getLogin() + "\"]");
691 				Iterator iter = nodeList.iterator();
692 				while (iter.hasNext()) {
693 					// NodeList lst = doc.getElementsByTagName("login");
694 					// System.out.println("size="+lst.getLength());
695 					// for(int i = 0; i < lst.getLength(); i++)
696 					// {
697 					// Node loginNode = lst.item(i);
698 					Element userToModify = (Element) iter.next();
699 					// String value = loginNode.getFirstChild().getNodeValue();
700 					// System.out.println("value="+value);
701 					// System.out.println("login="+user.getLogin());
702 					// if(value.equals(user.getLogin()))
703 					// {
704 					// Node userToModify = loginNode.getParentNode();
705 					if (delete) {
706 						// System.out.println("login="+user.getLogin());
707 						// suppression du noeud concern�
708 						userToModify.getParentNode().removeChild(userToModify);
709 					} else {
710 						NodeList childs = userToModify.getChildNodes();
711 						for (int j = 0; j < childs.getLength(); j++) {
712 							Node node = childs.item(j);
713 							String name = node.getNodeName();
714 							if (name.equals("login")) {
715 								Node nodeToRemove = node.getFirstChild();
716 								// System.out.println("test="+nodeToRemove.getNodeName()+"_"
717 								// + nodeToRemove.getNodeValue());
718 								Node bdv = doc.createTextNode(user.getLogin());
719 								node.replaceChild(bdv, nodeToRemove);
720 							}
721 							if (name.equals("password")) {
722 								Node nodeToRemove = node.getFirstChild();
723 								Node bdv = doc.createTextNode(user
724 										.getPassword());
725 								node.replaceChild(bdv, nodeToRemove);
726 							}
727 							if (name.equals("email")) {
728 								Node nodeToRemove = node.getFirstChild();
729 								Node bdv = doc.createTextNode(user.getEmail());
730 								node.replaceChild(bdv, nodeToRemove);
731 							}
732 							if (name.equals("employee")) {
733 								Node nodeToRemove = node.getFirstChild();
734 								Node bdv = doc.createTextNode(""
735 										+ user.isEmployee());
736 								node.replaceChild(bdv, nodeToRemove);
737 							}
738 							if (name.equals("modif")) {
739 								Node nodeToRemove = node.getFirstChild();
740 								// System.out.println("aprem2="+cd.isCbaprem());
741 								Node bdv = doc.createTextNode(""
742 										+ user.isModif());
743 								node.replaceChild(bdv, nodeToRemove);
744 							}
745 							if (name.equals("nom")) {
746 								Node nodeToRemove = node.getFirstChild();
747 								Node bdv = doc.createTextNode(user.getNom());
748 								node.replaceChild(bdv, nodeToRemove);
749 							}
750 							if (name.equals("prenom")) {
751 								Node nodeToRemove = node.getFirstChild();
752 								Node bdv = doc.createTextNode(user.getPrenom());
753 								node.replaceChild(bdv, nodeToRemove);
754 							}
755 							if (name.equals("team")) {
756 								Node nodeToRemove = node.getFirstChild();
757 								Node bdv = doc.createTextNode(user.getTeam());
758 								node.replaceChild(bdv, nodeToRemove);
759 							}
760 						}
761 					}
762 					// }
763 				}
764 			} else {
765 				// creation du noeud user
766 				Element nodePrincipal = doc.createElement("user");
767 
768 				// creation du noeud login
769 				Element nodeid = doc.createElement("login");
770 				nodeid.appendChild(doc.createTextNode(user.getLogin()));
771 				// creation du noeud password
772 				Element nodebd = doc.createElement("password");
773 				nodebd.appendChild(doc.createTextNode(user.getPassword()));
774 				// creation du noeud nom
775 				Element nodeed = doc.createElement("nom");
776 				nodeed.appendChild(doc.createTextNode(user.getNom()));
777 				// creation du noeud prenom
778 				Element nodem = doc.createElement("prenom");
779 				nodem.appendChild(doc.createTextNode(user.getPrenom()));
780 				// creation du noeud email
781 				Element nodea = doc.createElement("email");
782 				nodea.appendChild(doc.createTextNode(user.getEmail()));
783 				// creation du noeud modif
784 				Element noder = doc.createElement("modif");
785 				noder.appendChild(doc.createTextNode("" + user.isModif()));
786 				// creation du noeud employee
787 				Element nodee = doc.createElement("employee");
788 				nodee.appendChild(doc.createTextNode("" + user.isEmployee()));
789 				Element nodet = doc.createElement("team");
790 				nodet.appendChild(doc.createTextNode(user.getTeam()));
791 
792 				// System.out.println("4");
793 				nodePrincipal.appendChild(nodeid);
794 				nodePrincipal.appendChild(nodebd);
795 				nodePrincipal.appendChild(nodeed);
796 				nodePrincipal.appendChild(nodem);
797 				nodePrincipal.appendChild(nodea);
798 				nodePrincipal.appendChild(noder);
799 				nodePrincipal.appendChild(nodee);
800 				nodePrincipal.appendChild(nodet);
801 
802 				root.appendChild(nodePrincipal);
803 			}
804 			writeToXML(doc, pathFileName, "");
805 		}
806 	}
807 
808 	/**
809 	 * write an employee in data
810 	 * 
811 	 * @param employee -
812 	 *            EmployeeData
813 	 * @throws Exception
814 	 */
815 	public void writeEmployee(EmployeeData employee) throws Exception {
816 		writeEmployee(employee, null, false, false);
817 	}
818 
819 	/**
820 	 * write a modified employee
821 	 * 
822 	 * @param employee -
823 	 *            EmployeeData
824 	 * @param modifiedEmployee -
825 	 *            EmployeeData
826 	 * @param modif -
827 	 *            boolean
828 	 * @param delete -
829 	 *            boolean
830 	 * @throws Exception
831 	 */
832 	public void writeEmployee(EmployeeData employee,
833 			EmployeeData modifiedEmployee, boolean modif, boolean delete)
834 			throws Exception {
835 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
836 		DocumentBuilder constructeur = usine.newDocumentBuilder();
837 		Document doc;
838 		// System.out.println("1");
839 		String fileName = "employees.xml";
840 		String pathFileName = dataDirPath + File.separator + fileName;
841 		// System.out.println("file="+pathFileName);
842 		File employeeDataFile = new File(pathFileName);
843 		// System.out.println("2");
844 		Node root;
845 		if (employeeDataFile != null && employeeDataFile.exists()) {
846 			doc = constructeur.parse(employeeDataFile);
847 			// noeud absences root
848 			root = doc.getFirstChild();
849 
850 			if (modif) {
851 				JXPathContext context = JXPathContext.newContext(doc);
852 				List nodeList = context
853 						.selectNodes("/employees/employee[nom=\""
854 								+ employee.getNom() + "\" and prenom=\""
855 								+ employee.getPrenom() + "\"]");
856 				Iterator iter = nodeList.iterator();
857 				while (iter.hasNext()) {
858 
859 					Element employeeToModify = (Element) iter.next();
860 
861 					if (delete) {
862 						// suppression du noeud concern�
863 						employeeToModify.getParentNode().removeChild(
864 								employeeToModify);
865 					} else {
866 						if (modifiedEmployee != null) {
867 							// case that create entryDate field in data for when
868 							// entryDate is newly set
869 							// add on 04/02/2005 - add entryDate in user forms
870 							try {
871 								context
872 										.selectSingleNode("/employees/employee[nom=\""
873 												+ employee.getNom()
874 												+ "\" and prenom=\""
875 												+ employee.getPrenom()
876 												+ "\"]/entryDate");
877 							} catch (JXPathException e) {
878 								// System.out.println("creer entryDate");
879 								Node bdv = doc.createTextNode(modifiedEmployee
880 										.getEntryDate());
881 								Element nodeed = doc.createElement("entryDate");
882 								nodeed.appendChild(bdv);
883 								employeeToModify.appendChild(nodeed);
884 								root.appendChild(employeeToModify);
885 							}
886 							// case that create dayoffs in data for when dayoffs
887 							// are newly set
888 							// add on 12/07/2007 - add dayoff 1 to 7 in user
889 							// forms
890 							try {
891 								context
892 										.selectSingleNode("/employees/employee[nom=\""
893 												+ employee.getNom()
894 												+ "\" and prenom=\""
895 												+ employee.getPrenom()
896 												+ "\"]/dayoff1");
897 							} catch (JXPathException e) {
898 								Node bdv = doc.createTextNode(modifiedEmployee
899 										.getEntryDate());
900 								Element nodeed = doc.createElement("dayoff1");
901 								nodeed.appendChild(bdv);
902 								employeeToModify.appendChild(nodeed);
903 								root.appendChild(employeeToModify);
904 							}
905 							try {
906 								context
907 										.selectSingleNode("/employees/employee[nom=\""
908 												+ employee.getNom()
909 												+ "\" and prenom=\""
910 												+ employee.getPrenom()
911 												+ "\"]/dayoff2");
912 							} catch (JXPathException e) {
913 								Node bdv = doc.createTextNode(modifiedEmployee
914 										.getEntryDate());
915 								Element nodeed = doc.createElement("dayoff2");
916 								nodeed.appendChild(bdv);
917 								employeeToModify.appendChild(nodeed);
918 								root.appendChild(employeeToModify);
919 							}
920 							try {
921 								context
922 										.selectSingleNode("/employees/employee[nom=\""
923 												+ employee.getNom()
924 												+ "\" and prenom=\""
925 												+ employee.getPrenom()
926 												+ "\"]/dayoff3");
927 							} catch (JXPathException e) {
928 								Node bdv = doc.createTextNode(modifiedEmployee
929 										.getEntryDate());
930 								Element nodeed = doc.createElement("dayoff3");
931 								nodeed.appendChild(bdv);
932 								employeeToModify.appendChild(nodeed);
933 								root.appendChild(employeeToModify);
934 							}
935 							try {
936 								context
937 										.selectSingleNode("/employees/employee[nom=\""
938 												+ employee.getNom()
939 												+ "\" and prenom=\""
940 												+ employee.getPrenom()
941 												+ "\"]/dayoff4");
942 							} catch (JXPathException e) {
943 								Node bdv = doc.createTextNode(modifiedEmployee
944 										.getEntryDate());
945 								Element nodeed = doc.createElement("dayoff4");
946 								nodeed.appendChild(bdv);
947 								employeeToModify.appendChild(nodeed);
948 								root.appendChild(employeeToModify);
949 							}
950 							try {
951 								context
952 										.selectSingleNode("/employees/employee[nom=\""
953 												+ employee.getNom()
954 												+ "\" and prenom=\""
955 												+ employee.getPrenom()
956 												+ "\"]/dayoff5");
957 							} catch (JXPathException e) {
958 								Node bdv = doc.createTextNode(modifiedEmployee
959 										.getEntryDate());
960 								Element nodeed = doc.createElement("dayoff5");
961 								nodeed.appendChild(bdv);
962 								employeeToModify.appendChild(nodeed);
963 								root.appendChild(employeeToModify);
964 							}
965 							try {
966 								context
967 										.selectSingleNode("/employees/employee[nom=\""
968 												+ employee.getNom()
969 												+ "\" and prenom=\""
970 												+ employee.getPrenom()
971 												+ "\"]/dayoff6");
972 							} catch (JXPathException e) {
973 								Node bdv = doc.createTextNode(modifiedEmployee
974 										.getEntryDate());
975 								Element nodeed = doc.createElement("dayoff6");
976 								nodeed.appendChild(bdv);
977 								employeeToModify.appendChild(nodeed);
978 								root.appendChild(employeeToModify);
979 							}
980 							try {
981 								context
982 										.selectSingleNode("/employees/employee[nom=\""
983 												+ employee.getNom()
984 												+ "\" and prenom=\""
985 												+ employee.getPrenom()
986 												+ "\"]/dayoff7");
987 							} catch (JXPathException e) {
988 								Node bdv = doc.createTextNode(modifiedEmployee
989 										.getEntryDate());
990 								Element nodeed = doc.createElement("dayoff7");
991 								nodeed.appendChild(bdv);
992 								employeeToModify.appendChild(nodeed);
993 								root.appendChild(employeeToModify);
994 							}
995 
996 							NodeList childs = employeeToModify.getChildNodes();
997 							for (int k = 0; k < childs.getLength(); k++) {
998 								Node node = childs.item(k);
999 								String name = node.getNodeName();
1000 								if (name.equals("nom")) {
1001 									Node nodeToRemove = node.getFirstChild();
1002 									Node bdv = doc
1003 											.createTextNode(modifiedEmployee
1004 													.getNom());
1005 									node.replaceChild(bdv, nodeToRemove);
1006 								}
1007 
1008 								if (name.equals("prenom")) {
1009 									Node nodeToRemove = node.getFirstChild();
1010 									Node bdv = doc
1011 											.createTextNode(modifiedEmployee
1012 													.getPrenom());
1013 									node.replaceChild(bdv, nodeToRemove);
1014 								}
1015 
1016 								if (name.equals("pays")) {
1017 									Node nodeToRemove = node.getFirstChild();
1018 									Node bdv = doc
1019 											.createTextNode(modifiedEmployee
1020 													.getPays());
1021 									node.replaceChild(bdv, nodeToRemove);
1022 								}
1023 
1024 								if (name.equals("team")) {
1025 									Node nodeToRemove = node.getFirstChild();
1026 									Node bdv = doc
1027 											.createTextNode(modifiedEmployee
1028 													.getTeam());
1029 									node.replaceChild(bdv, nodeToRemove);
1030 								}
1031 
1032 								if (name.equals("entryDate")) {
1033 									Node nodeToRemove = node.getFirstChild();
1034 									Node bdv = doc
1035 											.createTextNode(modifiedEmployee
1036 													.getEntryDate());
1037 									node.replaceChild(bdv, nodeToRemove);
1038 								}
1039 								if (name.equals("dayoff1")) {
1040 									Node nodeToRemove = node.getFirstChild();
1041 									Node bdv = doc.createTextNode(""
1042 											+ modifiedEmployee.isDayoff1());
1043 									node.replaceChild(bdv, nodeToRemove);
1044 								}
1045 								if (name.equals("dayoff2")) {
1046 									Node nodeToRemove = node.getFirstChild();
1047 									Node bdv = doc.createTextNode(""
1048 											+ modifiedEmployee.isDayoff2());
1049 									node.replaceChild(bdv, nodeToRemove);
1050 								}
1051 								if (name.equals("dayoff3")) {
1052 									Node nodeToRemove = node.getFirstChild();
1053 									Node bdv = doc.createTextNode(""
1054 											+ modifiedEmployee.isDayoff3());
1055 									node.replaceChild(bdv, nodeToRemove);
1056 								}
1057 								if (name.equals("dayoff4")) {
1058 									Node nodeToRemove = node.getFirstChild();
1059 									Node bdv = doc.createTextNode(""
1060 											+ modifiedEmployee.isDayoff4());
1061 									node.replaceChild(bdv, nodeToRemove);
1062 								}
1063 								if (name.equals("dayoff5")) {
1064 									Node nodeToRemove = node.getFirstChild();
1065 									Node bdv = doc.createTextNode(""
1066 											+ modifiedEmployee.isDayoff5());
1067 									node.replaceChild(bdv, nodeToRemove);
1068 								}
1069 								if (name.equals("dayoff6")) {
1070 									Node nodeToRemove = node.getFirstChild();
1071 									Node bdv = doc.createTextNode(""
1072 											+ modifiedEmployee.isDayoff6());
1073 									node.replaceChild(bdv, nodeToRemove);
1074 								}
1075 								if (name.equals("dayoff7")) {
1076 									Node nodeToRemove = node.getFirstChild();
1077 									Node bdv = doc.createTextNode(""
1078 											+ modifiedEmployee.isDayoff7());
1079 									node.replaceChild(bdv, nodeToRemove);
1080 								}
1081 
1082 							}
1083 						}
1084 					}
1085 				}
1086 			} else {
1087 				// creation du noeud employee
1088 				Element nodePrincipal = doc.createElement("employee");
1089 
1090 				// creation du noeud nom
1091 				Element noden = doc.createElement("nom");
1092 				noden.appendChild(doc.createTextNode(employee.getNom()));
1093 				// creation du noeud prenom
1094 				Element nodepn = doc.createElement("prenom");
1095 				nodepn.appendChild(doc.createTextNode(employee.getPrenom()));
1096 				// creation du noeud prenom
1097 				Element nodep = doc.createElement("pays");
1098 				nodep.appendChild(doc.createTextNode(employee.getPays()));
1099 
1100 				Element nodet = doc.createElement("team");
1101 				nodet.appendChild(doc.createTextNode(employee.getTeam()));
1102 
1103 				Element nodeed = doc.createElement("entryDate");
1104 				nodeed.appendChild(doc.createTextNode(employee.getEntryDate()));
1105 
1106 				Element nodedo1 = doc.createElement("dayoff1");
1107 				nodedo1.appendChild(doc.createTextNode(""
1108 						+ employee.isDayoff1()));
1109 				Element nodedo2 = doc.createElement("dayoff2");
1110 				nodedo2.appendChild(doc.createTextNode(""
1111 						+ employee.isDayoff2()));
1112 				Element nodedo3 = doc.createElement("dayoff3");
1113 				nodedo3.appendChild(doc.createTextNode(""
1114 						+ employee.isDayoff3()));
1115 				Element nodedo4 = doc.createElement("dayoff4");
1116 				nodedo4.appendChild(doc.createTextNode(""
1117 						+ employee.isDayoff4()));
1118 				Element nodedo5 = doc.createElement("dayoff5");
1119 				nodedo5.appendChild(doc.createTextNode(""
1120 						+ employee.isDayoff5()));
1121 				Element nodedo6 = doc.createElement("dayoff6");
1122 				nodedo6.appendChild(doc.createTextNode(""
1123 						+ employee.isDayoff6()));
1124 				Element nodedo7 = doc.createElement("dayoff7");
1125 				nodedo7.appendChild(doc.createTextNode(""
1126 						+ employee.isDayoff7()));
1127 
1128 				nodePrincipal.appendChild(noden);
1129 				nodePrincipal.appendChild(nodepn);
1130 				nodePrincipal.appendChild(nodep);
1131 				nodePrincipal.appendChild(nodet);
1132 				nodePrincipal.appendChild(nodeed);
1133 				nodePrincipal.appendChild(nodedo1);
1134 				nodePrincipal.appendChild(nodedo2);
1135 				nodePrincipal.appendChild(nodedo3);
1136 				nodePrincipal.appendChild(nodedo4);
1137 				nodePrincipal.appendChild(nodedo5);
1138 				nodePrincipal.appendChild(nodedo6);
1139 				nodePrincipal.appendChild(nodedo7);
1140 
1141 				root.appendChild(nodePrincipal);
1142 			}
1143 
1144 			writeToXML(doc, pathFileName, "");
1145 		}
1146 	}
1147 
1148 	/**
1149 	 * @return Vector
1150 	 * @throws Exception
1151 	 */
1152 	public Vector readReasons() throws Exception {
1153 		// System.out.println("debut AccessDataXMLImpl readReasons");
1154 		Vector reasons = new Vector();
1155 
1156 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1157 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1158 		Document document;
1159 
1160 		String fileName = "reasons.xml";
1161 		String pathFileName = dataDirPath + File.separator + fileName;
1162 		File reasonsFile = new File(pathFileName);
1163 
1164 		if (reasonsFile.exists()) {
1165 			document = constructeur.parse(reasonsFile);
1166 			// DEBUT JXPath
1167 			JXPathContext context = JXPathContext.newContext(document);
1168 			List nodeList = context.selectNodes("/reasons/reason");
1169 			Iterator iter = nodeList.iterator();
1170 			while (iter.hasNext()) {
1171 				ReasonData rd = new ReasonData();
1172 				Element reason = (Element) iter.next();
1173 				context = JXPathContext.newContext(reason);
1174 				rd.setCouleur((String) context.getValue("/couleur"));
1175 				rd.setNom((String) context.getValue("/nom"));
1176 				if (rd.getNom() != null && rd.getNom().trim().length() > 0) {
1177 					reasons.add(rd);
1178 				}
1179 			}
1180 			// FIN JXPath
1181 		}
1182 
1183 		// System.out.println("FIN AccessDataXMLImpl readReasons");
1184 		return reasons;
1185 	}
1186 
1187 	/**
1188 	 * @return Vector
1189 	 * @throws Exception
1190 	 */
1191 	public Vector readUsers() throws Exception {
1192 		Vector lstOfUsers = new Vector();
1193 
1194 		// on lit le fichier users.xml
1195 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1196 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1197 		Document document;
1198 
1199 		String fileName = "users.xml";
1200 		String pathFileName = dataDirPath + File.separator + fileName;
1201 		File usersFile = new File(pathFileName);
1202 
1203 		if (usersFile.exists()) {
1204 			document = constructeur.parse(usersFile);
1205 
1206 			// DEBUT test JXPath
1207 			JXPathContext context = JXPathContext.newContext(document);
1208 			List nodeList = context.selectNodes("/users/user");
1209 			Iterator iter = nodeList.iterator();
1210 			while (iter.hasNext()) {
1211 				UserData ud = new UserData();
1212 				Element user = (Element) iter.next();
1213 				context = JXPathContext.newContext(user);
1214 				ud.setLogin((String) context.getValue("/login"));
1215 				ud.setPassword((String) context.getValue("/password"));
1216 				ud.setEmail((String) context.getValue("/email"));
1217 				ud.setEmployee(Boolean.parseBoolean((String) context
1218 						.getValue("/employee")));
1219 				ud.setModif(Boolean.parseBoolean((String) context
1220 						.getValue("/modif")));
1221 				ud.setNom((String) context.getValue("/nom"));
1222 				ud.setPrenom((String) context.getValue("/prenom"));
1223 				ud.setTeam((String) context.getValue("/team"));
1224 
1225 				if (ud != null) {
1226 					lstOfUsers.add(ud);
1227 				}
1228 			}
1229 			// FIN test JXPath
1230 		}
1231 
1232 		return lstOfUsers;
1233 	}
1234 
1235 	/**
1236 	 * @param login
1237 	 * @return UserData
1238 	 * @throws Exception
1239 	 */
1240 	public UserData searchUser(String login) throws Exception {
1241 		// System.out.println("d�but AccessDataXMLImpl searchUser");
1242 
1243 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1244 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1245 		Document document;
1246 
1247 		String fileName = "users.xml";
1248 		String pathFileName = dataDirPath + File.separator + fileName;
1249 		File userFile = new File(pathFileName);
1250 
1251 		UserData ud = null;
1252 
1253 		if (userFile.exists()) {
1254 			document = constructeur.parse(userFile);
1255 			// DEBUT JXPath
1256 			JXPathContext context = JXPathContext.newContext(document);
1257 			String xpath = "/users/user[login=\"" + login + "\"]";
1258 			Element user = (Element) context.selectSingleNode(xpath);
1259 			context = JXPathContext.newContext(user);
1260 			ud = new UserData();
1261 			ud.setLogin((String) context.getValue("login"));
1262 			ud.setPassword((String) context.getValue("password"));
1263 			ud.setEmail((String) context.getValue("email"));
1264 			ud.setEmployee(Boolean.parseBoolean((String) context
1265 					.getValue("employee")));
1266 			ud.setModif(Boolean
1267 					.parseBoolean((String) context.getValue("modif")));
1268 			ud.setNom((String) context.getValue("nom"));
1269 			ud.setPrenom((String) context.getValue("prenom"));
1270 			ud.setTeam((String) context.getValue("team"));
1271 			// FIN JXPATH
1272 		} else {
1273 			ud = null;
1274 		// System.out.println("fin AccessDataXMLImpl readUsers");
1275 		}
1276 
1277 		return ud;
1278 	}
1279 
1280 	/**
1281 	 * write a new employee
1282 	 * 
1283 	 * @param employee -
1284 	 *            EmployeeData
1285 	 * @param modif -
1286 	 *            boolean
1287 	 * @param delete -
1288 	 *            boolean
1289 	 * @throws Exception
1290 	 */
1291 	public void writeEmployee(EmployeeData employee, boolean modif,
1292 			boolean delete) throws Exception {
1293 		writeEmployee(employee, null, modif, delete);
1294 	}
1295 
1296 	/**
1297 	 * @param reasons
1298 	 * @throws Exception
1299 	 */
1300 	public void writeReasons(Vector reasons) throws Exception {
1301 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1302 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1303 		Document doc;
1304 
1305 		String fileName = "reasons.xml";
1306 		String pathFileName = dataDirPath + File.separator + fileName;
1307 		File reasonDataFile = new File(pathFileName);
1308 
1309 		if (reasonDataFile.exists()) {
1310 			reasonDataFile.delete();
1311 		}
1312 
1313 		doc = constructeur.newDocument();
1314 		Node root = doc.createElement("reasons");
1315 		doc.appendChild(root);
1316 
1317 		for (Enumeration e = reasons.elements(); e.hasMoreElements();) {
1318 			ReasonData reason = (ReasonData) e.nextElement();
1319 			// creation du noeud
1320 			Element nodePrincipal = doc.createElement("reason");
1321 
1322 			// creation du noeud nom
1323 			Element nodenom = doc.createElement("nom");
1324 			nodenom.appendChild(doc.createTextNode(reason.getNom()));
1325 			// creation du noeud couleur
1326 			Element nodecouleur = doc.createElement("couleur");
1327 			nodecouleur.appendChild(doc.createTextNode(reason.getCouleur()));
1328 
1329 			nodePrincipal.appendChild(nodenom);
1330 			nodePrincipal.appendChild(nodecouleur);
1331 
1332 			root.appendChild(nodePrincipal);
1333 		}
1334 		writeToXML(doc, pathFileName, "");
1335 	}
1336 
1337 	/**
1338 	 * @param oldnom
1339 	 * @param nom
1340 	 * @param employees
1341 	 * @throws Exception
1342 	 */
1343 	public void replaceOldWithNewReason(String oldnom, String nom,
1344 			Vector employees) throws Exception {
1345 
1346 		for (int i = 0; i < employees.size(); i++) {
1347 			EmployeeData employee = (EmployeeData) employees.get(i);
1348 
1349 			String filename = employee.getPrenom().toUpperCase() + "_"
1350 					+ employee.getNom().toUpperCase() + ".xml";
1351 			String pathFileName = dataDirPath + File.separator + filename;
1352 			// System.out.println("filename="+pathFileName);
1353 
1354 			DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1355 			// System.out.println("2");
1356 			DocumentBuilder constructeur = usine.newDocumentBuilder();
1357 
1358 			try {
1359 				FileInputStream fis = new FileInputStream(pathFileName);
1360 				Document doc = constructeur.parse(fis);
1361 				// System.out.println("3");
1362 				JXPathContext context = JXPathContext.newContext(doc);
1363 				List reasons = context.selectNodes("/reasons/reason[nom=\""
1364 						+ oldnom + "\"]");
1365 				// NodeList reasons = doc.getElementsByTagName("reason");
1366 				// System.out.println("4");
1367 				boolean modified = false;
1368 				// for(int j=0; j<reasons.getLength(); j++)
1369 				Iterator iter = reasons.iterator();
1370 				while (iter.hasNext()) {
1371 					// System.out.println("5");
1372 					// Node reason = reasons.item(j);
1373 					Element reason = (Element) iter.next();
1374 					// if(reason.hasChildNodes())
1375 					// if(reason.getFirstChild().getNodeValue().equals(oldnom))
1376 					// {
1377 					// System.out.println("trouv�");
1378 					Node nodeToRemove = reason.getFirstChild();
1379 					// System.out.println("test="+nodeToRemove.getNodeName()+"_"
1380 					// + nodeToRemove.getNodeValue());
1381 					Node newReason = doc.createTextNode(nom);
1382 					reason.replaceChild(newReason, nodeToRemove);
1383 					modified = true;
1384 					// }
1385 				}
1386 				if (modified) {
1387 					writeToXML(doc, pathFileName, "");
1388 				}
1389 			} catch (IOException e) {
1390 				throw e;
1391 			} catch (Exception e) {
1392 				System.out.println("error: " + e.getMessage());
1393 				// si c un pb pour trouver un fichier : do nothing
1394 			}
1395 		}
1396 	}
1397 
1398 	/**
1399 	 * @param params
1400 	 * @throws Exception
1401 	 */
1402 	public void writeParams(Vector params) throws Exception {
1403 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1404 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1405 		Document doc;
1406 
1407 		String fileName = "params.xml";
1408 		String pathFileName = dataDirPath + File.separator + fileName;
1409 		File file = new File(pathFileName);
1410 
1411 		if (file.exists()) {
1412 			file.delete();
1413 		}
1414 
1415 		doc = constructeur.newDocument();
1416 		Node root = doc.createElement("params");
1417 		doc.appendChild(root);
1418 
1419 		for (Enumeration e = params.elements(); e.hasMoreElements();) {
1420 			ParamsData param = (ParamsData) e.nextElement();
1421 			// creation du noeud
1422 			Element nodePrincipal = doc.createElement("param");
1423 
1424 			// creation du noeud raison
1425 			Element noderaison = doc.createElement("raison");
1426 			noderaison.appendChild(doc.createTextNode(param.getReason()));
1427 			// creation du noeud nbjours
1428 			Element nodenbjours = doc.createElement("nbjours");
1429 			nodenbjours.appendChild(doc.createTextNode(param.getNbJours()));
1430 			// creation du noeud datedeb
1431 			Element nodedatedeb = doc.createElement("datedeb");
1432 			nodedatedeb.appendChild(doc.createTextNode(param.getDateDebut()));
1433 			// creation du noeud datefin
1434 			Element nodedatefin = doc.createElement("datefin");
1435 			nodedatefin.appendChild(doc.createTextNode(param.getDateFin()));
1436 
1437 			Element nodetype = doc.createElement("type");
1438 			nodetype.appendChild(doc.createTextNode(param.getType()));
1439 
1440 			nodePrincipal.appendChild(noderaison);
1441 			nodePrincipal.appendChild(nodenbjours);
1442 			nodePrincipal.appendChild(nodedatedeb);
1443 			nodePrincipal.appendChild(nodedatefin);
1444 			nodePrincipal.appendChild(nodetype);
1445 
1446 			root.appendChild(nodePrincipal);
1447 		}
1448 		writeToXML(doc, pathFileName, "");
1449 	}
1450 
1451 	/**
1452 	 * @return Vector params
1453 	 * @throws Exception
1454 	 */
1455 	public Vector readParams() throws Exception {
1456 		// System.out.println("debut AccessDataXMLImpl readParams");
1457 
1458 		Vector params = new Vector();
1459 
1460 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1461 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1462 		Document document;
1463 
1464 		String fileName = "params.xml";
1465 		String pathFileName = dataDirPath + File.separator + fileName;
1466 		File paramsFile = new File(pathFileName);
1467 
1468 		// if(paramsFile.exists())
1469 		// {
1470 		document = constructeur.parse(paramsFile);
1471 
1472 		// DEBUT test JXPath
1473 		JXPathContext context = JXPathContext.newContext(document);
1474 		List nodeList = context.selectNodes("/params/param");
1475 
1476 		Iterator iter = nodeList.iterator();
1477 		while (iter.hasNext()) {
1478 			ParamsData rd = new ParamsData();
1479 			Element param = (Element) iter.next();
1480 			context = JXPathContext.newContext(param);
1481 			rd.setDateDebut((String) context.getValue("/datedeb"));
1482 			rd.setDateFin((String) context.getValue("/datefin"));
1483 			rd.setNbJours((String) context.getValue("/nbjours"));
1484 			rd.setReason((String) context.getValue("/raison"));
1485 
1486 			try {
1487 				Object oNode = context.getValue("/type");
1488 				rd.setType((String) oNode);
1489 			} catch (JXPathException e) {
1490 				rd.setType("progressif");
1491 			}
1492 
1493 			params.add(rd);
1494 		}
1495 		// FIN test JXPath
1496 		// System.out.println("FIN AccessDataXMLImpl readParams");
1497 
1498 		return params;
1499 	}
1500 
1501 	/**
1502 	 * @return String
1503 	 * @throws Exception
1504 	 */
1505 	public String readParamPays() throws Exception {
1506 		String country = "";
1507 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1508 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1509 		Document document;
1510 
1511 		String fileName = "paramPays.xml";
1512 		String pathFileName = dataDirPath + File.separator + fileName;
1513 		File paramsFile = new File(pathFileName);
1514 
1515 		if (paramsFile.exists()) {
1516 			document = constructeur.parse(paramsFile);
1517 			// DEBUT test JXPath
1518 			JXPathContext context = JXPathContext.newContext(document);
1519 			country = (String) context.getValue("/paramPays/iso");
1520 			// FIN test JXPath
1521 			return country;
1522 		} else {
1523 			return null;
1524 		}
1525 	}
1526 
1527 	/**
1528 	 * write country param / ecrit param pays
1529 	 * 
1530 	 * @param iso
1531 	 * @throws Exception
1532 	 */
1533 	public void writeParamPays(String iso) throws Exception {
1534 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1535 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1536 		Document doc;
1537 
1538 		String fileName = "paramPays.xml";
1539 		String pathFileName = dataDirPath + File.separator + fileName;
1540 		File file = new File(pathFileName);
1541 
1542 		if (file.exists()) {
1543 			file.delete();
1544 		}
1545 
1546 		doc = constructeur.newDocument();
1547 		Node root = doc.createElement("paramPays");
1548 		doc.appendChild(root);
1549 
1550 		// creation du noeud iso
1551 		Element nodeiso = doc.createElement("iso");
1552 		nodeiso.appendChild(doc.createTextNode(iso.toUpperCase()));
1553 		root.appendChild(nodeiso);
1554 
1555 		writeToXML(doc, pathFileName, "");
1556 	}
1557 
1558 	/*
1559 	 * (non-Javadoc)
1560 	 * 
1561 	 * @see fr.hyphonem.conges.AccessData#writeTeams(java.util.Vector)
1562 	 */
1563 	public void writeTeams(Vector teams) throws Exception {
1564 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1565 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1566 		Document doc;
1567 
1568 		String fileName = "teams.xml";
1569 		String pathFileName = dataDirPath + File.separator + fileName;
1570 		File reasonDataFile = new File(pathFileName);
1571 
1572 		if (reasonDataFile.exists()) {
1573 			reasonDataFile.delete();
1574 		}
1575 
1576 		doc = constructeur.newDocument();
1577 		Node root = doc.createElement("teams");
1578 		doc.appendChild(root);
1579 
1580 		for (Enumeration e = teams.elements(); e.hasMoreElements();) {
1581 			String nomEquipe = (String) e.nextElement();
1582 			// creation du noeud
1583 			Element nodePrincipal = doc.createElement("team");
1584 
1585 			// creation du noeud nom
1586 			Element nodenom = doc.createElement("nom");
1587 			nodenom.appendChild(doc.createTextNode(nomEquipe));
1588 
1589 			nodePrincipal.appendChild(nodenom);
1590 
1591 			root.appendChild(nodePrincipal);
1592 		}
1593 		writeToXML(doc, pathFileName, "");
1594 	}
1595 
1596 	/*
1597 	 * (non-Javadoc)
1598 	 * 
1599 	 * @see fr.hyphonem.conges.AccessData#replaceOldWithNewTeam(java.lang.String,
1600 	 *      java.lang.String, java.util.Vector)
1601 	 */
1602 	public void replaceOldWithNewTeam(String oldnom0, String nom0,
1603 			Vector employees) throws Exception {
1604 		String filename = "employees.xml";
1605 		String pathFileName = dataDirPath + File.separator + filename;
1606 		// System.out.println("filename="+pathFileName);
1607 
1608 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1609 		// System.out.println("2");
1610 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1611 
1612 		try {
1613 			FileInputStream fis = new FileInputStream(pathFileName);
1614 			Document doc = constructeur.parse(fis);
1615 			// System.out.println("3");
1616 			JXPathContext context = JXPathContext.newContext(doc);
1617 			List teams = context.selectNodes("/teams/team[nom=\"" + oldnom0
1618 					+ "\"]");
1619 			// NodeList teams = doc.getElementsByTagName("team");
1620 			// System.out.println("4");
1621 			boolean modified = false;
1622 			Iterator iter = teams.iterator();
1623 			// for(int j=0; j<teams.getLength(); j++)
1624 			while (iter.hasNext()) {
1625 				// System.out.println("5");
1626 				// Node team = teams.item(j);
1627 				Element team = (Element) iter.next();
1628 				// if(team.hasChildNodes())
1629 				// if(team.getFirstChild().getNodeValue().equals(oldnom0))
1630 				// {
1631 				// System.out.println("trouv�");
1632 				Node nodeToRemove = team.getFirstChild();
1633 				// System.out.println("test="+nodeToRemove.getNodeName()+"_" +
1634 				// nodeToRemove.getNodeValue());
1635 				Node newTeam = doc.createTextNode(nom0);
1636 				team.replaceChild(newTeam, nodeToRemove);
1637 				modified = true;
1638 				// }
1639 			}
1640 			if (modified) {
1641 				writeToXML(doc, pathFileName, "");
1642 			}
1643 		} catch (IOException e) {
1644 			throw e;
1645 		} catch (Exception e) {
1646 			System.out.println("error: " + e.getMessage());
1647 			// si c un pb pour trouver un fichier : do nothing
1648 		}
1649 	}
1650 
1651 	/*
1652 	 * (non-Javadoc)
1653 	 * 
1654 	 * @see fr.hyphonem.conges.AccessData#readTeams()
1655 	 */
1656 	public Iterator readTeams() throws Exception {
1657 		// System.out.println("d�but AccessDataXMLImpl readTeams");
1658 
1659 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1660 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1661 		Document document;
1662 
1663 		String fileName = "teams.xml";
1664 		String pathFileName = dataDirPath + File.separator + fileName;
1665 		File file = new File(pathFileName);
1666 		document = constructeur.parse(file);
1667 
1668 		// DEBUT test JXPath
1669 		JXPathContext context = JXPathContext.newContext(document);
1670 		return context.iterate("/teams/team/nom");
1671 		// FIN test JXPath
1672 	}
1673 
1674 	/*
1675 	 * (non-Javadoc)
1676 	 * 
1677 	 * @see fr.hyphonem.conges.AccessData#writePendingEventData(fr.hyphonem.conges.data.CalendarData,
1678 	 *      fr.hyphonem.conges.data.EmployeeData, java.lang.String)
1679 	 */
1680 	public void writePendingEvent(String id, CalendarData ca,
1681 			EmployeeData employee, String cause, String codPays, String dirWeb)
1682 			throws Exception {
1683 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1684 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1685 		Document doc;
1686 		Node root;
1687 		String fileName = "pendingEvents.xml";
1688 		String pathFileName = dataDirPath + File.separator + fileName;
1689 		File pendingEventsDataFile = new File(pathFileName);
1690 
1691 		if (pendingEventsDataFile.exists()) {
1692 			doc = constructeur.parse(pendingEventsDataFile);
1693 			root = doc.getFirstChild();
1694 		} else {
1695 			doc = constructeur.newDocument();
1696 			root = doc.createElement("events");
1697 			doc.appendChild(root);
1698 		}
1699 
1700 		// creation du noeud
1701 		Element nodePrincipal = doc.createElement("event");
1702 
1703 		// creation du noeud nom
1704 		String nom = employee.getNom();
1705 		Element nodenom = doc.createElement("nom");
1706 		nodenom.appendChild(doc.createTextNode(nom));
1707 
1708 		String prenom = employee.getPrenom();
1709 		Element nodeprenom = doc.createElement("prenom");
1710 		nodeprenom.appendChild(doc.createTextNode(prenom));
1711 
1712 		String equipe = employee.getTeam();
1713 		Element nodeequipe = doc.createElement("equipe");
1714 		nodeequipe.appendChild(doc.createTextNode(equipe));
1715 
1716 		String datedeb = ca.getDatedeb();
1717 		String datefin = ca.getDatefin();
1718 
1719 		double nombreJours = 0.0;
1720 		CommonCal common = new CommonCal();
1721 		Vector lstCal = new Vector();
1722 		lstCal.add(ca);
1723 		FeryDays jf = new FeryDays();
1724 		Hashtable hjf = jf.getNationalDays(datedeb, datefin, codPays, dirWeb);
1725 		Vector lstOfworkingDaysInCalData = common.getDiscretCalData(lstCal,
1726 				employee, hjf);
1727 		Iterator iter = lstOfworkingDaysInCalData.iterator();
1728 		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
1729 		Date datedebwd = sdf.parse("01/01/2050");
1730 		Date datefinwd = sdf.parse("10/12/1973");
1731 		while (iter.hasNext()) {
1732 			CalendarData caldata = (CalendarData) iter.next();
1733 			Date datedeb_d = sdf.parse(caldata.getDatedeb());
1734 			Date datefin_d = sdf.parse(caldata.getDatefin());
1735 			if (datedeb_d.before(datedebwd)) {
1736 				datedebwd = datedeb_d;
1737 			}
1738 			if (datefin_d.after(datefinwd)) {
1739 				datefinwd = datefin_d;
1740 			}
1741 
1742 			double jourAjout = 0.0;
1743 			if (ca.isCbaprem() && ca.isCbmatin()) {
1744 				jourAjout = 1.0;
1745 			} else if (ca.isCbaprem() || ca.isCbmatin()) {
1746 				jourAjout = 0.5;
1747 			}
1748 
1749 			nombreJours += jourAjout;
1750 		}
1751 
1752 		Date datedebcal = sdf.parse(datedeb);
1753 		Date datefincal = sdf.parse(datefin);
1754 
1755 		if (datedebcal.before(datedebwd)) {
1756 			datedeb = sdf.format(datedebwd);
1757 		}
1758 		if (datefincal.after(datefinwd)) {
1759 			datefin = sdf.format(datefinwd);
1760 		}
1761 
1762 		Element nodedatedeb = doc.createElement("datedeb");
1763 		nodedatedeb.appendChild(doc.createTextNode(datedeb));
1764 
1765 		Element nodedatefin = doc.createElement("datefin");
1766 		nodedatefin.appendChild(doc.createTextNode(datefin));
1767 
1768 		Element nodenbjours = doc.createElement("nbjours");
1769 		nodenbjours.appendChild(doc.createTextNode("" + nombreJours));
1770 
1771 		String raison = ca.getRaison();
1772 		Element noderaison = doc.createElement("raison");
1773 		noderaison.appendChild(doc.createTextNode(raison));
1774 
1775 		Element nodecause = doc.createElement("cause");
1776 		nodecause.appendChild(doc.createTextNode(cause));
1777 
1778 		Element nodeidcal = doc.createElement("idcal");
1779 		nodeidcal.appendChild(doc.createTextNode(ca.getId()));
1780 
1781 		Element nodeid = doc.createElement("id");
1782 		nodeid.appendChild(doc.createTextNode(id));
1783 
1784 		Element nodematin = doc.createElement("matin");
1785 		nodematin.appendChild(doc.createTextNode("" + ca.isCbmatin()));
1786 
1787 		Element nodeaprem = doc.createElement("aprem");
1788 		nodeaprem.appendChild(doc.createTextNode("" + ca.isCbaprem()));
1789 
1790 		nodePrincipal.appendChild(nodeid);
1791 		nodePrincipal.appendChild(nodenom);
1792 		nodePrincipal.appendChild(nodeprenom);
1793 		nodePrincipal.appendChild(nodeequipe);
1794 		nodePrincipal.appendChild(nodedatedeb);
1795 		nodePrincipal.appendChild(nodedatefin);
1796 		nodePrincipal.appendChild(nodenbjours);
1797 		nodePrincipal.appendChild(noderaison);
1798 		nodePrincipal.appendChild(nodecause);
1799 		nodePrincipal.appendChild(nodeidcal);
1800 		nodePrincipal.appendChild(nodematin);
1801 		nodePrincipal.appendChild(nodeaprem);
1802 
1803 		root.appendChild(nodePrincipal);
1804 
1805 		writeToXML(doc, pathFileName, "");
1806 	}
1807 
1808 	/*
1809 	 * (non-Javadoc)
1810 	 * 
1811 	 * @see fr.hyphonem.conges.AccessData#readPendingEvents()
1812 	 */
1813 	public Vector readPendingEvents(UserData user, String team)
1814 			throws Exception {
1815 
1816 		Vector pendingEvents = new Vector();
1817 
1818 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1819 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1820 		Document document;
1821 
1822 		String fileName = "pendingEvents.xml";
1823 		String pathFileName = dataDirPath + File.separator + fileName;
1824 		File file = new File(pathFileName);
1825 		if (file.exists()) {
1826 			document = constructeur.parse(file);
1827 
1828 			// DEBUT test JXPath
1829 			JXPathContext context = JXPathContext.newContext(document);
1830 			// dans le cas de toutes les �quipes (=none) on renvoie tous les
1831 			// pendingEvents
1832 			List listOfPendingEvents;
1833 			if (team.equals("none")) {
1834 				listOfPendingEvents = context.selectNodes("/events/event");
1835 			} else {
1836 				listOfPendingEvents = context
1837 						.selectNodes("/events/event[equipe=\"" + team + "\"]");
1838 			}
1839 			Iterator iterPendingEvents = listOfPendingEvents.iterator();
1840 			while (iterPendingEvents.hasNext()) {
1841 				Element event = (Element) iterPendingEvents.next();
1842 				PendingEventData ped = new PendingEventData();
1843 				context = JXPathContext.newContext(event);
1844 				ped.setId((String) context.getValue("/id"));
1845 				ped.setIdcal((String) context.getValue("/idcal"));
1846 				ped.setDatedeb((String) context.getValue("/datedeb"));
1847 				ped.setDatefin((String) context.getValue("/datefin"));
1848 				ped.setRaison((String) context.getValue("/raison"));
1849 				ped.setNom((String) context.getValue("/nom"));
1850 				ped.setPrenom((String) context.getValue("/prenom"));
1851 				ped.setNbjours((String) context.getValue("/nbjours"));
1852 				ped.setType((String) context.getValue("/cause"));
1853 				ped.setCbmatin(Boolean.parseBoolean((String) context
1854 						.getValue("/matin")));
1855 				ped.setCbaprem(Boolean.parseBoolean((String) context
1856 						.getValue("/aprem")));
1857 
1858 				if (ped.getNom().equals(user.getNom())
1859 						&& ped.getPrenom().equals(user.getPrenom())) {
1860 					// do nothing il ne peut valider ses propres demandes d
1861 					// absences
1862 					Logger.getAnonymousLogger().info(
1863 							user.getNomPrenom()
1864 									+ "validate his/her own pending event : "
1865 									+ ped.toString());
1866 				} else {
1867 					pendingEvents.add(ped);
1868 				}
1869 			}
1870 		}
1871 
1872 		return pendingEvents;
1873 	}
1874 
1875 	/**
1876 	 * return le pendingEvent correspondant � l'id
1877 	 * 
1878 	 * @param id
1879 	 * @return PendingEventData
1880 	 * @throws Exception
1881 	 */
1882 	public PendingEventData readPendingEvent(String id) throws Exception {
1883 
1884 		PendingEventData pendingEvent = new PendingEventData();
1885 
1886 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1887 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1888 		Document document;
1889 
1890 		String fileName = "pendingEvents.xml";
1891 		String pathFileName = dataDirPath + File.separator + fileName;
1892 		File file = new File(pathFileName);
1893 		if (file.exists()) {
1894 			document = constructeur.parse(file);
1895 
1896 			// DEBUT test JXPath
1897 			JXPathContext context = JXPathContext.newContext(document);
1898 			// dans le cas de toutes les �quipes (=none) on renvoie tous les
1899 			// pendingEvents
1900 			Element event = (Element) context
1901 					.selectSingleNode("/events/event[id=\"" + id + "\"]");
1902 
1903 			context = JXPathContext.newContext(event);
1904 			pendingEvent.setId((String) context.getValue("/id"));
1905 			pendingEvent.setIdcal((String) context.getValue("/idcal"));
1906 			pendingEvent.setDatedeb((String) context.getValue("/datedeb"));
1907 			pendingEvent.setDatefin((String) context.getValue("/datefin"));
1908 			pendingEvent.setRaison((String) context.getValue("/raison"));
1909 			pendingEvent.setNom((String) context.getValue("/nom"));
1910 			pendingEvent.setPrenom((String) context.getValue("/prenom"));
1911 			pendingEvent.setNbjours((String) context.getValue("/nbjours"));
1912 			pendingEvent.setType((String) context.getValue("/cause"));
1913 			pendingEvent.setCbmatin(Boolean.parseBoolean((String) context
1914 					.getValue("/matin")));
1915 			pendingEvent.setCbaprem(Boolean.parseBoolean((String) context
1916 					.getValue("/aprem")));
1917 
1918 		}
1919 
1920 		return pendingEvent;
1921 	}
1922 
1923 	/*
1924 	 * (non-Javadoc)
1925 	 * 
1926 	 * @see fr.hyphonem.conges.AccessData#deletePendingEvent(java.lang.String)
1927 	 */
1928 	public EmployeeIdCalData deletePendingEvent(String id) throws Exception {
1929 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1930 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1931 		Document document;
1932 
1933 		String fileName = "pendingEvents.xml";
1934 		String pathFileName = dataDirPath + File.separator + fileName;
1935 		File file = new File(pathFileName);
1936 		document = constructeur.parse(file);
1937 
1938 		JXPathContext context = JXPathContext.newContext(document);
1939 		String xpath = "/events/event[id=\"" + id + "\"]";
1940 		Element event = (Element) context.selectSingleNode(xpath);
1941 		context = JXPathContext.newContext(event);
1942 
1943 		EmployeeIdCalData eid = new EmployeeIdCalData();
1944 		eid.setNom((String) context.getValue("nom"));
1945 		eid.setPrenom((String) context.getValue("prenom"));
1946 		eid.setIdcal((String) context.getValue("idcal"));
1947 		eid.setNbJours((String) context.getValue("nbjours"));
1948 
1949 		event.getParentNode().removeChild(event);
1950 
1951 		writeToXML(document, pathFileName, "");
1952 
1953 		return eid;
1954 	}
1955 
1956 	/*
1957 	 * (non-Javadoc)
1958 	 * 
1959 	 * @see fr.hyphonem.conges.AccessData#searchCalendarData(java.lang.String)
1960 	 */
1961 	public Vector searchCalendarData(EmployeeIdCalData eid) throws Exception {
1962 
1963 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1964 		DocumentBuilder constructeur = usine.newDocumentBuilder();
1965 		Document doc;
1966 		// System.out.println("1");
1967 		String fileName = eid.getPrenom().toUpperCase() + "_"
1968 				+ eid.getNom().toUpperCase() + ".xml";
1969 		String pathFileName = dataDirPath + File.separator + fileName;
1970 		// System.out.println("file="+pathFileName);
1971 		File employeeDataFile = new File(pathFileName);
1972 		doc = constructeur.parse(employeeDataFile);
1973 
1974 		String idcal = eid.getIdcal();
1975 
1976 		JXPathContext context = JXPathContext.newContext(doc);
1977 
1978 		String nbids = eid.getNbJours();
1979 		double d_nbids = new Double(nbids).doubleValue();
1980 		long l_nbids = Math.round(d_nbids);
1981 		int i_nbids = new Long(l_nbids).intValue();
1982 		// new Integer((int)d_nbids).intValue() + 1;
1983 
1984 		Vector cals = new Vector();
1985 		int idcal_init = new Integer(idcal).intValue();
1986 
1987 		for (int i = 0; i < i_nbids; i++) {
1988 			int id_int = i + idcal_init;
1989 			String id = "" + id_int;
1990 
1991 			String xpath = "/absences/absence[id=\"" + id + "\"]";
1992 			Element absence = (Element) context.selectSingleNode(xpath);
1993 
1994 			CalendarData cal = new CalendarData();
1995 			context = JXPathContext.newContext(absence);
1996 			cal.setId((String) context.getValue("/id"));
1997 			cal.setDatedeb((String) context.getValue("/beginDate"));
1998 			cal.setDatefin((String) context.getValue("/endDate"));
1999 			cal.setCbmatin(Boolean.parseBoolean((String) context
2000 					.getValue("/morning")));
2001 			cal.setCbaprem(Boolean.parseBoolean((String) context
2002 					.getValue("/afternoon")));
2003 			cal.setRaison((String) context.getValue("/reason"));
2004 
2005 			EmployeeData ed = new EmployeeData();
2006 			ed.setNom(eid.getNom());
2007 			ed.setPrenom(eid.getPrenom());
2008 			cal.setEmployee(ed);
2009 
2010 			cals.add(cal);
2011 		}
2012 
2013 		return cals;
2014 	}
2015 
2016 	/**
2017 	 * read ending events / lit les absences � valider
2018 	 * 
2019 	 * @param ed
2020 	 * @return Vector
2021 	 */
2022 	public Vector readPendingEvents(EmployeeData ed) {
2023 
2024 		Vector pendingEvents = new Vector();
2025 		try {
2026 			DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
2027 			DocumentBuilder constructeur = usine.newDocumentBuilder();
2028 			Document document;
2029 
2030 			String fileName = "pendingEvents.xml";
2031 			String pathFileName = dataDirPath + File.separator + fileName;
2032 			File file = new File(pathFileName);
2033 			if (file.exists()) {
2034 				document = constructeur.parse(file);
2035 
2036 				// DEBUT test JXPath
2037 				JXPathContext context = JXPathContext.newContext(document);
2038 				// dans le cas de toutes les �quipes (=none) on renvoie tous les
2039 				// pendingEvents
2040 				List listOfPendingEvents;
2041 				listOfPendingEvents = context
2042 						.selectNodes("/events/event[nom=\"" + ed.getNom()
2043 								+ "\" and prenom=\"" + ed.getPrenom() + "\"]");
2044 				Iterator iterPendingEvents = listOfPendingEvents.iterator();
2045 				while (iterPendingEvents.hasNext()) {
2046 					Element event = (Element) iterPendingEvents.next();
2047 					PendingEventData ped = new PendingEventData();
2048 					context = JXPathContext.newContext(event);
2049 					ped.setId((String) context.getValue("/id"));
2050 					ped.setIdcal((String) context.getValue("/idcal"));
2051 					ped.setDatedeb((String) context.getValue("/datedeb"));
2052 					ped.setDatefin((String) context.getValue("/datefin"));
2053 					ped.setRaison((String) context.getValue("/raison"));
2054 					ped.setNom((String) context.getValue("/nom"));
2055 					ped.setPrenom((String) context.getValue("/prenom"));
2056 					ped.setNbjours((String) context.getValue("/nbjours"));
2057 					ped.setType((String) context.getValue("/cause"));
2058 					ped.setCbmatin(Boolean.parseBoolean((String) context
2059 							.getValue("/matin")));
2060 					ped.setCbaprem(Boolean.parseBoolean((String) context
2061 							.getValue("/aprem")));
2062 
2063 					pendingEvents.add(ped);
2064 				}
2065 			}
2066 		} catch (Exception e) {
2067 			System.out.println(e.getMessage());
2068 		}
2069 		return pendingEvents;
2070 	}
2071 
2072 	public String readParamMail() throws Exception {
2073 		String server = "";
2074 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
2075 		DocumentBuilder constructeur = usine.newDocumentBuilder();
2076 		Document document;
2077 
2078 		String fileName = "paramMail.xml";
2079 		String pathFileName = dataDirPath + File.separator + fileName;
2080 		File paramsFile = new File(pathFileName);
2081 
2082 		if (paramsFile.exists()) {
2083 			document = constructeur.parse(paramsFile);
2084 			// DEBUT test JXPath
2085 			JXPathContext context = JXPathContext.newContext(document);
2086 			server = (String) context.getValue("/paramMail/server");
2087 			// FIN test JXPath
2088 			return server;
2089 		} else {
2090 			return server;
2091 		}
2092 	}
2093 
2094 	/*
2095 	 * (non-Javadoc)
2096 	 * 
2097 	 * @see fr.hyphonem.conges.AccessData#writeParamPays(java.lang.String)
2098 	 */
2099 	public void writeParamMail(String server) throws Exception {
2100 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
2101 		DocumentBuilder constructeur = usine.newDocumentBuilder();
2102 		Document doc;
2103 
2104 		String fileName = "paramMail.xml";
2105 		String pathFileName = dataDirPath + File.separator + fileName;
2106 		File file = new File(pathFileName);
2107 
2108 		if (file.exists()) {
2109 			file.delete();
2110 		}
2111 
2112 		doc = constructeur.newDocument();
2113 		Node root = doc.createElement("paramMail");
2114 		doc.appendChild(root);
2115 
2116 		// creation du noeud iso
2117 		Element nodeserver = doc.createElement("server");
2118 		nodeserver.appendChild(doc.createTextNode(server.toUpperCase()));
2119 		root.appendChild(nodeserver);
2120 
2121 		writeToXML(doc, pathFileName, "");
2122 	}
2123 
2124 	public Vector searchSupervisor(EmployeeData employee, AccessData ad)
2125 			throws Exception {
2126 		String team = employee.getTeam();
2127 
2128 		Vector supervisors = ad.searchSupervisor(team);
2129 		// si l'employee est aussi un chef d'equipe alors son superviseur est
2130 		// celui dont l'equipe est none
2131 		UserData user = searchUser(employee);
2132 		if (user.isModif()) {
2133 			Iterator iter = supervisors.iterator();
2134 			supervisors.clear();
2135 			while (iter.hasNext()) {
2136 				UserData supervisor = (UserData) iter.next();
2137 				if (supervisor.getTeam().equals("none")) {
2138 					supervisors.add(supervisor);
2139 				}
2140 			}
2141 		}
2142 		return supervisors;
2143 	}
2144 
2145 	/**
2146 	 * @param employee
2147 	 * @return UserData
2148 	 * @throws Exception
2149 	 */
2150 	public UserData searchUser(EmployeeData employee) throws Exception {
2151 		UserData user = new UserData();
2152 		Vector users = readUsers();
2153 		Iterator iter = users.iterator();
2154 		while (iter.hasNext()) {
2155 			user = (UserData) iter.next();
2156 			if (user.getNom().equals(employee.getNom())
2157 					&& user.getPrenom().equals(employee.getPrenom())) {
2158 				break;
2159 			}
2160 		}
2161 		return user;
2162 	}
2163 
2164 	public Vector searchSupervisor(String team) throws Exception {
2165 		Vector supervisors = new Vector();
2166 		Vector users = readUsers();
2167 		Iterator iter = users.iterator();
2168 		while (iter.hasNext()) {
2169 			UserData user = (UserData) iter.next();
2170 			if (user.getTeam().equals(team) && user.isModif()) {
2171 				supervisors.add(user);
2172 			}
2173 			if (user.getTeam().equals("none") && user.isModif()) {
2174 				supervisors.add(user);
2175 			}
2176 		}
2177 		return supervisors;
2178 	}
2179 
2180 	public Hashtable readNationalHolidays(String country, String year)
2181 			throws Exception {
2182 		Hashtable hjf = new Hashtable();
2183 
2184 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
2185 		DocumentBuilder constructeur = usine.newDocumentBuilder();
2186 		Document document;
2187 
2188 		String fileName = country + ".xml";
2189 		String pathFileName = dataDirPath + File.separator + fileName;
2190 		File paramsFile = new File(pathFileName);
2191 
2192 		if (paramsFile.exists()) {
2193 			try {
2194 				document = constructeur.parse(paramsFile);
2195 				// DEBUT test JXPath
2196 				JXPathContext context = JXPathContext.newContext(document);
2197 
2198 				Object yearNodeObject = context
2199 						.selectSingleNode("/jfs/year[@value=\"" + year + "\"]");
2200 				if (yearNodeObject != null) {
2201 					Element yearNode = (Element) yearNodeObject;
2202 					context = JXPathContext.newContext(yearNode);
2203 					List nodeList = context.selectNodes("/jf");
2204 					Iterator iter = nodeList.iterator();
2205 					Vector listOfNationalDays = new Vector();
2206 					while (iter.hasNext()) {
2207 						Element jfnode = (Element) iter.next();
2208 						context = JXPathContext.newContext(jfnode);
2209 						String label = (String) context.getValue("label");
2210 						String date = (String) context.getValue("date");
2211 						NationalDayData ndd = new NationalDayData();
2212 						ndd.setDate(date);
2213 						ndd.setLibelle(label);
2214 						ndd.setPays(country);
2215 						listOfNationalDays.add(ndd);
2216 					}
2217 					hjf.put(year, listOfNationalDays);
2218 				} else {
2219 					Logger.getAnonymousLogger().info("No data for this year");
2220 				}
2221 			} catch (SAXParseException e) {
2222 				// do nothing le fichier n'est pas parseable
2223 				Logger.getAnonymousLogger()
2224 						.info("unparseable file " + fileName);
2225 			}
2226 		}
2227 		return hjf;
2228 	}
2229 
2230 	public void writeNationalHolidays(String country, String year,
2231 			Hashtable nationalDays) throws Exception {
2232 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
2233 		DocumentBuilder constructeur = usine.newDocumentBuilder();
2234 		Document doc;
2235 		Node root;
2236 		Element yearNode;
2237 		String fileName = country + ".xml";
2238 		String pathFileName = dataDirPath + File.separator + fileName;
2239 		File dataFile = new File(pathFileName);
2240 		// System.out.println(country);
2241 		if (dataFile.exists()) {
2242 			try {
2243 				doc = constructeur.parse(dataFile);
2244 				root = doc.getFirstChild();
2245 				// DEBUT test JXPath
2246 				JXPathContext context = JXPathContext.newContext(doc);
2247 				yearNode = (Element) context
2248 						.selectSingleNode("/jfs/year[@value=\"" + year + "\"]");
2249 
2250 				if (yearNode == null) {
2251 					Logger.getAnonymousLogger().info(
2252 							"element year a creer / element year to create.");
2253 				} else {
2254 					yearNode = (Element) root.removeChild(yearNode);
2255 				}
2256 			} catch (SAXParseException e) {
2257 				dataFile.delete();
2258 				doc = constructeur.newDocument();
2259 				root = doc.createElement("jfs");
2260 			}
2261 		} else {
2262 			doc = constructeur.newDocument();
2263 			root = doc.createElement("jfs");
2264 			doc.appendChild(root);
2265 		}
2266 		yearNode = doc.createElement("year");
2267 		yearNode.setAttribute("value", year);
2268 		yearNode = writeYearNationalDays(year, doc, yearNode, nationalDays);
2269 		root.appendChild(yearNode);
2270 
2271 		writeToXML(doc, pathFileName, "");
2272 	}
2273 
2274 	private Element writeYearNationalDays(String year, Document doc,
2275 			Element yearNode, Hashtable hNationalDays) {
2276 		Vector listOfNationaldays = (Vector) hNationalDays.get(year);
2277 
2278 		Iterator iter = listOfNationaldays.iterator();
2279 		while (iter.hasNext()) {
2280 			NationalDayData nationalDay = (NationalDayData) iter.next();
2281 			String label = nationalDay.getLibelle();
2282 			String date = nationalDay.getDate();
2283 			Element jf = doc.createElement("jf");
2284 			Element nodeDate = doc.createElement("date");
2285 			Element nodeLabel = doc.createElement("label");
2286 			nodeDate.appendChild(doc.createTextNode(date));
2287 			nodeLabel.appendChild(doc.createTextNode(label));
2288 			jf.appendChild(nodeLabel);
2289 			jf.appendChild(nodeDate);
2290 			yearNode.appendChild(jf);
2291 		}
2292 		return yearNode;
2293 	}
2294 
2295 	public void writeTemporarilyOriginalEvent(String id,
2296 			CalendarData originalEvent, EmployeeData employee,
2297 			String typeEvent, String codePays, String dirWeb) throws Exception {
2298 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
2299 		DocumentBuilder constructeur = usine.newDocumentBuilder();
2300 		Document doc;
2301 		Node root;
2302 		String fileName = "temporarilyOriginalEvents.xml";
2303 		String pathFileName = dataDirPath + File.separator + fileName;
2304 		File pendingEventsDataFile = new File(pathFileName);
2305 
2306 		if (pendingEventsDataFile.exists()) {
2307 			doc = constructeur.parse(pendingEventsDataFile);
2308 			root = doc.getFirstChild();
2309 		} else {
2310 			doc = constructeur.newDocument();
2311 			root = doc.createElement("events");
2312 			doc.appendChild(root);
2313 		}
2314 
2315 		// creation du noeud
2316 		Element nodePrincipal = doc.createElement("event");
2317 
2318 		// creation du noeud nom
2319 		String nom = employee.getNom();
2320 		Element nodenom = doc.createElement("nom");
2321 		nodenom.appendChild(doc.createTextNode(nom));
2322 
2323 		String prenom = employee.getPrenom();
2324 		Element nodeprenom = doc.createElement("prenom");
2325 		nodeprenom.appendChild(doc.createTextNode(prenom));
2326 
2327 		String equipe = employee.getTeam();
2328 		Element nodeequipe = doc.createElement("equipe");
2329 		nodeequipe.appendChild(doc.createTextNode(equipe));
2330 
2331 		Element nodeentrydate = doc.createElement("entryDate");
2332 		String entryDate = employee.getEntryDate();
2333 		nodeentrydate.appendChild(doc.createTextNode(entryDate));
2334 
2335 		String pays = employee.getPays();
2336 		Element nodepays = doc.createElement("pays");
2337 		nodepays.appendChild(doc.createTextNode(pays));
2338 
2339 		String datedeb = originalEvent.getDatedeb();
2340 		String datefin = originalEvent.getDatefin();
2341 
2342 		double nombreJours = 0.0;
2343 		CommonCal common = new CommonCal();
2344 		Vector lstCal = new Vector();
2345 		lstCal.add(originalEvent);
2346 		FeryDays jf = new FeryDays();
2347 		Hashtable hjf = jf.getNationalDays(datedeb, datefin, codePays, dirWeb);
2348 		Vector lstOfworkingDaysInCalData = common.getDiscretCalData(lstCal,
2349 				employee, hjf);
2350 		Iterator iter = lstOfworkingDaysInCalData.iterator();
2351 		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
2352 		Date datedebwd = sdf.parse("01/01/2050");
2353 		Date datefinwd = sdf.parse("10/12/1973");
2354 		while (iter.hasNext()) {
2355 			CalendarData caldata = (CalendarData) iter.next();
2356 			Date datedeb_d = sdf.parse(caldata.getDatedeb());
2357 			Date datefin_d = sdf.parse(caldata.getDatefin());
2358 			if (datedeb_d.before(datedebwd)) {
2359 				datedebwd = datedeb_d;
2360 			}
2361 			if (datefin_d.after(datefinwd)) {
2362 				datefinwd = datefin_d;
2363 			}
2364 
2365 			double jourAjout = 0.0;
2366 			if (originalEvent.isCbaprem() && originalEvent.isCbmatin()) {
2367 				jourAjout = 1.0;
2368 			} else if (originalEvent.isCbaprem() || originalEvent.isCbmatin()) {
2369 				jourAjout = 0.5;
2370 			}
2371 
2372 			nombreJours += jourAjout;
2373 		}
2374 
2375 		Date datedebcal = sdf.parse(datedeb);
2376 		Date datefincal = sdf.parse(datefin);
2377 
2378 		if (datedebcal.before(datedebwd)) {
2379 			datedeb = sdf.format(datedebwd);
2380 		}
2381 		if (datefincal.after(datefinwd)) {
2382 			datefin = sdf.format(datefinwd);
2383 		}
2384 
2385 		Element nodedatedeb = doc.createElement("datedeb");
2386 		nodedatedeb.appendChild(doc.createTextNode(datedeb));
2387 
2388 		Element nodedatefin = doc.createElement("datefin");
2389 		nodedatefin.appendChild(doc.createTextNode(datefin));
2390 
2391 		Element nodenbjours = doc.createElement("nbjours");
2392 		nodenbjours.appendChild(doc.createTextNode("" + nombreJours));
2393 
2394 		String raison = originalEvent.getRaison();
2395 		Element noderaison = doc.createElement("raison");
2396 		noderaison.appendChild(doc.createTextNode(raison));
2397 
2398 		Element nodecause = doc.createElement("cause");
2399 		nodecause.appendChild(doc.createTextNode(typeEvent));
2400 
2401 		Element nodeid = doc.createElement("id");
2402 		nodeid.appendChild(doc.createTextNode(id));
2403 
2404 		Element nodematin = doc.createElement("matin");
2405 		nodematin.appendChild(doc
2406 				.createTextNode("" + originalEvent.isCbmatin()));
2407 
2408 		Element nodeaprem = doc.createElement("aprem");
2409 		nodeaprem.appendChild(doc
2410 				.createTextNode("" + originalEvent.isCbaprem()));
2411 
2412 		Element nodecouleur = doc.createElement("couleurRaison");
2413 		nodecouleur.appendChild(doc.createTextNode(""
2414 				+ originalEvent.getCouleurRaison()));
2415 
2416 		nodePrincipal.appendChild(nodeid);
2417 		nodePrincipal.appendChild(nodenom);
2418 		nodePrincipal.appendChild(nodeprenom);
2419 		nodePrincipal.appendChild(nodeequipe);
2420 		nodePrincipal.appendChild(nodedatedeb);
2421 		nodePrincipal.appendChild(nodedatefin);
2422 		nodePrincipal.appendChild(nodenbjours);
2423 		nodePrincipal.appendChild(noderaison);
2424 		// nodePrincipal.appendChild(nodecause);
2425 		nodePrincipal.appendChild(nodematin);
2426 		nodePrincipal.appendChild(nodeaprem);
2427 		nodePrincipal.appendChild(nodecouleur);
2428 		nodePrincipal.appendChild(nodeentrydate);
2429 		nodePrincipal.appendChild(nodepays);
2430 
2431 		root.appendChild(nodePrincipal);
2432 
2433 		writeToXML(doc, pathFileName, "");
2434 	}
2435 
2436 	public void deleteTemporarilyOriginalEvent(String id) throws Exception {
2437 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
2438 		DocumentBuilder constructeur = usine.newDocumentBuilder();
2439 		Document document;
2440 
2441 		String fileName = "temporarilyOriginalEvents.xml";
2442 		String pathFileName = dataDirPath + File.separator + fileName;
2443 		File file = new File(pathFileName);
2444 		document = constructeur.parse(file);
2445 
2446 		JXPathContext context = JXPathContext.newContext(document);
2447 		String xpath = "/events/event[id=\"" + id + "\"]";
2448 		Element event = (Element) context.selectSingleNode(xpath);
2449 
2450 		event.getParentNode().removeChild(event);
2451 
2452 		writeToXML(document, pathFileName, "");
2453 	}
2454 
2455 	public CalendarData searchTemporarilyOriginalEvents(String id)
2456 			throws Exception {
2457 		CalendarData cal = new CalendarData();
2458 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
2459 		DocumentBuilder constructeur = usine.newDocumentBuilder();
2460 		Document document;
2461 
2462 		String fileName = "temporarilyOriginalEvents.xml";
2463 		String pathFileName = dataDirPath + File.separator + fileName;
2464 		File file = new File(pathFileName);
2465 		if (file.exists()) {
2466 			document = constructeur.parse(file);
2467 
2468 			// DEBUT test JXPath
2469 			JXPathContext context = JXPathContext.newContext(document);
2470 			// dans le cas de toutes les �quipes (=none) on renvoie tous les
2471 			// pendingEvents
2472 			Element event = (Element) context
2473 					.selectSingleNode("/events/event[id=\"" + id + "\"]");
2474 
2475 			context = JXPathContext.newContext(event);
2476 			cal.setId((String) context.getValue("/id"));
2477 			cal.setDatedeb((String) context.getValue("/datedeb"));
2478 			cal.setDatefin((String) context.getValue("/datefin"));
2479 			cal.setRaison((String) context.getValue("/raison"));
2480 			EmployeeData employee = new EmployeeData();
2481 			employee.setNom((String) context.getValue("/nom"));
2482 			employee.setPrenom((String) context.getValue("/prenom"));
2483 			employee.setTeam((String) context.getValue("/equipe"));
2484 			cal.setCbmatin(Boolean.parseBoolean((String) context
2485 					.getValue("/matin")));
2486 			cal.setCbaprem(Boolean.parseBoolean((String) context
2487 					.getValue("/aprem")));
2488 			cal.setCouleurRaison((String) context.getValue("/couleurRaison"));
2489 			// employee.setEntryDate((String) context.getValue("/entryDate"));
2490 			// employee.setPays((String) context.getValue("/pays"));
2491 
2492 			cal.setEmployee(employee);
2493 		}
2494 		return cal;
2495 
2496 	}
2497 
2498 	public Vector readParamPeriods() throws Exception {
2499 		// System.out.println("debut AccessDataXMLImpl readParamPeriods");
2500 		Vector periods = new Vector();
2501 
2502 		// add period "none" even if periods are not set
2503 		PeriodData periodData = new PeriodData("none", "");
2504 		periods.add(periodData);
2505 
2506 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
2507 		DocumentBuilder constructeur = usine.newDocumentBuilder();
2508 		Document document;
2509 
2510 		String fileName = "periods.xml";
2511 		String pathFileName = dataDirPath + File.separator + fileName;
2512 		File periodsFile = new File(pathFileName);
2513 
2514 		if (periodsFile.exists()) {
2515 			document = constructeur.parse(periodsFile);
2516 			// DEBUT JXPath
2517 			JXPathContext context = JXPathContext.newContext(document);
2518 			List nodeList = context.selectNodes("/periods/period");
2519 			Iterator iter = nodeList.iterator();
2520 			while (iter.hasNext()) {
2521 				PeriodData rd = new PeriodData();
2522 				Element period = (Element) iter.next();
2523 				context = JXPathContext.newContext(period);
2524 				rd.setCode((String) context.getValue("/code"));
2525 				rd.setLabel((String) context.getValue("/label"));
2526 				if (rd.getLabel() != null && rd.getLabel().trim().length() > 0) {
2527 					periods.add(rd);
2528 				}
2529 			}
2530 			// FIN JXPath
2531 		}
2532 
2533 		// System.out.println("FIN AccessDataXMLImpl readParamPeriods");
2534 		return periods;
2535 	}
2536 
2537 	public void writePeriods(Vector periods) throws Exception {
2538 		DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
2539 		DocumentBuilder constructeur = usine.newDocumentBuilder();
2540 		Document doc;
2541 
2542 		String fileName = "periods.xml";
2543 		String pathFileName = dataDirPath + File.separator + fileName;
2544 		File periodsFile = new File(pathFileName);
2545 
2546 		if (periodsFile.exists()) {
2547 			periodsFile.delete();
2548 		}
2549 
2550 		doc = constructeur.newDocument();
2551 		Node root = doc.createElement("periods");
2552 		doc.appendChild(root);
2553 
2554 		for (Enumeration e = periods.elements(); e.hasMoreElements();) {
2555 			PeriodData period = (PeriodData) e.nextElement();
2556 			// creation du noeud
2557 			Element nodePrincipal = doc.createElement("period");
2558 
2559 			// creation du noeud code
2560 			Element nodecode = doc.createElement("code");
2561 			nodecode.appendChild(doc.createTextNode(period.getCode()));
2562 			Element nodelabel = doc.createElement("label");
2563 			nodelabel.appendChild(doc.createTextNode(period.getLabel()));
2564 
2565 			nodePrincipal.appendChild(nodecode);
2566 			nodePrincipal.appendChild(nodelabel);
2567 
2568 			root.appendChild(nodePrincipal);
2569 		}
2570 		writeToXML(doc, pathFileName, "");
2571 
2572 	}
2573 }