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.communities.action;
022:
023: import com.liferay.portal.MembershipRequestCommentsException;
024: import com.liferay.portal.NoSuchGroupException;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.security.auth.PrincipalException;
027: import com.liferay.portal.service.MembershipRequestServiceUtil;
028: import com.liferay.portal.struts.PortletAction;
029: import com.liferay.util.servlet.SessionErrors;
030: import com.liferay.util.servlet.SessionMessages;
031:
032: import javax.portlet.ActionRequest;
033: import javax.portlet.ActionResponse;
034: import javax.portlet.PortletConfig;
035: import javax.portlet.RenderRequest;
036: import javax.portlet.RenderResponse;
037:
038: import org.apache.struts.action.ActionForm;
039: import org.apache.struts.action.ActionForward;
040: import org.apache.struts.action.ActionMapping;
041:
042: /**
043: * <a href="PostMembershipRequestAction.java.html"><b><i>View Source</i></b></a>
044: *
045: * @author Jorge Ferrer
046: *
047: */
048: public class PostMembershipRequestAction extends PortletAction {
049:
050: public void processAction(ActionMapping mapping, ActionForm form,
051: PortletConfig config, ActionRequest req, ActionResponse res)
052: throws Exception {
053:
054: try {
055: long groupId = ParamUtil.getLong(req, "groupId");
056: String comments = ParamUtil.getString(req, "comments");
057:
058: MembershipRequestServiceUtil.addMembershipRequest(groupId,
059: comments);
060:
061: SessionMessages.add(req, "membership_request_sent");
062:
063: sendRedirect(req, res);
064: } catch (Exception e) {
065: if (e instanceof NoSuchGroupException
066: || e instanceof PrincipalException) {
067:
068: SessionErrors.add(req, e.getClass().getName());
069:
070: setForward(req, "portlet.communities.error");
071: } else if (e instanceof MembershipRequestCommentsException) {
072:
073: SessionErrors.add(req, e.getClass().getName());
074:
075: setForward(req,
076: "portlet.communities.post_membership_request");
077: } else {
078: throw e;
079: }
080: }
081: }
082:
083: public ActionForward render(ActionMapping mapping, ActionForm form,
084: PortletConfig config, RenderRequest req, RenderResponse res)
085: throws Exception {
086:
087: try {
088: ActionUtil.getGroup(req);
089: } catch (Exception e) {
090: if (e instanceof NoSuchGroupException
091: || e instanceof PrincipalException) {
092:
093: SessionErrors.add(req, e.getClass().getName());
094:
095: return mapping.findForward("portlet.communities.error");
096: } else {
097: throw e;
098: }
099: }
100:
101: return mapping.findForward(getForward(req,
102: "portlet.communities.post_membership_request"));
103: }
104:
105: }
|