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.util.GetterUtil;
28 import com.liferay.portal.kernel.util.StringPool;
29 import com.liferay.portal.kernel.util.StringUtil;
30 import com.liferay.portal.kernel.util.Validator;
31 import com.liferay.portal.util.PortletKeys;
32
33 import java.util.Map;
34
35 import javax.portlet.PortletRequest;
36 import javax.portlet.ResourceURL;
37
38
43 public class JournalFriendlyURLMapper extends BaseFriendlyURLMapper {
44
45 public String buildPath(LiferayPortletURL portletURL) {
46 String friendlyURLPath = null;
47
48 String strutsAction = GetterUtil.getString(
49 portletURL.getParameter("struts_action"));
50
51 if (strutsAction.equals("/journal/rss") &&
52 portletURL.getLifecycle().equals(PortletRequest.RESOURCE_PHASE)) {
53
54 String groupId = portletURL.getParameter("groupId");
55 String feedId = portletURL.getParameter("feedId");
56
57 if (Validator.isNotNull(groupId) && Validator.isNotNull(feedId)) {
58 friendlyURLPath = "/journal/rss/" + groupId + "/" + feedId;
59
60 portletURL.addParameterIncludedInPath("groupId");
61 portletURL.addParameterIncludedInPath("feedId");
62 }
63 }
64
65 if (Validator.isNotNull(friendlyURLPath)) {
66 portletURL.addParameterIncludedInPath("p_p_id");
67 portletURL.addParameterIncludedInPath("p_p_lifecycle");
68 portletURL.addParameterIncludedInPath("p_p_cacheability");
69
70 portletURL.addParameterIncludedInPath("struts_action");
71 }
72
73 return friendlyURLPath;
74 }
75
76 public String getMapping() {
77 return _MAPPING;
78 }
79
80 public String getPortletId() {
81 return _PORTLET_ID;
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", "2");
92 addParam(params, "p_p_cacheability", ResourceURL.FULL);
93
94 addParam(params, "struts_action", "/journal/rss");
95
96 if (parts.length == 4) {
97 addParam(params, "feedId", parts[3]);
98 }
99 else if (parts.length == 5) {
100 addParam(params, "groupId", parts[3]);
101 addParam(params, "feedId", parts[4]);
102 }
103 }
104 }
105
106 private static final String _MAPPING = "journal";
107
108 private static final String _PORTLET_ID = PortletKeys.JOURNAL;
109
110 }