001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet;
022:
023: import com.liferay.portal.kernel.portlet.FriendlyURLMapper;
024: import com.liferay.portal.kernel.portlet.LiferayPortletURL;
025: import com.liferay.portal.kernel.portlet.LiferayWindowState;
026: import com.liferay.portal.kernel.util.GetterUtil;
027: import com.liferay.portal.kernel.util.StringPool;
028: import com.liferay.portal.model.impl.PortletImpl;
029: import com.liferay.portal.util.PortalUtil;
030:
031: import java.util.Map;
032:
033: import javax.portlet.PortletMode;
034: import javax.portlet.WindowState;
035:
036: /**
037: * <a href="WAIFriendlyURLMapper.java.html"><b><i>View Source</i></b></a>
038: *
039: * @author Jorge Ferrer
040: *
041: */
042: public class WAIFriendlyURLMapper implements FriendlyURLMapper {
043:
044: public String getMapping() {
045: return _MAPPING;
046: }
047:
048: public String buildPath(LiferayPortletURL portletURL) {
049: String portletId = portletURL.getPortletId();
050:
051: String prefix = portletId;
052:
053: int pos = portletId.indexOf(PortletImpl.WAR_SEPARATOR);
054:
055: if (pos != -1) {
056: prefix = portletId.substring(0, pos);
057: }
058:
059: String appUrl = GetterUtil.getString(portletURL
060: .getParameter("appURL"));
061:
062: portletURL.addParameterIncludedInPath("p_p_id");
063:
064: return StringPool.SLASH + _MAPPING + StringPool.SLASH + prefix
065: + StringPool.SLASH + appUrl;
066: }
067:
068: public void populateParams(String friendlyURLPath, Map params) {
069: int x = friendlyURLPath.indexOf(_MAPPING);
070: int y = friendlyURLPath.indexOf("/", x + _MAPPING.length() + 1);
071:
072: if (x == -1) {
073: return;
074: }
075:
076: String prefix = friendlyURLPath.substring(x + _MAPPING.length()
077: + 1, y);
078:
079: String portletId = prefix + PortletImpl.WAR_SEPARATOR + prefix;
080:
081: params.put("p_p_id", portletId);
082:
083: params.put("p_p_action", "0");
084:
085: if (hasBinaryExtension(friendlyURLPath)) {
086: params.put("p_p_state", LiferayWindowState.EXCLUSIVE
087: .toString());
088: } else {
089: params.put("p_p_state", WindowState.MAXIMIZED.toString());
090: }
091:
092: params.put("p_p_mode", PortletMode.VIEW.toString());
093:
094: String namespace = PortalUtil.getPortletNamespace(portletId);
095:
096: String path = friendlyURLPath.substring(y);
097:
098: params.put(namespace + "appURL", path);
099: }
100:
101: protected boolean hasBinaryExtension(String friendlyURLPath) {
102: for (int i = 0; i < _BINARY_EXTENSIONS.length; i++) {
103: String binaryExtension = _BINARY_EXTENSIONS[i];
104:
105: if (friendlyURLPath.endsWith(binaryExtension)) {
106: return true;
107: }
108: }
109:
110: return false;
111: }
112:
113: private static final String _MAPPING = "waiapp";
114:
115: private static final String[] _BINARY_EXTENSIONS = new String[] {
116: ".css", ".doc", ".gif", ".jpeg", ".jpg", ".js", ".odp",
117: ".png", ".ppt", ".tgz", ".xls", ".zip", };
118:
119: }
|