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.struts.PortletAction;
31 import com.liferay.portal.theme.ThemeDisplay;
32 import com.liferay.portal.util.WebKeys;
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.service.WikiPageServiceUtil;
39
40 import javax.portlet.ActionRequest;
41 import javax.portlet.ActionResponse;
42 import javax.portlet.PortletConfig;
43 import javax.portlet.PortletPreferences;
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 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
130 WebKeys.THEME_DISPLAY);
131
132 PortletPreferences prefs = actionRequest.getPreferences();
133
134 long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
135 String title = ParamUtil.getString(actionRequest, "title");
136 String newParentTitle = ParamUtil.getString(
137 actionRequest, "newParentTitle");
138
139 WikiPageServiceUtil.changeParent(
140 nodeId, title, newParentTitle, prefs, themeDisplay);
141 }
142
143 protected void renamePage(ActionRequest actionRequest) throws Exception {
144 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
145 WebKeys.THEME_DISPLAY);
146
147 PortletPreferences prefs = actionRequest.getPreferences();
148
149 long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
150 String title = ParamUtil.getString(actionRequest, "title");
151 String newTitle = ParamUtil.getString(actionRequest, "newTitle");
152
153 WikiPageServiceUtil.movePage(
154 nodeId, title, newTitle, prefs, themeDisplay);
155 }
156
157 protected boolean isCheckMethodOnProcessAction() {
158 return _CHECK_METHOD_ON_PROCESS_ACTION;
159 }
160
161 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
162
163 }