1
22
23 package com.liferay.portlet.assetpublisher;
24
25 import com.liferay.portal.kernel.portlet.BaseFriendlyURLMapper;
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.StringUtil;
31 import com.liferay.portal.kernel.util.Validator;
32 import com.liferay.portal.util.PortletKeys;
33 import com.liferay.portlet.assetpublisher.util.AssetPublisherUtil;
34
35 import java.util.Map;
36
37 import javax.portlet.PortletMode;
38 import javax.portlet.WindowState;
39
40
47 public class AssetPublisherFriendlyURLMapper extends BaseFriendlyURLMapper {
48
49 public String buildPath(LiferayPortletURL portletURL) {
50 String friendlyURLPath = null;
51
52 String strutsAction = GetterUtil.getString(
53 portletURL.getParameter("struts_action"));
54
55 WindowState windowState = portletURL.getWindowState();
56
57 if ((strutsAction.equals("/asset_publisher/view_content")) &&
58 ((windowState == null) ||
59 (!windowState.equals(LiferayWindowState.EXCLUSIVE)))) {
60
61 String portletId = portletURL.getPortletId();
62 String assetId = portletURL.getParameter("assetId");
63 String type = GetterUtil.getString(
64 portletURL.getParameter("type"), "content");
65
66 if (Validator.isNotNull(portletId) &&
67 Validator.isNotNull(assetId)) {
68
69 if (portletId.equals(_PORTLET_DEFAULT_INSTANCE)) {
70 portletId = _PORTLET_ID;
71 }
72
73 int pos = portletId.indexOf("_INSTANCE_");
74
75 String instanceId = null;
76
77 if (pos > 0) {
78 instanceId = portletId.substring(pos + 10);
79 }
80 else {
81 instanceId = portletId;
82 }
83
84 friendlyURLPath =
85 "/asset_publisher/" + instanceId + StringPool.SLASH + type +
86 StringPool.SLASH + assetId;
87
88 portletURL.addParameterIncludedInPath("type");
89 portletURL.addParameterIncludedInPath("assetId");
90 }
91 }
92
93 if (Validator.isNotNull(friendlyURLPath)) {
94 portletURL.addParameterIncludedInPath("p_p_id");
95
96 portletURL.addParameterIncludedInPath("struts_action");
97 }
98
99 return friendlyURLPath;
100 }
101
102 public String getMapping() {
103 return _MAPPING;
104 }
105
106 public String getPortletId() {
107 return _PORTLET_ID;
108 }
109
110 public void populateParams(
111 String friendlyURLPath, Map<String, String[]> params) {
112
113 int x = friendlyURLPath.indexOf(StringPool.SLASH, 1);
114
115 String[] urlFragments = StringUtil.split(
116 friendlyURLPath.substring(x + 1), StringPool.SLASH);
117
118 if (urlFragments.length > 2) {
119 String instanceId = urlFragments[0];
120 String type = urlFragments[1];
121 String assetId = urlFragments[2];
122
123 String portletId = _PORTLET_ID + "_INSTANCE_" + instanceId;
124
125 if (Validator.equals(portletId, _PORTLET_ID)) {
126 portletId = _PORTLET_DEFAULT_INSTANCE;
127
128 params.put("p_p_id", new String[] {portletId});
129 params.put(
130 "p_p_state",
131 new String[] {WindowState.MAXIMIZED.toString()});
132 }
133 else {
134 params.put("p_p_id", new String[] {portletId});
135 params.put(
136 "p_p_state", new String[] {WindowState.NORMAL.toString()});
137 }
138
139 params.put("p_p_lifecycle", new String[] {"0"});
140 params.put("p_p_mode", new String[] {PortletMode.VIEW.toString()});
141
142 String namespace =
143 StringPool.UNDERLINE + portletId + StringPool.UNDERLINE;
144
145 params.put(
146 namespace + "struts_action",
147 new String[] {"/asset_publisher/view_content"});
148
149 if (Validator.isNumber(assetId) &&
150 !type.equals(AssetPublisherUtil.TYPE_CONTENT)) {
151
152 params.put(namespace + "assetId", new String[] {assetId});
153 }
154 else {
155 params.put(namespace + "type", new String[] {type});
156 params.put(namespace + "urlTitle", new String[] {assetId});
157 }
158 }
159 }
160
161 private static final String _MAPPING = "asset_publisher";
162
163 private static final String _PORTLET_DEFAULT_INSTANCE =
164 PortletKeys.ASSET_PUBLISHER + "_INSTANCE_0000";
165
166 private static final String _PORTLET_ID = PortletKeys.ASSET_PUBLISHER;
167
168 }