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.journal;
022:
023: import com.liferay.portal.kernel.portlet.BaseFriendlyURLMapper;
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.kernel.util.StringUtil;
029: import com.liferay.portal.kernel.util.Validator;
030: import com.liferay.portal.util.PortletKeys;
031:
032: import java.util.Map;
033:
034: import javax.portlet.PortletMode;
035:
036: /**
037: * <a href="JournalFriendlyURLMapper.java.html"><b><i>View Source</i></b></a>
038: *
039: * @author Raymond Augé
040: *
041: */
042: public class JournalFriendlyURLMapper extends BaseFriendlyURLMapper {
043:
044: public String getMapping() {
045: return _MAPPING;
046: }
047:
048: public String getPortletId() {
049: return _PORTLET_ID;
050: }
051:
052: public String buildPath(LiferayPortletURL portletURL) {
053: String friendlyURLPath = null;
054:
055: String strutsAction = GetterUtil.getString(portletURL
056: .getParameter("struts_action"));
057:
058: if ((strutsAction.equals("/journal/rss"))
059: && (portletURL.getWindowState() == LiferayWindowState.EXCLUSIVE)
060: && (!portletURL.isAction())) {
061:
062: String groupId = portletURL.getParameter("groupId");
063: String feedId = portletURL.getParameter("feedId");
064:
065: if (Validator.isNotNull(groupId)
066: && Validator.isNotNull(feedId)) {
067: friendlyURLPath = "/journal/rss/" + groupId + "/"
068: + feedId;
069:
070: portletURL.addParameterIncludedInPath("groupId");
071: portletURL.addParameterIncludedInPath("feedId");
072: }
073: }
074:
075: if (Validator.isNotNull(friendlyURLPath)) {
076: portletURL.addParameterIncludedInPath("p_p_id");
077: portletURL.addParameterIncludedInPath("struts_action");
078: }
079:
080: return friendlyURLPath;
081: }
082:
083: public void populateParams(String friendlyURLPath, Map params) {
084: String[] parts = StringUtil.split(friendlyURLPath,
085: StringPool.SLASH);
086:
087: if ((parts.length >= 4) && parts[2].equals("rss")) {
088: params.put("p_p_id", _PORTLET_ID);
089: params.put("p_p_action", "0");
090: params.put("p_p_state", LiferayWindowState.EXCLUSIVE
091: .toString());
092: params.put("p_p_mode", PortletMode.VIEW.toString());
093:
094: addParam(params, "struts_action", "/journal/rss");
095:
096: if (parts.length == 4) {
097: addParam(params, "feedId", parts[3]);
098: } else if (parts.length == 5) {
099: addParam(params, "groupId", parts[3]);
100: addParam(params, "feedId", parts[4]);
101: }
102: }
103: }
104:
105: private static final String _MAPPING = "journal";
106:
107: private static final String _PORTLET_ID = PortletKeys.JOURNAL;
108:
109: }
|