1
22
23 package com.liferay.portal.action;
24
25 import com.liferay.portal.kernel.util.GetterUtil;
26 import com.liferay.portal.kernel.util.StringPool;
27 import com.liferay.portal.kernel.util.StringUtil;
28 import com.liferay.portal.model.Layout;
29 import com.liferay.portal.model.LayoutTypePortlet;
30 import com.liferay.portal.model.impl.LayoutImpl;
31 import com.liferay.portal.model.impl.PortletImpl;
32 import com.liferay.portal.security.auth.PrincipalException;
33 import com.liferay.portal.service.LayoutLocalServiceUtil;
34 import com.liferay.portal.struts.ActionConstants;
35 import com.liferay.portal.theme.ThemeDisplay;
36 import com.liferay.portal.util.PortalUtil;
37 import com.liferay.portal.util.PropsUtil;
38 import com.liferay.portal.util.WebKeys;
39
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpServletResponse;
42 import javax.servlet.jsp.PageContext;
43
44 import org.apache.struts.action.Action;
45 import org.apache.struts.action.ActionForm;
46 import org.apache.struts.action.ActionForward;
47 import org.apache.struts.action.ActionMapping;
48
49
55 public class TCKAction extends Action {
56
57 public ActionForward execute(
58 ActionMapping mapping, ActionForm form, HttpServletRequest req,
59 HttpServletResponse res)
60 throws Exception {
61
62 try {
63 if (!GetterUtil.getBoolean(PropsUtil.get(PropsUtil.TCK_URL))) {
64 throw new PrincipalException();
65 }
66
67 ThemeDisplay themeDisplay =
68 (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
69
70 String[] portletIds = req.getParameterValues("portletId");
71
72 if (portletIds == null) {
73 portletIds = req.getParameterValues("portletName");
74 }
75
76 for (int i = 0; i < portletIds.length; i++) {
77 String[] nameAndWar = StringUtil.split(portletIds[i], "/");
78
79 portletIds[i] = PortalUtil.getJsSafePortletId(
80 nameAndWar[1] + PortletImpl.WAR_SEPARATOR + nameAndWar[0]);
81 }
82
83
85 long userId = 2;
86
87
89 long groupId = 14;
90
91 Layout layout = LayoutLocalServiceUtil.addLayout(
92 userId, groupId, false, LayoutImpl.DEFAULT_PARENT_LAYOUT_ID,
93 "TCKAction", StringPool.BLANK, StringPool.BLANK,
94 LayoutImpl.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 req.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 req.setAttribute(PageContext.EXCEPTION, e);
116
117 return mapping.findForward(ActionConstants.COMMON_ERROR);
118 }
119 }
120
121 }