1
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
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 }