1
22
23 package com.liferay.portlet;
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.model.impl.PortletImpl;
31 import com.liferay.portal.util.PortalUtil;
32
33 import java.util.Map;
34
35 import javax.portlet.PortletMode;
36 import javax.portlet.WindowState;
37
38
44 public class WAIFriendlyURLMapper implements FriendlyURLMapper {
45
46 public String getMapping() {
47 return _MAPPING;
48 }
49
50 public String buildPath(LiferayPortletURL portletURL) {
51 String portletId = portletURL.getPortletId();
52
53 String prefix = portletId;
54
55 int pos = portletId.indexOf(PortletImpl.WAR_SEPARATOR);
56
57 if (pos != -1) {
58 prefix = portletId.substring(0, pos);
59 }
60
61 String appUrl = GetterUtil.getString(portletURL.getParameter("appURL"));
62
63 portletURL.addParameterIncludedInPath("p_p_id");
64
65 return StringPool.SLASH + _MAPPING + StringPool.SLASH + prefix +
66 StringPool.SLASH + appUrl;
67 }
68
69 public void populateParams(
70 String friendlyURLPath, Map<String, String[]> params) {
71
72 int x = friendlyURLPath.indexOf(_MAPPING);
73 int y = friendlyURLPath.indexOf("/", x + _MAPPING.length() + 1);
74
75 if (x == -1) {
76 return;
77 }
78
79 String prefix = friendlyURLPath.substring(x + _MAPPING.length() + 1, y);
80
81 String portletId = prefix + PortletImpl.WAR_SEPARATOR + prefix;
82
83 params.put("p_p_id", new String[] {portletId});
84 params.put("p_p_lifecycle", new String[] {"0"});
85
86 if (hasBinaryExtension(friendlyURLPath)) {
87 params.put(
88 "p_p_state",
89 new String[] {LiferayWindowState.EXCLUSIVE.toString()});
90 }
91 else {
92 params.put(
93 "p_p_state", new String[] {WindowState.MAXIMIZED.toString()});
94 }
95
96 params.put("p_p_mode", new String[] {PortletMode.VIEW.toString()});
97
98 String namespace = PortalUtil.getPortletNamespace(portletId);
99
100 String path = friendlyURLPath.substring(y);
101
102 params.put(namespace + "appURL", new String[] {path});
103 }
104
105 protected boolean hasBinaryExtension(String friendlyURLPath) {
106 for (int i = 0; i < _BINARY_EXTENSIONS.length; i++) {
107 String binaryExtension = _BINARY_EXTENSIONS[i];
108
109 if (friendlyURLPath.endsWith(binaryExtension)) {
110 return true;
111 }
112 }
113
114 return false;
115 }
116
117 private static final String _MAPPING = "waiapp";
118
119 private static final String[] _BINARY_EXTENSIONS = new String[] {
120 ".css", ".doc", ".gif", ".jpeg", ".jpg", ".js", ".odp", ".png", ".ppt",
121 ".tgz", ".xls", ".zip",
122 };
123
124 }