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.wiki;
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.StringMaker;
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: import javax.portlet.WindowState;
036:
037: /**
038: * <a href="WikiFriendlyURLMapper.java.html"><b><i>View Source</i></b></a>
039: *
040: * @author Jorge Ferrer
041: *
042: */
043: public class WikiFriendlyURLMapper extends BaseFriendlyURLMapper {
044:
045: public String getMapping() {
046: return _MAPPING;
047: }
048:
049: public String getPortletId() {
050: return _PORTLET_ID;
051: }
052:
053: public String buildPath(LiferayPortletURL portletURL) {
054: String friendlyURLPath = null;
055:
056: String strutsAction = GetterUtil.getString(portletURL
057: .getParameter("struts_action"));
058:
059: if (strutsAction.equals("/wiki/view")) {
060: String title = portletURL.getParameter("title");
061: String nodeId = portletURL.getParameter("nodeId");
062:
063: if (Validator.isNotNull(nodeId)) {
064: StringMaker sm = new StringMaker();
065:
066: sm.append(StringPool.SLASH);
067: sm.append(_MAPPING);
068: sm.append(StringPool.SLASH);
069: sm.append(nodeId);
070:
071: portletURL.addParameterIncludedInPath("nodeId");
072:
073: if (Validator.isNotNull(title)) {
074: sm.append(StringPool.SLASH);
075: sm.append(title);
076:
077: portletURL.addParameterIncludedInPath("title");
078: }
079:
080: friendlyURLPath = sm.toString();
081: }
082: }
083:
084: if (Validator.isNotNull(friendlyURLPath)) {
085: portletURL.addParameterIncludedInPath("p_p_id");
086: portletURL.addParameterIncludedInPath("struts_action");
087: }
088:
089: return friendlyURLPath;
090: }
091:
092: public void populateParams(String friendlyURLPath, Map params) {
093: params.put("p_p_id", _PORTLET_ID);
094: params.put("p_p_action", "0");
095: params.put("p_p_state", WindowState.MAXIMIZED.toString());
096: params.put("p_p_mode", PortletMode.VIEW.toString());
097:
098: addParam(params, "struts_action", "/wiki/view");
099:
100: int x = friendlyURLPath.indexOf(StringPool.SLASH, 1);
101:
102: String[] urlFragments = StringUtil.split(friendlyURLPath
103: .substring(x + 1), StringPool.SLASH);
104:
105: if (urlFragments.length >= 1) {
106: String nodeId = urlFragments[0];
107:
108: addParam(params, "nodeId", nodeId);
109:
110: if (urlFragments.length >= 2) {
111: String title = urlFragments[1];
112:
113: addParam(params, "title", title);
114: }
115: }
116: }
117:
118: private static final String _MAPPING = "wikipage";
119:
120: private static final String _PORTLET_ID = PortletKeys.WIKI;
121:
122: }
|