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.actions;
13  
14  import java.util.Calendar;
15  import java.util.Hashtable;
16  
17  import javax.servlet.http.HttpServletRequest;
18  import javax.servlet.http.HttpServletResponse;
19  import javax.servlet.http.HttpSession;
20  
21  import org.apache.struts.action.Action;
22  import org.apache.struts.action.ActionErrors;
23  import org.apache.struts.action.ActionForm;
24  import org.apache.struts.action.ActionForward;
25  import org.apache.struts.action.ActionMapping;
26  
27  import fr.hyphonem.conges.AccessData;
28  import fr.hyphonem.conges.AccessDataMng;
29  import fr.hyphonem.conges.data.UserData;
30  
31  /**
32   * @author Stephane Gauchet pour Hyphonem
33   */
34  public class NationalDaysAction extends Action {
35  
36  	public ActionForward execute(ActionMapping mapping, ActionForm form,
37  			HttpServletRequest request, HttpServletResponse response)
38  			throws Exception {
39  
40  		HttpSession session = request.getSession();
41  		if (session.getAttribute("user") == null) {
42  			return mapping.findForward("invalidsession");
43  		}
44  
45  		UserData userd = (UserData) session.getAttribute("user");
46  		// admin only
47  		if (userd.isModif() || userd.isEmployee()) {
48  			return mapping.findForward("invalidaction");
49  		}
50  
51  		ActionErrors errors = new ActionErrors();
52  		ActionForward forward = new ActionForward();
53  
54  		// pays en cours
55  		String pays = (String) session.getServletContext().getAttribute(
56  				"country");
57  		if (request.getParameter("pays") != null) {
58  			pays = request.getParameter("pays");
59  		} else if (session.getAttribute("pays") != null) {
60  			pays = (String) session.getAttribute("pays");
61  		}
62  		session.setAttribute("pays", pays);
63  
64  		// annee en cours
65  		String year = "" + Calendar.getInstance().get(Calendar.YEAR);
66  		if (request.getParameter("year") != null) {
67  			year = request.getParameter("year");
68  		} else if (session.getAttribute("year") != null) {
69  			year = (String) session.getAttribute("year");
70  		}
71  		session.setAttribute("year", year);
72  
73  		// lire tous les jours feries pour le pays et l annee en cours
74  		String dataDirPath = (String) session.getAttribute("dataDirPath");
75  		AccessData ad = new AccessDataMng().getInstance(dataDirPath);
76  
77  		Hashtable hJF = ad.readNationalHolidays(pays, year);
78  		session.setAttribute("listeDeJoursFeries", hJF);
79  
80  		if (!errors.isEmpty()) {
81  			saveErrors(request, errors);
82  			// Forward control to the appropriate 'failure' URI (change name as
83  			// desired)
84  			forward = mapping.getInputForward();
85  		} else {
86  			// Forward control to the appropriate 'success' URI (change name as
87  			// desired)
88  			forward = mapping.findForward("success");
89  		}
90  
91  		// Finish with
92  		return (forward);
93  	}
94  }