1
22
23 package com.liferay.portlet.blogs.util;
24
25 import com.liferay.portal.kernel.language.LanguageUtil;
26 import com.liferay.portal.kernel.portlet.LiferayWindowState;
27 import com.liferay.portal.kernel.util.StringPool;
28 import com.liferay.portlet.blogs.model.BlogsCategory;
29 import com.liferay.portlet.blogs.service.BlogsCategoryLocalServiceUtil;
30
31 import javax.portlet.PortletURL;
32 import javax.portlet.RenderRequest;
33 import javax.portlet.RenderResponse;
34 import javax.portlet.WindowState;
35
36 import javax.servlet.jsp.PageContext;
37
38
44 public class BlogsUtil {
45
46 public static String getBreadcrumbs(
47 long categoryId, PageContext pageContext, RenderRequest req,
48 RenderResponse res)
49 throws Exception {
50
51 BlogsCategory category = null;
52
53 try {
54 category = BlogsCategoryLocalServiceUtil.getCategory(categoryId);
55 }
56 catch (Exception e) {
57 }
58
59 return getBreadcrumbs(category, pageContext, req, res);
60 }
61
62 public static String getBreadcrumbs(
63 BlogsCategory category, PageContext pageContext, RenderRequest req,
64 RenderResponse res)
65 throws Exception {
66
67 PortletURL categoriesURL = res.createRenderURL();
68
69 WindowState windowState = req.getWindowState();
70
71 if (windowState.equals(LiferayWindowState.POP_UP)) {
72 categoriesURL.setWindowState(LiferayWindowState.POP_UP);
73
74 categoriesURL.setParameter(
75 "struts_action", "/blogs/select_category");
76 }
77 else {
78 categoriesURL.setWindowState(WindowState.MAXIMIZED);
79
80 categoriesURL.setParameter("struts_action", "/blogs/view");
81 categoriesURL.setParameter("tabs1", "categories");
82 }
83
84 String categoriesLink =
85 "<a href=\"" + categoriesURL.toString() + "\">" +
86 LanguageUtil.get(pageContext, "categories") + "</a>";
87
88 if (category == null) {
89 return categoriesLink;
90 }
91
92 String breadcrumbs = StringPool.BLANK;
93
94 if (category != null) {
95 for (int i = 0;; i++) {
96 PortletURL portletURL = res.createRenderURL();
97
98 if (windowState.equals(LiferayWindowState.POP_UP)) {
99 portletURL.setWindowState(LiferayWindowState.POP_UP);
100
101 portletURL.setParameter(
102 "struts_action", "/blogs/select_category");
103 }
104 else {
105 portletURL.setWindowState(WindowState.MAXIMIZED);
106
107 portletURL.setParameter("struts_action", "/blogs/view");
108 portletURL.setParameter("tabs1", "categories");
109 portletURL.setParameter(
110 "categoryId", String.valueOf(category.getCategoryId()));
111 }
112
113 String categoryLink =
114 "<a href=\"" + portletURL.toString() + "\">" +
115 category.getName() + "</a>";
116
117 if (i == 0) {
118 breadcrumbs = categoryLink;
119 }
120 else {
121 breadcrumbs = categoryLink + " » " + breadcrumbs;
122 }
123
124 if (category.isRoot()) {
125 break;
126 }
127
128 category = BlogsCategoryLocalServiceUtil.getCategory(
129 category.getParentCategoryId());
130 }
131 }
132
133 breadcrumbs = categoriesLink + " » " + breadcrumbs;
134
135 return breadcrumbs;
136 }
137
138 }