001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.action;
022:
023: import com.liferay.portal.kernel.util.StringPool;
024: import com.liferay.portal.kernel.util.StringUtil;
025: import com.liferay.portal.model.Layout;
026: import com.liferay.portal.model.LayoutTypePortlet;
027: import com.liferay.portal.model.impl.LayoutImpl;
028: import com.liferay.portal.model.impl.PortletImpl;
029: import com.liferay.portal.security.auth.PrincipalException;
030: import com.liferay.portal.service.LayoutLocalServiceUtil;
031: import com.liferay.portal.struts.ActionConstants;
032: import com.liferay.portal.theme.ThemeDisplay;
033: import com.liferay.portal.util.PortalUtil;
034: import com.liferay.portal.util.PropsValues;
035: import com.liferay.portal.util.WebKeys;
036:
037: import javax.servlet.http.HttpServletRequest;
038: import javax.servlet.http.HttpServletResponse;
039: import javax.servlet.jsp.PageContext;
040:
041: import org.apache.struts.action.Action;
042: import org.apache.struts.action.ActionForm;
043: import org.apache.struts.action.ActionForward;
044: import org.apache.struts.action.ActionMapping;
045:
046: /**
047: * <a href="TCKAction.java.html"><b><i>View Source</i></b></a>
048: *
049: * @author Brian Wing Shun Chan
050: *
051: */
052: public class TCKAction extends Action {
053:
054: public ActionForward execute(ActionMapping mapping,
055: ActionForm form, HttpServletRequest req,
056: HttpServletResponse res) throws Exception {
057:
058: try {
059: if (!PropsValues.TCK_URL) {
060: throw new PrincipalException();
061: }
062:
063: ThemeDisplay themeDisplay = (ThemeDisplay) req
064: .getAttribute(WebKeys.THEME_DISPLAY);
065:
066: String[] portletIds = req.getParameterValues("portletId");
067:
068: if (portletIds == null) {
069: portletIds = req.getParameterValues("portletName");
070: }
071:
072: for (int i = 0; i < portletIds.length; i++) {
073: String[] nameAndWar = StringUtil.split(portletIds[i],
074: "/");
075:
076: portletIds[i] = PortalUtil
077: .getJsSafePortletId(nameAndWar[1]
078: + PortletImpl.WAR_SEPARATOR
079: + nameAndWar[0]);
080: }
081:
082: // Default admin
083:
084: long userId = 2;
085:
086: // Guest group
087:
088: long groupId = 14;
089:
090: Layout layout = LayoutLocalServiceUtil.addLayout(userId,
091: groupId, false,
092: LayoutImpl.DEFAULT_PARENT_LAYOUT_ID, "TCKAction",
093: StringPool.BLANK, StringPool.BLANK,
094: LayoutImpl.TYPE_PORTLET, false, StringPool.BLANK);
095:
096: LayoutTypePortlet layoutType = (LayoutTypePortlet) layout
097: .getLayoutType();
098:
099: for (int i = 0; i < portletIds.length; i++) {
100: layoutType.addPortletId(userId, portletIds[i]);
101: }
102:
103: LayoutLocalServiceUtil.updateLayout(layout.getGroupId(),
104: layout.isPrivateLayout(), layout.getLayoutId(),
105: layout.getTypeSettings());
106:
107: req.setAttribute(WebKeys.FORWARD_URL, themeDisplay
108: .getPathMain()
109: + "/portal/layout?p_l_id=" + layout.getPlid());
110:
111: return mapping
112: .findForward(ActionConstants.COMMON_FORWARD_JSP);
113: } catch (Exception e) {
114: req.setAttribute(PageContext.EXCEPTION, e);
115:
116: return mapping.findForward(ActionConstants.COMMON_ERROR);
117: }
118: }
119:
120: }
|