001
014
015 package com.liferay.portal.util;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.model.Layout;
019 import com.liferay.portal.kernel.model.LayoutConstants;
020 import com.liferay.portal.kernel.service.ServiceContext;
021 import com.liferay.portal.kernel.service.persistence.LayoutUtil;
022 import com.liferay.portal.kernel.theme.ThemeDisplay;
023 import com.liferay.portal.kernel.util.PortalUtil;
024 import com.liferay.portal.kernel.util.StringPool;
025
026 import javax.servlet.http.HttpServletRequest;
027
028
031 public class LayoutURLUtil {
032
033 public static String getLayoutURL(
034 Layout layout, ServiceContext serviceContext) {
035
036 HttpServletRequest request = serviceContext.getRequest();
037
038 if (request == null) {
039 return StringPool.BLANK;
040 }
041
042 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
043 com.liferay.portal.kernel.util.WebKeys.THEME_DISPLAY);
044
045 try {
046 return PortalUtil.getLayoutURL(layout, themeDisplay);
047 }
048 catch (Exception e) {
049 return StringPool.BLANK;
050 }
051 }
052
053 public static String getLayoutURL(
054 long groupId, String portletId, ServiceContext serviceContext)
055 throws PortalException {
056
057 long plid = serviceContext.getPlid();
058
059 long controlPanelPlid = PortalUtil.getControlPanelPlid(
060 serviceContext.getCompanyId());
061
062 if (plid == controlPanelPlid) {
063 plid = PortalUtil.getPlidFromPortletId(groupId, portletId);
064 }
065
066 String layoutURL = StringPool.BLANK;
067
068 if (plid != LayoutConstants.DEFAULT_PLID) {
069 Layout layout = LayoutUtil.findByPrimaryKey(plid);
070
071 layoutURL = getLayoutURL(layout, serviceContext);
072 }
073
074 return layoutURL;
075 }
076
077 }