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
44 public class JournalFriendlyURLMapper extends BaseFriendlyURLMapper {
45
46 public String buildPath(LiferayPortletURL portletURL) {
47 String friendlyURLPath = null;
48
49 String strutsAction = GetterUtil.getString(
50 portletURL.getParameter("struts_action"));
51
52 if (strutsAction.equals("/journal/rss") &&
53 portletURL.getLifecycle().equals(PortletRequest.RESOURCE_PHASE)) {
54
55 String groupId = portletURL.getParameter("groupId");
56 String feedId = portletURL.getParameter("feedId");
57
58 if (Validator.isNotNull(groupId) && Validator.isNotNull(feedId)) {
59 friendlyURLPath = "/journal/rss/" + groupId + "/" + feedId;
60
61 portletURL.addParameterIncludedInPath("groupId");
62 portletURL.addParameterIncludedInPath("feedId");
63 }
64 }
65
66 if (Validator.isNotNull(friendlyURLPath)) {
67 portletURL.addParameterIncludedInPath("p_p_id");
68 portletURL.addParameterIncludedInPath("p_p_lifecycle");
69 portletURL.addParameterIncludedInPath("p_p_cacheability");
70
71 portletURL.addParameterIncludedInPath("struts_action");
72 }
73
74 return friendlyURLPath;
75 }
76
77 public String getMapping() {
78 return _MAPPING;
79 }
80
81 public String getPortletId() {
82 return _PORTLET_ID;
83 }
84
85 public void populateParams(
86 String friendlyURLPath, Map<String, String[]> params) {
87
88 String[] parts = StringUtil.split(friendlyURLPath, StringPool.SLASH);
89
90 if ((parts.length >= 4) && parts[2].equals("rss")) {
91 addParam(params, "p_p_id", _PORTLET_ID);
92 addParam(params, "p_p_lifecycle", "2");
93 addParam(params, "p_p_cacheability", ResourceURL.FULL);
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 }