1
14
15 package com.liferay.portlet.myplaces.action;
16
17 import com.liferay.portal.kernel.util.ParamUtil;
18 import com.liferay.portal.kernel.util.StringPool;
19 import com.liferay.portal.model.Layout;
20 import com.liferay.portal.model.LayoutConstants;
21 import com.liferay.portal.service.LayoutLocalServiceUtil;
22 import com.liferay.portal.service.LayoutServiceUtil;
23 import com.liferay.portal.struts.PortletAction;
24 import com.liferay.portal.util.PortalUtil;
25 import com.liferay.portal.util.PortletKeys;
26 import com.liferay.portlet.PortletURLImpl;
27
28 import java.util.List;
29
30 import javax.portlet.ActionRequest;
31 import javax.portlet.ActionResponse;
32 import javax.portlet.PortletConfig;
33 import javax.portlet.PortletMode;
34 import javax.portlet.PortletRequest;
35 import javax.portlet.PortletURL;
36 import javax.portlet.WindowState;
37
38 import javax.servlet.http.HttpServletRequest;
39
40 import org.apache.struts.action.ActionForm;
41 import org.apache.struts.action.ActionMapping;
42
43
48 public class EditPagesAction extends PortletAction {
49
50 public void processAction(
51 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
52 ActionRequest actionRequest, ActionResponse actionResponse)
53 throws Exception {
54
55 String redirect = ParamUtil.getString(actionRequest, "redirect");
56
57 long groupId = ParamUtil.getLong(actionRequest, "groupId");
58 boolean privateLayout = ParamUtil.getBoolean(
59 actionRequest, "privateLayout");
60
61 Layout layout = null;
62
63 List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(
64 groupId, privateLayout, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, 0,
65 1);
66
67 if (layouts.size() > 0) {
68 layout = layouts.get(0);
69 }
70 else {
71 long parentLayoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;
72 String name = "New Page";
73 String title = StringPool.BLANK;
74 String description = StringPool.BLANK;
75 String type = LayoutConstants.TYPE_PORTLET;
76 boolean hidden = false;
77 String friendlyURL = StringPool.BLANK;
78
79 layout = LayoutServiceUtil.addLayout(
80 groupId, privateLayout, parentLayoutId, name, title,
81 description, type, hidden, friendlyURL);
82 }
83
84 if (layout != null) {
85 String tabs1 = "public-pages";
86
87 if (privateLayout) {
88 tabs1 = "private-pages";
89 }
90
91 HttpServletRequest request = PortalUtil.getHttpServletRequest(
92 actionRequest);
93
94 PortletURL portletURL = new PortletURLImpl(
95 request, PortletKeys.LAYOUT_MANAGEMENT, layout.getPlid(),
96 PortletRequest.RENDER_PHASE);
97
98 portletURL.setWindowState(WindowState.MAXIMIZED);
99 portletURL.setPortletMode(PortletMode.VIEW);
100
101 portletURL.setParameter(
102 "struts_action", "/layout_management/edit_pages");
103 portletURL.setParameter("tabs1", tabs1);
104 portletURL.setParameter("redirect", redirect);
105 portletURL.setParameter("groupId", String.valueOf(groupId));
106
107 actionResponse.sendRedirect(portletURL.toString());
108 }
109 }
110
111 }