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