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.messageboards;
022:
023: import com.liferay.portal.kernel.portlet.BaseFriendlyURLMapper;
024: import com.liferay.portal.kernel.portlet.LiferayPortletURL;
025: import com.liferay.portal.kernel.util.GetterUtil;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.portal.util.PortletKeys;
028: import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
029:
030: import java.util.Map;
031:
032: import javax.portlet.PortletMode;
033: import javax.portlet.WindowState;
034:
035: /**
036: * <a href="MBFriendlyURLMapper.java.html"><b><i>View Source</i></b></a>
037: *
038: * @author Brian Wing Shun Chan
039: * @author Jorge Ferrer
040: *
041: */
042: public class MBFriendlyURLMapper 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 tabs1 = GetterUtil.getString(portletURL
056: .getParameter("tabs1"));
057: String tabs2 = GetterUtil.getString(portletURL
058: .getParameter("tabs2"));
059:
060: if (Validator.isNotNull(tabs2)) {
061: return null;
062: }
063:
064: String strutsAction = GetterUtil.getString(portletURL
065: .getParameter("struts_action"));
066:
067: if (strutsAction.equals("/message_boards/view")) {
068: String categoryId = GetterUtil.getString(portletURL
069: .getParameter("categoryId"));
070:
071: if (Validator.isNotNull(categoryId)
072: && !categoryId.equals("0")) {
073: friendlyURLPath = "/message_boards/category/"
074: + categoryId;
075:
076: portletURL.addParameterIncludedInPath("categoryId");
077: } else {
078: friendlyURLPath = "/message_boards";
079:
080: if (Validator.isNotNull(tabs1)
081: && !tabs1.equals("categories")) {
082: friendlyURLPath += "/" + tabs1;
083: }
084:
085: portletURL.addParameterIncludedInPath("tabs1");
086:
087: if (categoryId.equals("0")) {
088: portletURL.addParameterIncludedInPath("categoryId");
089: }
090: }
091: } else if (strutsAction.equals("/message_boards/view_message")) {
092: String messageId = portletURL.getParameter("messageId");
093:
094: if (Validator.isNotNull(messageId)) {
095: friendlyURLPath = "/message_boards/message/"
096: + messageId;
097:
098: portletURL.addParameterIncludedInPath("messageId");
099: }
100: }
101:
102: if (Validator.isNotNull(friendlyURLPath)) {
103: portletURL.addParameterIncludedInPath("p_p_id");
104: portletURL.addParameterIncludedInPath("struts_action");
105: }
106:
107: return friendlyURLPath;
108: }
109:
110: public void populateParams(String friendlyURLPath, Map params) {
111: params.put("p_p_id", _PORTLET_ID);
112: params.put("p_p_action", "0");
113: params.put("p_p_state", WindowState.MAXIMIZED.toString());
114: params.put("p_p_mode", PortletMode.VIEW.toString());
115:
116: int x = friendlyURLPath.indexOf("/", 1);
117:
118: if ((x + 1) == friendlyURLPath.length()) {
119: addParam(params, "struts_action", "/message_boards/view");
120: addParam(params, "categoryId",
121: MBCategoryImpl.DEFAULT_PARENT_CATEGORY_ID);
122:
123: return;
124: }
125:
126: int y = friendlyURLPath.indexOf("/", x + 1);
127:
128: if (y == -1) {
129: y = friendlyURLPath.length();
130: }
131:
132: String type = friendlyURLPath.substring(x + 1, y);
133:
134: if (type.equals("category")) {
135: String categoryId = friendlyURLPath.substring(y + 1,
136: friendlyURLPath.length());
137:
138: addParam(params, "struts_action", "/message_boards/view");
139: addParam(params, "categoryId", categoryId);
140: } else if (type.equals("message")) {
141: String messageId = friendlyURLPath.substring(y + 1,
142: friendlyURLPath.length());
143:
144: addParam(params, "struts_action",
145: "/message_boards/view_message");
146: addParam(params, "messageId", messageId);
147: } else if (type.equals("my_posts")
148: || type.equals("my_subscriptions")
149: || type.equals("recent_posts")
150: || type.equals("statistics")
151: || type.equals("banned_users")) {
152:
153: addParam(params, "struts_action", "/message_boards/view");
154: params.put("tabs1", type);
155: }
156: }
157:
158: private static final String _MAPPING = "message_boards";
159:
160: private static final String _PORTLET_ID = PortletKeys.MESSAGE_BOARDS;
161:
162: }
|