1
14
15 package com.liferay.portlet.journal;
16
17 import com.liferay.portal.kernel.portlet.BaseFriendlyURLMapper;
18 import com.liferay.portal.kernel.portlet.LiferayPortletURL;
19 import com.liferay.portal.kernel.util.GetterUtil;
20 import com.liferay.portal.kernel.util.StringPool;
21 import com.liferay.portal.kernel.util.StringUtil;
22 import com.liferay.portal.kernel.util.Validator;
23 import com.liferay.portal.util.PortletKeys;
24
25 import java.util.Map;
26
27 import javax.portlet.PortletRequest;
28 import javax.portlet.ResourceURL;
29
30
35 public class JournalFriendlyURLMapper extends BaseFriendlyURLMapper {
36
37 public String buildPath(LiferayPortletURL portletURL) {
38 String friendlyURLPath = null;
39
40 String strutsAction = GetterUtil.getString(
41 portletURL.getParameter("struts_action"));
42
43 if (strutsAction.equals("/journal/rss") &&
44 portletURL.getLifecycle().equals(PortletRequest.RESOURCE_PHASE)) {
45
46 String groupId = portletURL.getParameter("groupId");
47 String feedId = portletURL.getParameter("feedId");
48
49 if (Validator.isNotNull(groupId) && Validator.isNotNull(feedId)) {
50 friendlyURLPath = "/journal/rss/" + groupId + "/" + feedId;
51
52 portletURL.addParameterIncludedInPath("groupId");
53 portletURL.addParameterIncludedInPath("feedId");
54 }
55 }
56
57 if (Validator.isNotNull(friendlyURLPath)) {
58 portletURL.addParameterIncludedInPath("p_p_id");
59 portletURL.addParameterIncludedInPath("p_p_lifecycle");
60 portletURL.addParameterIncludedInPath("p_p_cacheability");
61
62 portletURL.addParameterIncludedInPath("struts_action");
63 }
64
65 return friendlyURLPath;
66 }
67
68 public String getMapping() {
69 return _MAPPING;
70 }
71
72 public String getPortletId() {
73 return _PORTLET_ID;
74 }
75
76 public void populateParams(
77 String friendlyURLPath, Map<String, String[]> params) {
78
79 String[] parts = StringUtil.split(friendlyURLPath, StringPool.SLASH);
80
81 if ((parts.length >= 4) && parts[2].equals("rss")) {
82 addParam(params, "p_p_id", _PORTLET_ID);
83 addParam(params, "p_p_lifecycle", "2");
84 addParam(params, "p_p_cacheability", ResourceURL.FULL);
85
86 addParam(params, "struts_action", "/journal/rss");
87
88 if (parts.length == 4) {
89 addParam(params, "feedId", parts[3]);
90 }
91 else if (parts.length == 5) {
92 addParam(params, "groupId", parts[3]);
93 addParam(params, "feedId", parts[4]);
94 }
95 }
96 }
97
98 private static final String _MAPPING = "journal";
99
100 private static final String _PORTLET_ID = PortletKeys.JOURNAL;
101
102 }