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(String friendlyURLPath, Map params) {
94 int w = friendlyURLPath.indexOf("/", 1);
95 int x = friendlyURLPath.indexOf("/", w + 1);
96 int y = friendlyURLPath.indexOf("/", x + 1);
97 int z = friendlyURLPath.indexOf("/", y + 1);
98
99 if (x == -1) {
100 return;
101 }
102
103 String portletId = friendlyURLPath.substring(w + 1, x);
104
105 String namespace =
106 StringPool.UNDERLINE + portletId + StringPool.UNDERLINE;
107
108 if (Validator.equals(portletId, _PORTLET_ID)) {
109 portletId = _PORTLET_DEFAULT_INSTANCE;
110
111 namespace = StringPool.UNDERLINE + portletId + StringPool.UNDERLINE;
112
113 params.put("p_p_id", portletId);
114 params.put("p_p_state", WindowState.MAXIMIZED.toString());
115 }
116 else {
117 params.put("p_p_id", portletId);
118 params.put("p_p_state", WindowState.NORMAL.toString());
119 }
120
121 params.put("p_p_action", "0");
122 params.put("p_p_mode", PortletMode.VIEW.toString());
123
124 String groupId = friendlyURLPath.substring(x + 1, y);
125
126 params.put(namespace + "groupId", groupId);
127
128 String articleId = null;
129
130 if (z == -1) {
131 articleId =
132 friendlyURLPath.substring(y + 1, friendlyURLPath.length());
133
134 params.put(namespace + "articleId", articleId);
135 }
136 else {
137 articleId = friendlyURLPath.substring(y + 1, z);
138
139 params.put(namespace + "articleId", articleId);
140
141 String templateId =
142 friendlyURLPath.substring(z + 1, friendlyURLPath.length());
143
144 params.put(namespace + "templateId", templateId);
145 }
146
147 params.put(namespace + "struts_action", "/journal_content/view");
148 }
149
150 private static final String _MAPPING = "journal_content";
151
152 private static final String _PORTLET_DEFAULT_INSTANCE =
153 PortletKeys.JOURNAL_CONTENT + "_INSTANCE_0000";
154
155 private static final String _PORTLET_ID = PortletKeys.JOURNAL_CONTENT;
156
157 }