001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.language.action;
022:
023: import com.liferay.portal.kernel.language.LanguageUtil;
024: import com.liferay.portal.kernel.util.LocaleUtil;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.portal.model.Contact;
028: import com.liferay.portal.model.Layout;
029: import com.liferay.portal.model.User;
030: import com.liferay.portal.struts.PortletAction;
031: import com.liferay.portal.theme.ThemeDisplay;
032: import com.liferay.portal.util.PortalUtil;
033: import com.liferay.portal.util.WebKeys;
034: import com.liferay.portlet.admin.util.AdminUtil;
035: import com.liferay.util.ListUtil;
036:
037: import java.util.List;
038: import java.util.Locale;
039:
040: import javax.portlet.ActionRequest;
041: import javax.portlet.ActionResponse;
042: import javax.portlet.PortletConfig;
043: import javax.portlet.RenderRequest;
044: import javax.portlet.RenderResponse;
045:
046: import javax.servlet.http.HttpServletRequest;
047: import javax.servlet.http.HttpServletResponse;
048: import javax.servlet.http.HttpSession;
049:
050: import org.apache.struts.Globals;
051: import org.apache.struts.action.ActionForm;
052: import org.apache.struts.action.ActionForward;
053: import org.apache.struts.action.ActionMapping;
054:
055: /**
056: * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
057: *
058: * @author Brian Wing Shun Chan
059: *
060: */
061: public class ViewAction extends PortletAction {
062:
063: public void processAction(ActionMapping mapping, ActionForm form,
064: PortletConfig config, ActionRequest req, ActionResponse res)
065: throws Exception {
066:
067: HttpServletRequest httpReq = PortalUtil
068: .getHttpServletRequest(req);
069: HttpServletResponse httpRes = PortalUtil
070: .getHttpServletResponse(res);
071: HttpSession httpSes = httpReq.getSession();
072:
073: ThemeDisplay themeDisplay = (ThemeDisplay) req
074: .getAttribute(WebKeys.THEME_DISPLAY);
075:
076: Layout layout = themeDisplay.getLayout();
077:
078: String languageId = ParamUtil.getString(req, "languageId");
079:
080: Locale locale = LocaleUtil.fromLanguageId(languageId);
081:
082: List availableLocales = ListUtil.fromArray(LanguageUtil
083: .getAvailableLocales());
084:
085: if (availableLocales.contains(locale)) {
086: if (themeDisplay.isSignedIn()) {
087: User user = themeDisplay.getUser();
088:
089: Contact contact = user.getContact();
090:
091: AdminUtil.updateUser(req, user.getUserId(), user
092: .getScreenName(), user.getEmailAddress(),
093: languageId, user.getTimeZoneId(), user
094: .getGreeting(), user.getComments(),
095: contact.getSmsSn(), contact.getAimSn(), contact
096: .getIcqSn(), contact.getJabberSn(),
097: contact.getMsnSn(), contact.getSkypeSn(),
098: contact.getYmSn());
099: }
100:
101: httpSes.setAttribute(Globals.LOCALE_KEY, locale);
102:
103: LanguageUtil.updateCookie(httpRes, locale);
104: }
105:
106: // Send redirect
107:
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(ActionMapping mapping, ActionForm form,
118: PortletConfig config, RenderRequest req, RenderResponse res)
119: throws Exception {
120:
121: return mapping.findForward("portlet.language.view");
122: }
123:
124: protected boolean isCheckMethodOnProcessAction() {
125: return _CHECK_METHOD_ON_PROCESS_ACTION;
126: }
127:
128: private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
129:
130: }
|