001
014
015 package com.liferay.portlet.imagegallery.util;
016
017 import com.liferay.portal.kernel.portlet.LiferayWindowState;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.theme.ThemeDisplay;
020 import com.liferay.portal.util.PortalUtil;
021 import com.liferay.portal.util.WebKeys;
022 import com.liferay.portlet.imagegallery.model.IGFolder;
023 import com.liferay.portlet.imagegallery.model.IGFolderConstants;
024 import com.liferay.portlet.imagegallery.model.IGImage;
025 import com.liferay.portlet.imagegallery.service.IGFolderLocalServiceUtil;
026
027 import java.util.Collections;
028 import java.util.List;
029
030 import javax.portlet.PortletURL;
031 import javax.portlet.RenderResponse;
032
033 import javax.servlet.http.HttpServletRequest;
034
035
038 public class IGUtil {
039
040 public static void addPortletBreadcrumbEntries(
041 IGImage image, HttpServletRequest request,
042 RenderResponse renderResponse)
043 throws Exception {
044
045 IGFolder folder = image.getFolder();
046
047 addPortletBreadcrumbEntries(folder, request, renderResponse);
048
049 PortletURL portletURL = renderResponse.createRenderURL();
050
051 portletURL.setParameter("struts_action", "/image_gallery/view_image");
052 portletURL.setParameter("imageId", String.valueOf(image.getImageId()));
053
054 PortalUtil.addPortletBreadcrumbEntry(
055 request, image.getName(), portletURL.toString());
056 }
057
058 public static void addPortletBreadcrumbEntries(
059 long folderId, HttpServletRequest request,
060 RenderResponse renderResponse)
061 throws Exception {
062
063 if (folderId == IGFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
064 return;
065 }
066
067 IGFolder folder = IGFolderLocalServiceUtil.getFolder(
068 folderId);
069
070 addPortletBreadcrumbEntries(folder, request, renderResponse);
071 }
072
073 public static void addPortletBreadcrumbEntries(
074 IGFolder folder, HttpServletRequest request,
075 RenderResponse renderResponse)
076 throws Exception {
077
078 String strutsAction = ParamUtil.getString(request, "struts_action");
079
080 PortletURL portletURL = renderResponse.createRenderURL();
081
082 if (strutsAction.equals("/journal/select_image_gallery") ||
083 strutsAction.equals("/image_gallery/select_folder")) {
084 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
085 WebKeys.THEME_DISPLAY);
086
087 portletURL.setWindowState(LiferayWindowState.POP_UP);
088
089 portletURL.setParameter("struts_action", strutsAction);
090
091 PortalUtil.addPortletBreadcrumbEntry(
092 request, themeDisplay.translate("images-home"),
093 portletURL.toString());
094 }
095 else {
096 portletURL.setParameter("struts_action", "/image_gallery/view");
097 }
098
099 List<IGFolder> ancestorFolders = folder.getAncestors();
100
101 Collections.reverse(ancestorFolders);
102
103 for (IGFolder ancestorFolder : ancestorFolders) {
104
105 portletURL.setParameter(
106 "folderId", String.valueOf(ancestorFolder.getFolderId()));
107
108 PortalUtil.addPortletBreadcrumbEntry(
109 request, ancestorFolder.getName(), portletURL.toString());
110 }
111
112 portletURL.setParameter(
113 "folderId", String.valueOf(folder.getFolderId()));
114
115 PortalUtil.addPortletBreadcrumbEntry(
116 request, folder.getName(), portletURL.toString());
117 }
118
119 }