View Javadoc

1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   */
18  
19  package org.itracker.web.actions.admin.language;
20  
21  import java.io.IOException;
22  import java.util.List;
23  import java.util.Map;
24  
25  import javax.servlet.ServletException;
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  import org.apache.log4j.Logger;
30  import org.apache.struts.action.ActionForm;
31  import org.apache.struts.action.ActionForward;
32  import org.apache.struts.action.ActionMapping;
33  import org.apache.struts.action.ActionMessage;
34  import org.apache.struts.action.ActionMessages;
35  import org.itracker.core.resources.ITrackerResources;
36  import org.itracker.services.ConfigurationService;
37  import org.itracker.services.util.UserUtilities;
38  import org.itracker.web.actions.base.ItrackerBaseAction;
39  
40  
41  /**
42   * 
43   * Please comment this one... what is it used for?
44   * @author ready
45   *
46   */
47  public class CreateLanguageKeyFormAction extends ItrackerBaseAction {
48  	private static final Logger log = Logger.getLogger(CreateLanguageKeyFormAction.class);
49  	
50  
51      public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
52      	ActionMessages errors = new ActionMessages();
53  
54          if(! hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) {
55              return mapping.findForward("unauthorized");
56          }
57  
58  		ConfigurationService configurationService = this.getITrackerServices().getConfigurationService();
59  	    Map<String,List<String>> languages = configurationService.getAvailableLanguages();
60  	    String baseLocale = ITrackerResources.BASE_LOCALE;
61  	    
62  		request.setAttribute("languages",languages);
63  		request.setAttribute("languageKeys",languages.keySet().toArray());
64  		request.setAttribute("baseLocale",baseLocale);
65  		
66          try {
67              saveToken(request);
68              return mapping.getInputForward();
69          } catch(Exception e) {
70              log.error("Exception while creating create language key form.", e);
71              errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
72          }
73  
74          if(! errors.isEmpty()) {
75              saveErrors(request, errors);
76          }
77  
78          return mapping.findForward("error");
79      }
80  
81  }
82