1
22
23 package com.liferay.portlet.journal;
24
25 import com.liferay.portal.kernel.portlet.BaseFriendlyURLMapper;
26 import com.liferay.portal.kernel.portlet.LiferayPortletURL;
27 import com.liferay.portal.kernel.portlet.LiferayWindowState;
28 import com.liferay.portal.kernel.util.GetterUtil;
29 import com.liferay.portal.kernel.util.StringPool;
30 import com.liferay.portal.kernel.util.StringUtil;
31 import com.liferay.portal.kernel.util.Validator;
32 import com.liferay.portal.util.PortletKeys;
33
34 import java.util.Map;
35
36 import javax.portlet.PortletMode;
37
38
44 public class JournalFriendlyURLMapper extends BaseFriendlyURLMapper {
45
46 public String getMapping() {
47 return _MAPPING;
48 }
49
50 public String getPortletId() {
51 return _PORTLET_ID;
52 }
53
54 public String buildPath(LiferayPortletURL portletURL) {
55 String friendlyURLPath = null;
56
57 String strutsAction = GetterUtil.getString(
58 portletURL.getParameter("struts_action"));
59
60 if ((strutsAction.equals("/journal/rss")) &&
61 (portletURL.getWindowState() == LiferayWindowState.EXCLUSIVE) &&
62 (!portletURL.isAction())) {
63
64 String groupId = portletURL.getParameter("groupId");
65 String feedId = portletURL.getParameter("feedId");
66
67 if (Validator.isNotNull(groupId) && Validator.isNotNull(feedId)) {
68 friendlyURLPath = "/journal/rss/" + groupId + "/" + feedId;
69
70 portletURL.addParameterIncludedInPath("groupId");
71 portletURL.addParameterIncludedInPath("feedId");
72 }
73 }
74
75 if (Validator.isNotNull(friendlyURLPath)) {
76 portletURL.addParameterIncludedInPath("p_p_id");
77 portletURL.addParameterIncludedInPath("struts_action");
78 }
79
80 return friendlyURLPath;
81 }
82
83 public void populateParams(String friendlyURLPath, Map params) {
84 String[] parts = StringUtil.split(friendlyURLPath, StringPool.SLASH);
85
86 if ((parts.length >= 4) && parts[2].equals("rss")) {
87 params.put("p_p_id", _PORTLET_ID);
88 params.put("p_p_action", "0");
89 params.put("p_p_state", LiferayWindowState.EXCLUSIVE.toString());
90 params.put("p_p_mode", PortletMode.VIEW.toString());
91
92 addParam(params, "struts_action", "/journal/rss");
93
94 if (parts.length == 4) {
95 addParam(params, "feedId", parts[3]);
96 }
97 else if (parts.length == 5) {
98 addParam(params, "groupId", parts[3]);
99 addParam(params, "feedId", parts[4]);
100 }
101 }
102 }
103
104 private static final String _MAPPING = "journal";
105
106 private static final String _PORTLET_ID = PortletKeys.JOURNAL;
107
108 }