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