1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.wiki.action;
24  
25  import com.liferay.portal.kernel.util.ParamUtil;
26  import com.liferay.portal.security.auth.PrincipalException;
27  import com.liferay.portal.struts.PortletAction;
28  import com.liferay.portal.theme.ThemeDisplay;
29  import com.liferay.portal.util.WebKeys;
30  import com.liferay.portlet.wiki.DuplicatePageException;
31  import com.liferay.portlet.wiki.NoSuchNodeException;
32  import com.liferay.portlet.wiki.NoSuchPageException;
33  import com.liferay.portlet.wiki.PageContentException;
34  import com.liferay.portlet.wiki.PageTitleException;
35  import com.liferay.portlet.wiki.service.WikiPageServiceUtil;
36  import com.liferay.util.servlet.SessionErrors;
37  
38  import javax.portlet.ActionRequest;
39  import javax.portlet.ActionResponse;
40  import javax.portlet.PortletConfig;
41  import javax.portlet.PortletPreferences;
42  import javax.portlet.RenderRequest;
43  import javax.portlet.RenderResponse;
44  
45  import org.apache.struts.action.ActionForm;
46  import org.apache.struts.action.ActionForward;
47  import org.apache.struts.action.ActionMapping;
48  
49  /**
50   * <a href="MovePageAction.java.html"><b><i>View Source</i></b></a>
51   *
52   * @author Jorge Ferrer
53   *
54   */
55  public class MovePageAction extends PortletAction {
56  
57      public void processAction(
58              ActionMapping mapping, ActionForm form, PortletConfig config,
59              ActionRequest req, ActionResponse res)
60          throws Exception {
61  
62          try {
63              movePage(req);
64  
65              sendRedirect(req, res);
66          }
67          catch (Exception e) {
68              if (e instanceof NoSuchNodeException ||
69                  e instanceof NoSuchPageException ||
70                  e instanceof PrincipalException) {
71  
72                  SessionErrors.add(req, e.getClass().getName());
73  
74                  setForward(req, "portlet.wiki.error");
75              }
76              else if (e instanceof DuplicatePageException ||
77                       e instanceof PageContentException ||
78                       e instanceof PageTitleException) {
79  
80                  SessionErrors.add(req, e.getClass().getName());
81              }
82              else {
83                  throw e;
84              }
85          }
86      }
87  
88      public ActionForward render(
89              ActionMapping mapping, ActionForm form, PortletConfig config,
90              RenderRequest req, RenderResponse res)
91          throws Exception {
92  
93          try {
94              ActionUtil.getNode(req);
95              ActionUtil.getPage(req);
96          }
97          catch (Exception e) {
98              if (e instanceof NoSuchNodeException ||
99                  e instanceof NoSuchPageException ||
100                 e instanceof PageTitleException ||
101                 e instanceof PrincipalException) {
102 
103                 SessionErrors.add(req, e.getClass().getName());
104 
105                 return mapping.findForward("portlet.wiki.error");
106             }
107             else {
108                 throw e;
109             }
110         }
111 
112         return mapping.findForward(getForward(req, "portlet.wiki.move_page"));
113     }
114 
115     protected void movePage(ActionRequest req) throws Exception {
116         ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(
117             WebKeys.THEME_DISPLAY);
118 
119         PortletPreferences prefs = req.getPreferences();
120 
121         long nodeId = ParamUtil.getLong(req, "nodeId");
122         String title = ParamUtil.getString(req, "title");
123         String newTitle = ParamUtil.getString(req, "newTitle");
124 
125         WikiPageServiceUtil.movePage(
126             nodeId, title, newTitle, prefs, themeDisplay);
127     }
128 
129     protected boolean isCheckMethodOnProcessAction() {
130         return _CHECK_METHOD_ON_PROCESS_ACTION;
131     }
132 
133     private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
134 
135 }