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
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 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
131 WebKeys.THEME_DISPLAY);
132
133 PortletPreferences prefs = actionRequest.getPreferences();
134
135 long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
136 String title = ParamUtil.getString(actionRequest, "title");
137 String newParentTitle = ParamUtil.getString(
138 actionRequest, "newParentTitle");
139
140 WikiPageServiceUtil.changeParent(
141 nodeId, title, newParentTitle, prefs, themeDisplay);
142 }
143
144 protected void renamePage(ActionRequest actionRequest) throws Exception {
145 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
146 WebKeys.THEME_DISPLAY);
147
148 PortletPreferences prefs = actionRequest.getPreferences();
149
150 long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
151 String title = ParamUtil.getString(actionRequest, "title");
152 String newTitle = ParamUtil.getString(actionRequest, "newTitle");
153
154 WikiPageServiceUtil.movePage(
155 nodeId, title, newTitle, prefs, themeDisplay);
156 }
157
158 protected boolean isCheckMethodOnProcessAction() {
159 return _CHECK_METHOD_ON_PROCESS_ACTION;
160 }
161
162 private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
163
164 }