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 import javax.portlet.PortletRequest;
38
39
45 public class JournalFriendlyURLMapper extends BaseFriendlyURLMapper {
46
47 public String getMapping() {
48 return _MAPPING;
49 }
50
51 public String getPortletId() {
52 return _PORTLET_ID;
53 }
54
55 public String buildPath(LiferayPortletURL portletURL) {
56 String friendlyURLPath = null;
57
58 String strutsAction = GetterUtil.getString(
59 portletURL.getParameter("struts_action"));
60
61 if ((strutsAction.equals("/journal/rss")) &&
62 (portletURL.getWindowState() == LiferayWindowState.EXCLUSIVE) &&
63 (portletURL.getLifecycle().equals(PortletRequest.RENDER_PHASE))) {
64
65 String groupId = portletURL.getParameter("groupId");
66 String feedId = portletURL.getParameter("feedId");
67
68 if (Validator.isNotNull(groupId) && Validator.isNotNull(feedId)) {
69 friendlyURLPath = "/journal/rss/" + groupId + "/" + feedId;
70
71 portletURL.addParameterIncludedInPath("groupId");
72 portletURL.addParameterIncludedInPath("feedId");
73 }
74 }
75
76 if (Validator.isNotNull(friendlyURLPath)) {
77 portletURL.addParameterIncludedInPath("p_p_id");
78 portletURL.addParameterIncludedInPath("struts_action");
79 }
80
81 return friendlyURLPath;
82 }
83
84 public void populateParams(
85 String friendlyURLPath, Map<String, String[]> params) {
86
87 String[] parts = StringUtil.split(friendlyURLPath, StringPool.SLASH);
88
89 if ((parts.length >= 4) && parts[2].equals("rss")) {
90 addParam(params, "p_p_id", _PORTLET_ID);
91 addParam(params, "p_p_lifecycle", "0");
92 addParam(params, "p_p_state", LiferayWindowState.EXCLUSIVE);
93 addParam(params, "p_p_mode", PortletMode.VIEW);
94
95 addParam(params, "struts_action", "/journal/rss");
96
97 if (parts.length == 4) {
98 addParam(params, "feedId", parts[3]);
99 }
100 else if (parts.length == 5) {
101 addParam(params, "groupId", parts[3]);
102 addParam(params, "feedId", parts[4]);
103 }
104 }
105 }
106
107 private static final String _MAPPING = "journal";
108
109 private static final String _PORTLET_ID = PortletKeys.JOURNAL;
110
111 }