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