1
22
23 package com.liferay.portlet.language.action;
24
25 import com.liferay.portal.kernel.language.LanguageUtil;
26 import com.liferay.portal.kernel.util.LocaleUtil;
27 import com.liferay.portal.kernel.util.ParamUtil;
28 import com.liferay.portal.kernel.util.Validator;
29 import com.liferay.portal.model.Contact;
30 import com.liferay.portal.model.Layout;
31 import com.liferay.portal.model.User;
32 import com.liferay.portal.struts.PortletAction;
33 import com.liferay.portal.theme.ThemeDisplay;
34 import com.liferay.portal.util.PortalUtil;
35 import com.liferay.portal.util.WebKeys;
36 import com.liferay.portlet.admin.util.AdminUtil;
37 import com.liferay.util.ListUtil;
38
39 import java.util.List;
40 import java.util.Locale;
41
42 import javax.portlet.ActionRequest;
43 import javax.portlet.ActionResponse;
44 import javax.portlet.PortletConfig;
45 import javax.portlet.RenderRequest;
46 import javax.portlet.RenderResponse;
47
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpServletResponse;
50 import javax.servlet.http.HttpSession;
51
52 import org.apache.struts.Globals;
53 import org.apache.struts.action.ActionForm;
54 import org.apache.struts.action.ActionForward;
55 import org.apache.struts.action.ActionMapping;
56
57
63 public class ViewAction extends PortletAction {
64
65 public void processAction(
66 ActionMapping mapping, ActionForm form, PortletConfig config,
67 ActionRequest req, ActionResponse res)
68 throws Exception {
69
70 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
71 HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(res);
72 HttpSession httpSes = httpReq.getSession();
73
74 ThemeDisplay themeDisplay =
75 (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
76
77 Layout layout = themeDisplay.getLayout();
78
79 String languageId = ParamUtil.getString(req, "languageId");
80
81 Locale locale = LocaleUtil.fromLanguageId(languageId);
82
83 List availableLocales = ListUtil.fromArray(
84 LanguageUtil.getAvailableLocales());
85
86 if (availableLocales.contains(locale)) {
87 if (themeDisplay.isSignedIn()) {
88 User user = themeDisplay.getUser();
89
90 Contact contact = user.getContact();
91
92 AdminUtil.updateUser(
93 req, user.getUserId(), user.getScreenName(),
94 user.getEmailAddress(), languageId, user.getTimeZoneId(),
95 user.getGreeting(), user.getComments(), contact.getSmsSn(),
96 contact.getAimSn(), contact.getIcqSn(),
97 contact.getJabberSn(), contact.getMsnSn(),
98 contact.getSkypeSn(), contact.getYmSn());
99 }
100
101 httpSes.setAttribute(Globals.LOCALE_KEY, locale);
102
103 LanguageUtil.updateCookie(httpRes, locale);
104 }
105
106
108 String redirect = ParamUtil.getString(req, "redirect");
109
110 if (Validator.isNull(redirect)) {
111 redirect = PortalUtil.getLayoutURL(layout, themeDisplay);
112 }
113
114 res.sendRedirect(redirect);
115 }
116
117 public ActionForward render(
118 ActionMapping mapping, ActionForm form, PortletConfig config,
119 RenderRequest req, RenderResponse res)
120 throws Exception {
121
122 return mapping.findForward("portlet.language.view");
123 }
124
125 }