1
22
23 package com.liferay.portlet.wiki.action;
24
25 import com.liferay.portal.kernel.servlet.SessionErrors;
26 import com.liferay.portal.kernel.util.Constants;
27 import com.liferay.portal.kernel.util.ParamUtil;
28 import com.liferay.portal.kernel.util.Validator;
29 import com.liferay.portal.security.auth.PrincipalException;
30 import com.liferay.portal.service.ServiceContext;
31 import com.liferay.portal.service.ServiceContextFactory;
32 import com.liferay.portal.struts.PortletAction;
33 import com.liferay.portlet.wiki.DuplicatePageException;
34 import com.liferay.portlet.wiki.NoSuchNodeException;
35 import com.liferay.portlet.wiki.NoSuchPageException;
36 import com.liferay.portlet.wiki.PageContentException;
37 import com.liferay.portlet.wiki.PageTitleException;
38 import com.liferay.portlet.wiki.model.WikiPage;
39 import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
40
41 import javax.portlet.ActionRequest;
42 import javax.portlet.ActionResponse;
43 import javax.portlet.PortletConfig;
44 import javax.portlet.RenderRequest;
45 import javax.portlet.RenderResponse;
46
47 import org.apache.struts.action.ActionForm;
48 import org.apache.struts.action.ActionForward;
49 import org.apache.struts.action.ActionMapping;
50
51
56 public class MovePageAction extends PortletAction {
57
58 public void processAction(
59 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
60 ActionRequest actionRequest, ActionResponse actionResponse)
61 throws Exception {
62
63 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
64
65 try {
66 if (cmd.equals("changeParent")) {
67 changeParentPage(actionRequest);
68 }
69 else if (cmd.equals("rename")) {
70 renamePage(actionRequest);
71 }
72
73 if (Validator.isNotNull(cmd)) {
74 sendRedirect(actionRequest, actionResponse);
75 }
76 }
77 catch (Exception e) {
78 if (e instanceof NoSuchNodeException ||
79 e instanceof NoSuchPageException ||
80 e instanceof PrincipalException) {
81
82 SessionErrors.add(actionRequest, e.getClass().getName());
83
84 setForward(actionRequest, "portlet.wiki.error");
85 }
86 else if (e instanceof DuplicatePageException ||
87 e instanceof PageContentException ||
88 e instanceof PageTitleException) {
89
90 SessionErrors.add(actionRequest, e.getClass().getName());
91 }
92 else {
93 throw e;
94 }
95 }
96 }
97
98 public ActionForward render(
99 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
100 RenderRequest renderRequest, RenderResponse renderResponse)
101 throws Exception {
102
103 try {
104 ActionUtil.getNode(renderRequest);
105 ActionUtil.getPage(renderRequest);
106 }
107 catch (Exception e) {
108 if (e instanceof NoSuchNodeException ||
109 e instanceof NoSuchPageException ||
110 e instanceof PageTitleException ||
111 e instanceof PrincipalException) {
112
113 SessionErrors.add(renderRequest, e.getClass().getName());
114
115 return mapping.findForward("portlet.wiki.error");
116 }
117 else {
118 throw e;
119 }
120 }
121
122 return mapping.findForward(
123 getForward(renderRequest, "portlet.wiki.move_page"));
124 }
125
126 protected void changeParentPage(ActionRequest actionRequest)
127 throws Exception {
128
129 long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
130 String title = ParamUtil.getString(actionRequest, "title");
131 String newParentTitle = ParamUtil.getString(
132 actionRequest, "newParentTitle");
133
134 ServiceContext serviceContext = ServiceContextFactory.getInstance(
135 WikiPage.class.getName(), actionRequest);
136
137 WikiPageServiceUtil.changeParent(
138 nodeId, title, newParentTitle, serviceContext);
139 }
140
141 protected void renamePage(ActionRequest actionRequest) throws Exception {
142 long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
143 String title = ParamUtil.getString(actionRequest, "title");
144 String newTitle = ParamUtil.getString(actionRequest, "newTitle");
145
146 ServiceContext serviceContext = ServiceContextFactory.getInstance(
147 WikiPage.class.getName(), actionRequest);
148
149 WikiPageServiceUtil.movePage(nodeId, title, newTitle, serviceContext);
150 }
151
152 protected boolean isCheckMethodOnProcessAction() {
153 return _CHECK_METHOD_ON_PROCESS_ACTION;
154 }
155
156 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
157
158 }