1
22
23 package com.liferay.portlet.journalcontent;
24
25 import com.liferay.portal.kernel.portlet.FriendlyURLMapper;
26 import com.liferay.portal.kernel.portlet.LiferayPortletURL;
27 import com.liferay.portal.kernel.portlet.LiferayWindowState;
28 import com.liferay.portal.kernel.util.GetterUtil;
29 import com.liferay.portal.kernel.util.StringPool;
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.PortletMode;
36 import javax.portlet.WindowState;
37
38
44 public class JournalContentFriendlyURLMapper implements FriendlyURLMapper {
45
46 public String buildPath(LiferayPortletURL portletURL) {
47 String friendlyURLPath = null;
48
49 String strutsAction = GetterUtil.getString(
50 portletURL.getParameter("struts_action"));
51
52 WindowState windowState = portletURL.getWindowState();
53
54 if ((strutsAction.equals("/journal_content/view")) &&
55 ((windowState == null) ||
56 (!windowState.equals(LiferayWindowState.EXCLUSIVE)))) {
57
58 String portletId = portletURL.getPortletId();
59 String groupId = portletURL.getParameter("groupId");
60 String articleId = portletURL.getParameter("articleId");
61 String templateId = portletURL.getParameter("templateId");
62
63 if (Validator.isNotNull(portletId) &&
64 Validator.isNotNull(groupId) &&
65 Validator.isNotNull(articleId)) {
66
67 if (portletId.equals(_PORTLET_DEFAULT_INSTANCE)) {
68 portletId = _PORTLET_ID;
69 }
70
71 friendlyURLPath =
72 "/journal_content/" + portletId + "/" + groupId + "/" +
73 articleId;
74
75 portletURL.addParameterIncludedInPath("groupId");
76 portletURL.addParameterIncludedInPath("articleId");
77
78 if (Validator.isNotNull(templateId)) {
79 friendlyURLPath += "/" + templateId;
80
81 portletURL.addParameterIncludedInPath("templateId");
82 }
83 }
84 }
85
86 if (Validator.isNotNull(friendlyURLPath)) {
87 portletURL.addParameterIncludedInPath("p_p_id");
88
89 portletURL.addParameterIncludedInPath("struts_action");
90 }
91
92 return friendlyURLPath;
93 }
94
95 public String getMapping() {
96 return _MAPPING;
97 }
98
99 public boolean isCheckMappingWithPrefix() {
100 return _CHECK_MAPPING_WITH_PREFIX;
101 }
102
103 public void populateParams(
104 String friendlyURLPath, Map<String, String[]> params) {
105
106 int w = friendlyURLPath.indexOf("/", 1);
107 int x = friendlyURLPath.indexOf("/", w + 1);
108 int y = friendlyURLPath.indexOf("/", x + 1);
109 int z = friendlyURLPath.indexOf("/", y + 1);
110
111 if (x == -1) {
112 return;
113 }
114
115 String portletId = friendlyURLPath.substring(w + 1, x);
116
117 String namespace =
118 StringPool.UNDERLINE + portletId + StringPool.UNDERLINE;
119
120 if (Validator.equals(portletId, _PORTLET_ID)) {
121 portletId = _PORTLET_DEFAULT_INSTANCE;
122
123 namespace = StringPool.UNDERLINE + portletId + StringPool.UNDERLINE;
124
125 params.put("p_p_id", new String[] {portletId});
126 params.put(
127 "p_p_state", new String[] {WindowState.MAXIMIZED.toString()});
128 }
129 else {
130 params.put("p_p_id", new String[] {portletId});
131 params.put(
132 "p_p_state", new String[] {WindowState.NORMAL.toString()});
133 }
134
135 params.put("p_p_lifecycle", new String[] {"0"});
136 params.put("p_p_mode", new String[] {PortletMode.VIEW.toString()});
137
138 String groupId = friendlyURLPath.substring(x + 1, y);
139
140 params.put(namespace + "groupId", new String[] {groupId});
141
142 String articleId = null;
143
144 if (z == -1) {
145 articleId =
146 friendlyURLPath.substring(y + 1, friendlyURLPath.length());
147
148 params.put(namespace + "articleId", new String[] {articleId});
149 }
150 else {
151 articleId = friendlyURLPath.substring(y + 1, z);
152
153 params.put(namespace + "articleId", new String[] {articleId});
154
155 String templateId =
156 friendlyURLPath.substring(z + 1, friendlyURLPath.length());
157
158 params.put(namespace + "templateId", new String[] {templateId});
159 }
160
161 params.put(
162 namespace + "struts_action",
163 new String[] {"/journal_content/view"});
164 }
165
166 private static final boolean _CHECK_MAPPING_WITH_PREFIX = true;
167
168 private static final String _MAPPING = "journal_content";
169
170 private static final String _PORTLET_DEFAULT_INSTANCE =
171 PortletKeys.JOURNAL_CONTENT + "_INSTANCE_0000";
172
173 private static final String _PORTLET_ID = PortletKeys.JOURNAL_CONTENT;
174
175 }