1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.myplaces.action;
24  
25  import com.liferay.portal.kernel.util.ParamUtil;
26  import com.liferay.portal.kernel.util.StringPool;
27  import com.liferay.portal.model.Layout;
28  import com.liferay.portal.model.LayoutConstants;
29  import com.liferay.portal.service.LayoutLocalServiceUtil;
30  import com.liferay.portal.service.LayoutServiceUtil;
31  import com.liferay.portal.struts.PortletAction;
32  import com.liferay.portal.util.PortalUtil;
33  import com.liferay.portal.util.PortletKeys;
34  import com.liferay.portlet.PortletURLImpl;
35  
36  import java.util.List;
37  
38  import javax.portlet.ActionRequest;
39  import javax.portlet.ActionResponse;
40  import javax.portlet.PortletConfig;
41  import javax.portlet.PortletMode;
42  import javax.portlet.PortletRequest;
43  import javax.portlet.PortletURL;
44  import javax.portlet.WindowState;
45  
46  import javax.servlet.http.HttpServletRequest;
47  
48  import org.apache.struts.action.ActionForm;
49  import org.apache.struts.action.ActionMapping;
50  
51  /**
52   * <a href="EditPagesAction.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   */
56  public class EditPagesAction 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 redirect = ParamUtil.getString(actionRequest, "redirect");
64  
65          long groupId = ParamUtil.getLong(actionRequest, "groupId");
66          boolean privateLayout = ParamUtil.getBoolean(
67              actionRequest, "privateLayout");
68  
69          Layout layout = null;
70  
71          List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(
72              groupId, privateLayout, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, 0,
73              1);
74  
75          if (layouts.size() > 0) {
76              layout = layouts.get(0);
77          }
78          else {
79              long parentLayoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;
80              String name = "New Page";
81              String title = StringPool.BLANK;
82              String description = StringPool.BLANK;
83              String type = LayoutConstants.TYPE_PORTLET;
84              boolean hidden = false;
85              String friendlyURL = StringPool.BLANK;
86  
87              layout = LayoutServiceUtil.addLayout(
88                  groupId, privateLayout, parentLayoutId, name, title,
89                  description, type, hidden, friendlyURL);
90          }
91  
92          if (layout != null) {
93              String tabs1 = "public-pages";
94  
95              if (privateLayout) {
96                  tabs1 = "private-pages";
97              }
98  
99              HttpServletRequest request = PortalUtil.getHttpServletRequest(
100                 actionRequest);
101 
102             PortletURL portletURL = new PortletURLImpl(
103                 request, PortletKeys.LAYOUT_MANAGEMENT, layout.getPlid(),
104                 PortletRequest.RENDER_PHASE);
105 
106             portletURL.setWindowState(WindowState.MAXIMIZED);
107             portletURL.setPortletMode(PortletMode.VIEW);
108 
109             portletURL.setParameter(
110                 "struts_action", "/layout_management/edit_pages");
111             portletURL.setParameter("tabs1", tabs1);
112             portletURL.setParameter("redirect", redirect);
113             portletURL.setParameter("groupId", String.valueOf(groupId));
114 
115             actionResponse.sendRedirect(portletURL.toString());
116         }
117     }
118 
119 }