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