1
2
3
4
5
6
7
8
9
10
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
53
54
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
70
71 public AccessDataXMLImpl() {
72 super();
73 }
74
75
76
77
78
79
80
81
82
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
95
96
97
98
99
100
101
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
115
116
117
118 public AccessDataXMLImpl(String dataPath) {
119 super();
120 dataDirPath = dataPath;
121 }
122
123
124
125
126 public CalendarData getCd() {
127 return cd;
128 }
129
130
131
132
133 public String getDataDirPath() {
134 return dataDirPath;
135 }
136
137
138
139
140 public EmployeeData getEd() {
141 return ed;
142 }
143
144
145
146
147 public String getFromDate() {
148 return fromDate;
149 }
150
151
152
153
154 public String getToDate() {
155 return toDate;
156 }
157
158
159
160
161 public void setCd(CalendarData data) {
162 cd = data;
163 }
164
165
166
167
168 public void setDataDirPath(String string) {
169 dataDirPath = string;
170 }
171
172
173
174
175 public void setEd(EmployeeData data) {
176 ed = data;
177 }
178
179
180
181
182 public void setFromDate(String string) {
183 fromDate = string;
184 }
185
186
187
188
189 public void setToDate(String string) {
190 toDate = string;
191 }
192
193
194
195
196
197
198
199
200
201
202 public Vector readCalendarData(EmployeeData employee) throws Exception {
203
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
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
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
237
238
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
287 return vCalendarData;
288 }
289
290
291
292
293
294
295
296
297
298
299
300 public void writeCalendarData(CalendarData cd, boolean modif)
301 throws Exception {
302 writeCalendarData(cd, modif, false);
303 }
304
305
306
307
308
309
310
311
312
313
314
315
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
324 String fileName = cd.getEmployee().getPrenom().toUpperCase() + "_"
325 + cd.getEmployee().getNom().toUpperCase() + ".xml";
326 String pathFileName = dataDirPath + File.separator + fileName;
327
328 File employeeDataFile = new File(pathFileName);
329
330 Node root;
331 if (employeeDataFile != null && employeeDataFile.exists()) {
332 doc = constructeur.parse(employeeDataFile);
333
334 root = doc.getFirstChild();
335 } else {
336 doc = constructeur.newDocument();
337 root = doc.createElement("absences");
338 doc.appendChild(root);
339 }
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
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
428 Element nodePrincipal = doc.createElement("absence");
429
430
431 Element nodeid = doc.createElement("id");
432 nodeid.appendChild(doc.createTextNode(cd.getId()));
433
434 Element nodebd = doc.createElement("beginDate");
435 nodebd.appendChild(doc.createTextNode(cd.getDatedeb()));
436
437 Element nodeed = doc.createElement("endDate");
438 nodeed.appendChild(doc.createTextNode(cd.getDatefin()));
439
440 Element nodem = doc.createElement("morning");
441 nodem.appendChild(doc.createTextNode("" + cd.isCbmatin()));
442
443 Element nodea = doc.createElement("afternoon");
444 nodea.appendChild(doc.createTextNode("" + cd.isCbaprem()));
445
446 Element noder = doc.createElement("reason");
447 noder.appendChild(doc.createTextNode(cd.getRaison()));
448
449
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
460
461 }
462
463 writeToXML(doc, pathFileName, "");
464
465 }
466
467
468
469
470
471
472
473
474
475
476
477
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
507
508
509
510
511
512
513
514 public UserData searchUser(String login, String password) throws Exception {
515
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
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
548 } else {
549 ud = null;
550 }
551
552
553
554 return ud;
555 }
556
557
558
559
560
561
562
563 public Vector readEmployees() throws Exception {
564
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
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
629 ed.setDayoff6(true);
630 }
631 try {
632 ed.setDayoff7(Boolean.parseBoolean((String) context
633 .getValue("/dayoff7")));
634 } catch (JXPathException e) {
635
636 ed.setDayoff7(true);
637 }
638
639 employees.add(ed);
640 }
641
642 }
643
644
645 return employees;
646
647 }
648
649
650
651
652
653
654
655 public void writeUser(UserData user) throws Exception {
656 writeUser(user, false, false);
657 }
658
659
660
661
662
663
664
665
666
667
668
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
676 String fileName = "users.xml";
677 String pathFileName = dataDirPath + File.separator + fileName;
678
679 File usersFile = new File(pathFileName);
680
681 Node root;
682 if (usersFile != null && usersFile.exists()) {
683 doc = constructeur.parse(usersFile);
684
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
694
695
696
697
698 Element userToModify = (Element) iter.next();
699
700
701
702
703
704
705 if (delete) {
706
707
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
717
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
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
766 Element nodePrincipal = doc.createElement("user");
767
768
769 Element nodeid = doc.createElement("login");
770 nodeid.appendChild(doc.createTextNode(user.getLogin()));
771
772 Element nodebd = doc.createElement("password");
773 nodebd.appendChild(doc.createTextNode(user.getPassword()));
774
775 Element nodeed = doc.createElement("nom");
776 nodeed.appendChild(doc.createTextNode(user.getNom()));
777
778 Element nodem = doc.createElement("prenom");
779 nodem.appendChild(doc.createTextNode(user.getPrenom()));
780
781 Element nodea = doc.createElement("email");
782 nodea.appendChild(doc.createTextNode(user.getEmail()));
783
784 Element noder = doc.createElement("modif");
785 noder.appendChild(doc.createTextNode("" + user.isModif()));
786
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
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
810
811
812
813
814
815 public void writeEmployee(EmployeeData employee) throws Exception {
816 writeEmployee(employee, null, false, false);
817 }
818
819
820
821
822
823
824
825
826
827
828
829
830
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
839 String fileName = "employees.xml";
840 String pathFileName = dataDirPath + File.separator + fileName;
841
842 File employeeDataFile = new File(pathFileName);
843
844 Node root;
845 if (employeeDataFile != null && employeeDataFile.exists()) {
846 doc = constructeur.parse(employeeDataFile);
847
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
863 employeeToModify.getParentNode().removeChild(
864 employeeToModify);
865 } else {
866 if (modifiedEmployee != null) {
867
868
869
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
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
887
888
889
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
1088 Element nodePrincipal = doc.createElement("employee");
1089
1090
1091 Element noden = doc.createElement("nom");
1092 noden.appendChild(doc.createTextNode(employee.getNom()));
1093
1094 Element nodepn = doc.createElement("prenom");
1095 nodepn.appendChild(doc.createTextNode(employee.getPrenom()));
1096
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
1150
1151
1152 public Vector readReasons() throws Exception {
1153
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
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
1181 }
1182
1183
1184 return reasons;
1185 }
1186
1187
1188
1189
1190
1191 public Vector readUsers() throws Exception {
1192 Vector lstOfUsers = new Vector();
1193
1194
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
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
1230 }
1231
1232 return lstOfUsers;
1233 }
1234
1235
1236
1237
1238
1239
1240 public UserData searchUser(String login) throws Exception {
1241
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
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
1272 } else {
1273 ud = null;
1274
1275 }
1276
1277 return ud;
1278 }
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291 public void writeEmployee(EmployeeData employee, boolean modif,
1292 boolean delete) throws Exception {
1293 writeEmployee(employee, null, modif, delete);
1294 }
1295
1296
1297
1298
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
1320 Element nodePrincipal = doc.createElement("reason");
1321
1322
1323 Element nodenom = doc.createElement("nom");
1324 nodenom.appendChild(doc.createTextNode(reason.getNom()));
1325
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
1339
1340
1341
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
1353
1354 DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1355
1356 DocumentBuilder constructeur = usine.newDocumentBuilder();
1357
1358 try {
1359 FileInputStream fis = new FileInputStream(pathFileName);
1360 Document doc = constructeur.parse(fis);
1361
1362 JXPathContext context = JXPathContext.newContext(doc);
1363 List reasons = context.selectNodes("/reasons/reason[nom=\""
1364 + oldnom + "\"]");
1365
1366
1367 boolean modified = false;
1368
1369 Iterator iter = reasons.iterator();
1370 while (iter.hasNext()) {
1371
1372
1373 Element reason = (Element) iter.next();
1374
1375
1376
1377
1378 Node nodeToRemove = reason.getFirstChild();
1379
1380
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
1394 }
1395 }
1396 }
1397
1398
1399
1400
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
1422 Element nodePrincipal = doc.createElement("param");
1423
1424
1425 Element noderaison = doc.createElement("raison");
1426 noderaison.appendChild(doc.createTextNode(param.getReason()));
1427
1428 Element nodenbjours = doc.createElement("nbjours");
1429 nodenbjours.appendChild(doc.createTextNode(param.getNbJours()));
1430
1431 Element nodedatedeb = doc.createElement("datedeb");
1432 nodedatedeb.appendChild(doc.createTextNode(param.getDateDebut()));
1433
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
1453
1454
1455 public Vector readParams() throws Exception {
1456
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
1469
1470 document = constructeur.parse(paramsFile);
1471
1472
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
1496
1497
1498 return params;
1499 }
1500
1501
1502
1503
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
1518 JXPathContext context = JXPathContext.newContext(document);
1519 country = (String) context.getValue("/paramPays/iso");
1520
1521 return country;
1522 } else {
1523 return null;
1524 }
1525 }
1526
1527
1528
1529
1530
1531
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
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
1560
1561
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
1583 Element nodePrincipal = doc.createElement("team");
1584
1585
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
1598
1599
1600
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
1607
1608 DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1609
1610 DocumentBuilder constructeur = usine.newDocumentBuilder();
1611
1612 try {
1613 FileInputStream fis = new FileInputStream(pathFileName);
1614 Document doc = constructeur.parse(fis);
1615
1616 JXPathContext context = JXPathContext.newContext(doc);
1617 List teams = context.selectNodes("/teams/team[nom=\"" + oldnom0
1618 + "\"]");
1619
1620
1621 boolean modified = false;
1622 Iterator iter = teams.iterator();
1623
1624 while (iter.hasNext()) {
1625
1626
1627 Element team = (Element) iter.next();
1628
1629
1630
1631
1632 Node nodeToRemove = team.getFirstChild();
1633
1634
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
1648 }
1649 }
1650
1651
1652
1653
1654
1655
1656 public Iterator readTeams() throws Exception {
1657
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
1669 JXPathContext context = JXPathContext.newContext(document);
1670 return context.iterate("/teams/team/nom");
1671
1672 }
1673
1674
1675
1676
1677
1678
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
1701 Element nodePrincipal = doc.createElement("event");
1702
1703
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
1810
1811
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
1829 JXPathContext context = JXPathContext.newContext(document);
1830
1831
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
1861
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
1877
1878
1879
1880
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
1897 JXPathContext context = JXPathContext.newContext(document);
1898
1899
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
1925
1926
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
1958
1959
1960
1961 public Vector searchCalendarData(EmployeeIdCalData eid) throws Exception {
1962
1963 DocumentBuilderFactory usine = DocumentBuilderFactory.newInstance();
1964 DocumentBuilder constructeur = usine.newDocumentBuilder();
1965 Document doc;
1966
1967 String fileName = eid.getPrenom().toUpperCase() + "_"
1968 + eid.getNom().toUpperCase() + ".xml";
1969 String pathFileName = dataDirPath + File.separator + fileName;
1970
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
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
2018
2019
2020
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
2037 JXPathContext context = JXPathContext.newContext(document);
2038
2039
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
2085 JXPathContext context = JXPathContext.newContext(document);
2086 server = (String) context.getValue("/paramMail/server");
2087
2088 return server;
2089 } else {
2090 return server;
2091 }
2092 }
2093
2094
2095
2096
2097
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
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
2130
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
2147
2148
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
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
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
2241 if (dataFile.exists()) {
2242 try {
2243 doc = constructeur.parse(dataFile);
2244 root = doc.getFirstChild();
2245
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
2316 Element nodePrincipal = doc.createElement("event");
2317
2318
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
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
2469 JXPathContext context = JXPathContext.newContext(document);
2470
2471
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
2490
2491
2492 cal.setEmployee(employee);
2493 }
2494 return cal;
2495
2496 }
2497
2498 public Vector readParamPeriods() throws Exception {
2499
2500 Vector periods = new Vector();
2501
2502
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
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
2531 }
2532
2533
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
2557 Element nodePrincipal = doc.createElement("period");
2558
2559
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 }