1
22
23 package com.liferay.portal.action;
24
25 import com.liferay.portal.kernel.util.StringPool;
26 import com.liferay.portal.kernel.util.StringUtil;
27 import com.liferay.portal.model.Layout;
28 import com.liferay.portal.model.LayoutConstants;
29 import com.liferay.portal.model.LayoutTypePortlet;
30 import com.liferay.portal.model.PortletConstants;
31 import com.liferay.portal.security.auth.PrincipalException;
32 import com.liferay.portal.service.LayoutLocalServiceUtil;
33 import com.liferay.portal.struts.ActionConstants;
34 import com.liferay.portal.theme.ThemeDisplay;
35 import com.liferay.portal.util.PortalUtil;
36 import com.liferay.portal.util.PropsValues;
37 import com.liferay.portal.util.WebKeys;
38
39 import javax.servlet.http.HttpServletRequest;
40 import javax.servlet.http.HttpServletResponse;
41
42 import org.apache.struts.action.Action;
43 import org.apache.struts.action.ActionForm;
44 import org.apache.struts.action.ActionForward;
45 import org.apache.struts.action.ActionMapping;
46
47
53 public class TCKAction extends Action {
54
55 public ActionForward execute(
56 ActionMapping mapping, ActionForm form, HttpServletRequest request,
57 HttpServletResponse response)
58 throws Exception {
59
60 try {
61 if (!PropsValues.TCK_URL) {
62 throw new PrincipalException();
63 }
64
65 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
66 WebKeys.THEME_DISPLAY);
67
68 String[] portletIds = request.getParameterValues("portletId");
69
70 if (portletIds == null) {
71 portletIds = request.getParameterValues("portletName");
72 }
73
74 for (int i = 0; i < portletIds.length; i++) {
75 String[] nameAndWar = StringUtil.split(portletIds[i], "/");
76
77 portletIds[i] = PortalUtil.getJsSafePortletId(
78 nameAndWar[1] + PortletConstants.WAR_SEPARATOR +
79 nameAndWar[0]);
80 }
81
82
84 long userId = 2;
85
86
88 long groupId = 14;
89
90 Layout layout = LayoutLocalServiceUtil.addLayout(
91 userId, groupId, false,
92 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "TCKAction",
93 StringPool.BLANK, StringPool.BLANK,
94 LayoutConstants.TYPE_PORTLET, false, StringPool.BLANK);
95
96 LayoutTypePortlet layoutType =
97 (LayoutTypePortlet)layout.getLayoutType();
98
99 for (int i = 0; i < portletIds.length; i++) {
100 layoutType.addPortletId(userId, portletIds[i]);
101 }
102
103 LayoutLocalServiceUtil.updateLayout(
104 layout.getGroupId(), layout.isPrivateLayout(),
105 layout.getLayoutId(), layout.getTypeSettings());
106
107 request.setAttribute(
108 WebKeys.FORWARD_URL,
109 themeDisplay.getPathMain() + "/portal/layout?p_l_id=" +
110 layout.getPlid());
111
112 return mapping.findForward(ActionConstants.COMMON_FORWARD_JSP);
113 }
114 catch (Exception e) {
115 PortalUtil.sendError(e, request, response);
116
117 return null;
118 }
119 }
120
121 }