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