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.LayoutTypePortlet;
29 import com.liferay.portal.model.impl.LayoutImpl;
30 import com.liferay.portal.model.impl.PortletImpl;
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 import javax.servlet.jsp.PageContext;
42
43 import org.apache.struts.action.Action;
44 import org.apache.struts.action.ActionForm;
45 import org.apache.struts.action.ActionForward;
46 import org.apache.struts.action.ActionMapping;
47
48
54 public class TCKAction extends Action {
55
56 public ActionForward execute(
57 ActionMapping mapping, ActionForm form, HttpServletRequest req,
58 HttpServletResponse res)
59 throws Exception {
60
61 try {
62 if (!PropsValues.TCK_URL) {
63 throw new PrincipalException();
64 }
65
66 ThemeDisplay themeDisplay =
67 (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
68
69 String[] portletIds = req.getParameterValues("portletId");
70
71 if (portletIds == null) {
72 portletIds = req.getParameterValues("portletName");
73 }
74
75 for (int i = 0; i < portletIds.length; i++) {
76 String[] nameAndWar = StringUtil.split(portletIds[i], "/");
77
78 portletIds[i] = PortalUtil.getJsSafePortletId(
79 nameAndWar[1] + PortletImpl.WAR_SEPARATOR + 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, LayoutImpl.DEFAULT_PARENT_LAYOUT_ID,
92 "TCKAction", StringPool.BLANK, StringPool.BLANK,
93 LayoutImpl.TYPE_PORTLET, false, StringPool.BLANK);
94
95 LayoutTypePortlet layoutType =
96 (LayoutTypePortlet)layout.getLayoutType();
97
98 for (int i = 0; i < portletIds.length; i++) {
99 layoutType.addPortletId(userId, portletIds[i]);
100 }
101
102 LayoutLocalServiceUtil.updateLayout(
103 layout.getGroupId(), layout.isPrivateLayout(),
104 layout.getLayoutId(), layout.getTypeSettings());
105
106 req.setAttribute(
107 WebKeys.FORWARD_URL,
108 themeDisplay.getPathMain() + "/portal/layout?p_l_id=" +
109 layout.getPlid());
110
111 return mapping.findForward(ActionConstants.COMMON_FORWARD_JSP);
112 }
113 catch (Exception e) {
114 req.setAttribute(PageContext.EXCEPTION, e);
115
116 return mapping.findForward(ActionConstants.COMMON_ERROR);
117 }
118 }
119
120 }