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.communities.util;
022:
023: import com.germinus.easyconf.Filter;
024:
025: import com.liferay.portal.events.EventsProcessor;
026: import com.liferay.portal.kernel.security.permission.ActionKeys;
027: import com.liferay.portal.kernel.security.permission.PermissionChecker;
028: import com.liferay.portal.kernel.util.ParamUtil;
029: import com.liferay.portal.kernel.util.StringUtil;
030: import com.liferay.portal.model.Layout;
031: import com.liferay.portal.service.LayoutLocalServiceUtil;
032: import com.liferay.portal.service.LayoutServiceUtil;
033: import com.liferay.portal.service.permission.LayoutPermissionUtil;
034: import com.liferay.portal.theme.ThemeDisplay;
035: import com.liferay.portal.util.PropsUtil;
036: import com.liferay.portal.util.WebKeys;
037: import com.liferay.portlet.ActionRequestImpl;
038: import com.liferay.portlet.ActionResponseImpl;
039: import com.liferay.portlet.RenderRequestImpl;
040: import com.liferay.portlet.RenderResponseImpl;
041:
042: import javax.portlet.ActionRequest;
043: import javax.portlet.ActionResponse;
044: import javax.portlet.RenderRequest;
045: import javax.portlet.RenderResponse;
046:
047: import javax.servlet.http.HttpServletRequest;
048: import javax.servlet.http.HttpServletResponse;
049:
050: /**
051: * <a href="CommunitiesUtil.java.html"><b><i>View Source</i></b></a>
052: *
053: * @author Raymond Augé
054: *
055: */
056: public class CommunitiesUtil {
057:
058: public static void deleteLayout(ActionRequest req,
059: ActionResponse res) throws Exception {
060:
061: HttpServletRequest httpReq = (HttpServletRequest) ((ActionRequestImpl) req)
062: .getHttpServletRequest();
063: HttpServletResponse httpRes = (HttpServletResponse) ((ActionResponseImpl) res)
064: .getHttpServletResponse();
065:
066: deleteLayout(httpReq, httpRes);
067: }
068:
069: public static void deleteLayout(RenderRequest req,
070: RenderResponse res) throws Exception {
071:
072: HttpServletRequest httpReq = (HttpServletRequest) ((RenderRequestImpl) req)
073: .getHttpServletRequest();
074: HttpServletResponse httpRes = (HttpServletResponse) ((RenderResponseImpl) res)
075: .getHttpServletResponse();
076:
077: deleteLayout(httpReq, httpRes);
078: }
079:
080: public static void deleteLayout(HttpServletRequest req,
081: HttpServletResponse res) throws Exception {
082:
083: ThemeDisplay themeDisplay = (ThemeDisplay) req
084: .getAttribute(WebKeys.THEME_DISPLAY);
085:
086: PermissionChecker permissionChecker = themeDisplay
087: .getPermissionChecker();
088:
089: long plid = ParamUtil.getLong(req, "plid");
090:
091: long groupId = ParamUtil.getLong(req, "groupId");
092: boolean privateLayout = ParamUtil.getBoolean(req,
093: "privateLayout");
094: long layoutId = ParamUtil.getLong(req, "layoutId");
095:
096: Layout layout = null;
097:
098: if (plid <= 0) {
099: layout = LayoutLocalServiceUtil.getLayout(groupId,
100: privateLayout, layoutId);
101: } else {
102: layout = LayoutLocalServiceUtil.getLayout(plid);
103:
104: groupId = layout.getGroupId();
105: privateLayout = layout.isPrivateLayout();
106: layoutId = layout.getLayoutId();
107: }
108:
109: if (LayoutPermissionUtil.contains(permissionChecker, groupId,
110: privateLayout, layoutId, ActionKeys.DELETE)) {
111:
112: String[] eventClasses = StringUtil
113: .split(PropsUtil
114: .getComponentProperties()
115: .getString(
116: PropsUtil.LAYOUT_CONFIGURATION_ACTION_DELETE,
117: Filter.by(layout.getType())));
118:
119: EventsProcessor.process(eventClasses, req, res);
120: }
121:
122: LayoutServiceUtil
123: .deleteLayout(groupId, privateLayout, layoutId);
124: }
125:
126: }
|