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.messageboards.action;
022:
023: import com.liferay.portal.kernel.util.ParamUtil;
024: import com.liferay.portal.security.auth.PrincipalException;
025: import com.liferay.portal.struts.PortletAction;
026: import com.liferay.portal.theme.ThemeDisplay;
027: import com.liferay.portal.util.WebKeys;
028: import com.liferay.portlet.ActionResponseImpl;
029: import com.liferay.portlet.messageboards.MessageBodyException;
030: import com.liferay.portlet.messageboards.MessageSubjectException;
031: import com.liferay.portlet.messageboards.NoSuchMessageException;
032: import com.liferay.portlet.messageboards.NoSuchThreadException;
033: import com.liferay.portlet.messageboards.RequiredMessageException;
034: import com.liferay.portlet.messageboards.model.MBThread;
035: import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
036: import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
037: import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
038: import com.liferay.portlet.messageboards.service.MBThreadServiceUtil;
039: import com.liferay.util.servlet.SessionErrors;
040:
041: import java.util.ArrayList;
042:
043: import javax.portlet.ActionRequest;
044: import javax.portlet.ActionResponse;
045: import javax.portlet.PortletConfig;
046: import javax.portlet.PortletPreferences;
047: import javax.portlet.PortletURL;
048: import javax.portlet.RenderRequest;
049: import javax.portlet.RenderResponse;
050:
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="MoveThreadAction.java.html"><b><i>View Source</i></b></a>
057: *
058: * @author Jorge Ferrer
059: *
060: */
061: public class MoveThreadAction extends PortletAction {
062:
063: public void processAction(ActionMapping mapping, ActionForm form,
064: PortletConfig config, ActionRequest req, ActionResponse res)
065: throws Exception {
066:
067: try {
068: moveThread(req, res);
069: } catch (Exception e) {
070: if (e instanceof PrincipalException
071: || e instanceof RequiredMessageException) {
072:
073: SessionErrors.add(req, e.getClass().getName());
074:
075: setForward(req, "portlet.message_boards.error");
076: } else if (e instanceof MessageBodyException
077: || e instanceof MessageSubjectException
078: || e instanceof NoSuchThreadException) {
079:
080: SessionErrors.add(req, e.getClass().getName());
081: } else {
082: throw e;
083: }
084: }
085: }
086:
087: public ActionForward render(ActionMapping mapping, ActionForm form,
088: PortletConfig config, RenderRequest req, RenderResponse res)
089: throws Exception {
090:
091: try {
092: ActionUtil.getThreadMessage(req);
093: } catch (Exception e) {
094: if (e instanceof NoSuchMessageException
095: || e instanceof PrincipalException) {
096:
097: SessionErrors.add(req, e.getClass().getName());
098:
099: return mapping
100: .findForward("portlet.message_boards.error");
101: } else {
102: throw e;
103: }
104: }
105:
106: return mapping.findForward(getForward(req,
107: "portlet.message_boards.move_thread"));
108: }
109:
110: protected void moveThread(ActionRequest req, ActionResponse res)
111: throws Exception {
112:
113: ThemeDisplay themeDisplay = (ThemeDisplay) req
114: .getAttribute(WebKeys.THEME_DISPLAY);
115:
116: PortletPreferences prefs = req.getPreferences();
117:
118: long categoryId = ParamUtil.getLong(req, "categoryId");
119: long threadId = ParamUtil.getLong(req, "threadId");
120:
121: MBThread thread = MBThreadLocalServiceUtil.getThread(threadId);
122:
123: MBThreadServiceUtil.moveThread(categoryId, threadId);
124:
125: boolean addExplanationPost = ParamUtil.getBoolean(req,
126: "addExplanationPost");
127:
128: if (addExplanationPost) {
129: String subject = ParamUtil.getString(req, "subject");
130: String body = ParamUtil.getString(req, "body");
131:
132: MBMessageServiceUtil.addMessage(categoryId, threadId,
133: thread.getRootMessageId(), subject, body,
134: new ArrayList(), false,
135: MBThreadImpl.PRIORITY_NOT_GIVEN, null, prefs, true,
136: true, themeDisplay);
137: }
138:
139: PortletURL portletURL = ((ActionResponseImpl) res)
140: .createRenderURL();
141:
142: portletURL.setParameter("struts_action",
143: "/message_boards/view_message");
144: portletURL.setParameter("messageId", String.valueOf(thread
145: .getRootMessageId()));
146:
147: res.sendRedirect(portletURL.toString());
148: }
149:
150: }
|