1
14
15 package com.liferay.portlet.blogs;
16
17 import com.liferay.portal.kernel.portlet.BaseFriendlyURLMapper;
18 import com.liferay.portal.kernel.portlet.LiferayPortletURL;
19 import com.liferay.portal.kernel.portlet.LiferayWindowState;
20 import com.liferay.portal.kernel.util.GetterUtil;
21 import com.liferay.portal.kernel.util.HttpUtil;
22 import com.liferay.portal.kernel.util.StringPool;
23 import com.liferay.portal.kernel.util.Validator;
24 import com.liferay.portal.util.PortletKeys;
25
26 import java.util.Map;
27
28 import javax.portlet.PortletMode;
29 import javax.portlet.WindowState;
30
31
36 public class BlogsFriendlyURLMapper extends BaseFriendlyURLMapper {
37
38 public String buildPath(LiferayPortletURL portletURL) {
39 String friendlyURLPath = null;
40
41 String strutsAction = GetterUtil.getString(
42 portletURL.getParameter("struts_action"));
43
44 if (strutsAction.equals("/blogs/rss")) {
45 friendlyURLPath = "/blogs/rss";
46 }
47 else if (strutsAction.equals("/blogs/view_entry")) {
48 String entryId = portletURL.getParameter("entryId");
49
50 String urlTitle = portletURL.getParameter("urlTitle");
51
52 if (Validator.isNotNull(entryId)) {
53 friendlyURLPath = "/blogs/" + entryId;
54
55 portletURL.addParameterIncludedInPath("entryId");
56 }
57 else if (Validator.isNotNull(urlTitle)) {
58 friendlyURLPath = "/blogs/" + HttpUtil.encodeURL(urlTitle);
59
60 portletURL.addParameterIncludedInPath("urlTitle");
61 }
62 }
63
64 if (Validator.isNotNull(friendlyURLPath)) {
65 WindowState windowState = portletURL.getWindowState();
66
67 if (windowState.equals(WindowState.MAXIMIZED)) {
68 friendlyURLPath += StringPool.SLASH + windowState;
69 }
70
71 portletURL.addParameterIncludedInPath("p_p_id");
72
73 portletURL.addParameterIncludedInPath("struts_action");
74 }
75
76 return friendlyURLPath;
77 }
78
79 public String getMapping() {
80 return _MAPPING;
81 }
82
83 public String getPortletId() {
84 return _PORTLET_ID;
85 }
86
87 public void populateParams(
88 String friendlyURLPath, Map<String, String[]> params) {
89
90 addParam(params, "p_p_id", _PORTLET_ID);
91 addParam(params, "p_p_lifecycle", "0");
92 addParam(params, "p_p_mode", PortletMode.VIEW);
93
94 int x = friendlyURLPath.indexOf("/", 1);
95 int y = friendlyURLPath.indexOf("/", x + 1);
96
97 if (y == -1) {
98 y = friendlyURLPath.length();
99 }
100
101 if ((x + 1) == friendlyURLPath.length()) {
102 addParam(params, "struts_action", "/blogs/view");
103
104 return;
105 }
106
107 String type = friendlyURLPath.substring(x + 1, y);
108
109 if (type.equals("rss")) {
110 addParam(params, "p_p_lifecycle", "1");
111 addParam(params, "p_p_state", LiferayWindowState.EXCLUSIVE);
112
113 addParam(params, "struts_action", "/blogs/rss");
114 }
115 else if (type.equals("trackback")) {
116 addParam(params, "p_p_lifecycle", "1");
117 addParam(params, "p_p_state", LiferayWindowState.EXCLUSIVE);
118
119 addParam(params, "struts_action", "/blogs/trackback");
120
121 type = friendlyURLPath.substring(y + 1);
122
123 addParam(params, getEntryIdParam(type), type);
124 }
125 else {
126 addParam(params, "struts_action", "/blogs/view_entry");
127
128 addParam(params, getEntryIdParam(type), type);
129 }
130
131 if (friendlyURLPath.indexOf("maximized", x) != -1) {
132 addParam(params, "p_p_state", WindowState.MAXIMIZED);
133 }
134 }
135
136 protected String getEntryIdParam(String type) {
137 if (Validator.isNumber(type)) {
138 return "entryId";
139 }
140 else {
141 return "urlTitle";
142 }
143 }
144
145 private static final String _MAPPING = "blogs";
146
147 private static final String _PORTLET_ID = PortletKeys.BLOGS;
148
149 }