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.portlet.myplaces.action;
022:
023: import com.liferay.portal.kernel.util.ParamUtil;
024: import com.liferay.portal.kernel.util.StringPool;
025: import com.liferay.portal.model.Layout;
026: import com.liferay.portal.model.impl.LayoutImpl;
027: import com.liferay.portal.service.LayoutLocalServiceUtil;
028: import com.liferay.portal.service.LayoutServiceUtil;
029: import com.liferay.portal.struts.PortletAction;
030: import com.liferay.portal.util.PortalUtil;
031: import com.liferay.portal.util.PortletKeys;
032: import com.liferay.portlet.PortletURLImpl;
033:
034: import java.util.List;
035:
036: import javax.portlet.ActionRequest;
037: import javax.portlet.ActionResponse;
038: import javax.portlet.PortletConfig;
039: import javax.portlet.PortletMode;
040: import javax.portlet.PortletURL;
041: import javax.portlet.WindowState;
042:
043: import javax.servlet.http.HttpServletRequest;
044:
045: import org.apache.struts.action.ActionForm;
046: import org.apache.struts.action.ActionMapping;
047:
048: /**
049: * <a href="EditPagesAction.java.html"><b><i>View Source</i></b></a>
050: *
051: * @author Brian Wing Shun Chan
052: *
053: */
054: public class EditPagesAction extends PortletAction {
055:
056: public void processAction(ActionMapping mapping, ActionForm form,
057: PortletConfig config, ActionRequest req, ActionResponse res)
058: throws Exception {
059:
060: long groupId = ParamUtil.getLong(req, "groupId");
061: boolean privateLayout = ParamUtil.getBoolean(req,
062: "privateLayout");
063:
064: Layout layout = null;
065:
066: List layouts = LayoutLocalServiceUtil.getLayouts(groupId,
067: privateLayout, LayoutImpl.DEFAULT_PARENT_LAYOUT_ID, 0,
068: 1);
069:
070: if (layouts.size() > 0) {
071: layout = (Layout) layouts.get(0);
072: } else {
073: long parentLayoutId = LayoutImpl.DEFAULT_PARENT_LAYOUT_ID;
074: String name = "New Page";
075: String title = StringPool.BLANK;
076: String description = StringPool.BLANK;
077: String type = LayoutImpl.TYPE_PORTLET;
078: boolean hidden = false;
079: String friendlyURL = StringPool.BLANK;
080:
081: layout = LayoutServiceUtil.addLayout(groupId,
082: privateLayout, parentLayoutId, name, title,
083: description, type, hidden, friendlyURL);
084: }
085:
086: if (layout != null) {
087: String tabs2 = "public";
088:
089: if (privateLayout) {
090: tabs2 = "private";
091: }
092:
093: HttpServletRequest httReq = PortalUtil
094: .getHttpServletRequest(req);
095:
096: PortletURL portletURL = new PortletURLImpl(httReq,
097: PortletKeys.LAYOUT_MANAGEMENT, layout.getPlid(),
098: false);
099:
100: portletURL.setWindowState(WindowState.MAXIMIZED);
101: portletURL.setPortletMode(PortletMode.VIEW);
102:
103: portletURL.setParameter("struts_action",
104: "/layout_management/edit_pages");
105: portletURL.setParameter("tabs2", tabs2);
106: portletURL.setParameter("groupId", String.valueOf(groupId));
107:
108: res.sendRedirect(portletURL.toString());
109: }
110: }
111:
112: }
|