1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.actions.admin.language;
20
21 import org.apache.log4j.Logger;
22 import org.apache.struts.action.*;
23 import org.itracker.core.resources.ITrackerResources;
24 import org.itracker.model.util.UserUtilities;
25 import org.itracker.services.ConfigurationService;
26 import org.itracker.web.actions.base.ItrackerBaseAction;
27 import org.itracker.web.util.ServletContextUtils;
28
29 import javax.servlet.ServletException;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import java.io.IOException;
33 import java.util.List;
34 import java.util.Map;
35
36
37
38
39
40
41
42 public class CreateLanguageKeyFormAction extends ItrackerBaseAction {
43 private static final Logger log = Logger.getLogger(CreateLanguageKeyFormAction.class);
44
45
46 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
47 ActionMessages errors = new ActionMessages();
48
49 if (!hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) {
50 return mapping.findForward("unauthorized");
51 }
52
53 ConfigurationService configurationService = ServletContextUtils.getItrackerServices().getConfigurationService();
54 Map<String, List<String>> languages = configurationService.getAvailableLanguages();
55 String baseLocale = ITrackerResources.BASE_LOCALE;
56
57 request.setAttribute("languages", languages);
58 request.setAttribute("languageKeys", languages.keySet().toArray());
59 request.setAttribute("baseLocale", baseLocale);
60
61 try {
62 saveToken(request);
63 return mapping.getInputForward();
64 } catch (Exception e) {
65 log.error("Exception while creating create language key form.", e);
66 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
67 }
68
69 if (!errors.isEmpty()) {
70 saveErrors(request, errors);
71 }
72
73 return mapping.findForward("error");
74 }
75
76 }
77