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