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.blogs;
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.Validator;
028: import com.liferay.portal.util.PortletKeys;
029:
030: import java.util.Map;
031:
032: import javax.portlet.PortletMode;
033: import javax.portlet.WindowState;
034:
035: /**
036: * <a href="BlogsFriendlyURLMapper.java.html"><b><i>View Source</i></b></a>
037: *
038: * @author Brian Wing Shun Chan
039: *
040: */
041: public class BlogsFriendlyURLMapper extends BaseFriendlyURLMapper {
042:
043: public String getMapping() {
044: return _MAPPING;
045: }
046:
047: public String getPortletId() {
048: return _PORTLET_ID;
049: }
050:
051: public String buildPath(LiferayPortletURL portletURL) {
052: String friendlyURLPath = null;
053:
054: String strutsAction = GetterUtil.getString(portletURL
055: .getParameter("struts_action"));
056:
057: if (strutsAction.equals("/blogs/rss")) {
058: friendlyURLPath = "/blogs/rss";
059: } else if (strutsAction.equals("/blogs/view_entry")) {
060: String entryId = portletURL.getParameter("entryId");
061:
062: String urlTitle = portletURL.getParameter("urlTitle");
063:
064: if (Validator.isNotNull(entryId)) {
065: friendlyURLPath = "/blogs/" + entryId;
066:
067: portletURL.addParameterIncludedInPath("entryId");
068: } else if (Validator.isNotNull(urlTitle)) {
069: friendlyURLPath = "/blogs/" + urlTitle;
070:
071: portletURL.addParameterIncludedInPath("urlTitle");
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: params.put("p_p_id", _PORTLET_ID);
085: params.put("p_p_action", "0");
086: params.put("p_p_state", WindowState.NORMAL.toString());
087: params.put("p_p_mode", PortletMode.VIEW.toString());
088:
089: int x = friendlyURLPath.indexOf("/", 1);
090: int y = friendlyURLPath.length();
091:
092: if ((x + 1) == y) {
093: addParam(params, "struts_action", "/blogs/view");
094:
095: return;
096: }
097:
098: String type = friendlyURLPath.substring(x + 1, y);
099:
100: if (type.equals("rss")) {
101: params.put("p_p_action", "1");
102: params.put("p_p_state", LiferayWindowState.EXCLUSIVE
103: .toString());
104:
105: addParam(params, "struts_action", "/blogs/rss");
106: } else {
107: addParam(params, "struts_action", "/blogs/view_entry");
108:
109: if (Validator.isNumber(type)) {
110: String entryId = type;
111:
112: addParam(params, "entryId", entryId);
113: } else {
114: String urlTitle = type;
115:
116: addParam(params, "urlTitle", urlTitle);
117: }
118: }
119: }
120:
121: private static final String _MAPPING = "blogs";
122:
123: private static final String _PORTLET_ID = PortletKeys.BLOGS;
124:
125: }
|