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
57 public class MovePageAction extends PortletAction {
58
59 public void processAction(
60 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
61 ActionRequest actionRequest, ActionResponse actionResponse)
62 throws Exception {
63
64 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
65
66 try {
67 if (cmd.equals("changeParent")) {
68 changeParentPage(actionRequest);
69 }
70 else if (cmd.equals("rename")) {
71 renamePage(actionRequest);
72 }
73
74 if (Validator.isNotNull(cmd)) {
75 sendRedirect(actionRequest, actionResponse);
76 }
77 }
78 catch (Exception e) {
79 if (e instanceof NoSuchNodeException ||
80 e instanceof NoSuchPageException ||
81 e instanceof PrincipalException) {
82
83 SessionErrors.add(actionRequest, e.getClass().getName());
84
85 setForward(actionRequest, "portlet.wiki.error");
86 }
87 else if (e instanceof DuplicatePageException ||
88 e instanceof PageContentException ||
89 e instanceof PageTitleException) {
90
91 SessionErrors.add(actionRequest, e.getClass().getName());
92 }
93 else {
94 throw e;
95 }
96 }
97 }
98
99 public ActionForward render(
100 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
101 RenderRequest renderRequest, RenderResponse renderResponse)
102 throws Exception {
103
104 try {
105 ActionUtil.getNode(renderRequest);
106 ActionUtil.getPage(renderRequest);
107 }
108 catch (Exception e) {
109 if (e instanceof NoSuchNodeException ||
110 e instanceof NoSuchPageException ||
111 e instanceof PageTitleException ||
112 e instanceof PrincipalException) {
113
114 SessionErrors.add(renderRequest, e.getClass().getName());
115
116 return mapping.findForward("portlet.wiki.error");
117 }
118 else {
119 throw e;
120 }
121 }
122
123 return mapping.findForward(
124 getForward(renderRequest, "portlet.wiki.move_page"));
125 }
126
127 protected void changeParentPage(ActionRequest actionRequest)
128 throws Exception {
129
130 long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
131 String title = ParamUtil.getString(actionRequest, "title");
132 String newParentTitle = ParamUtil.getString(
133 actionRequest, "newParentTitle");
134
135 ServiceContext serviceContext = ServiceContextFactory.getInstance(
136 WikiPage.class.getName(), actionRequest);
137
138 WikiPageServiceUtil.changeParent(
139 nodeId, title, newParentTitle, serviceContext);
140 }
141
142 protected void renamePage(ActionRequest actionRequest) throws Exception {
143 long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
144 String title = ParamUtil.getString(actionRequest, "title");
145 String newTitle = ParamUtil.getString(actionRequest, "newTitle");
146
147 ServiceContext serviceContext = ServiceContextFactory.getInstance(
148 WikiPage.class.getName(), actionRequest);
149
150 WikiPageServiceUtil.movePage(nodeId, title, newTitle, serviceContext);
151 }
152
153 protected boolean isCheckMethodOnProcessAction() {
154 return _CHECK_METHOD_ON_PROCESS_ACTION;
155 }
156
157 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
158
159 }