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.journalcontent;
022:
023: import com.liferay.portal.kernel.portlet.FriendlyURLMapper;
024: import com.liferay.portal.kernel.portlet.LiferayPortletURL;
025: import com.liferay.portal.kernel.util.GetterUtil;
026: import com.liferay.portal.kernel.util.StringPool;
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="JournalContentFriendlyURLMapper.java.html"><b><i>View Source</i></b>
037: * </a>
038: *
039: * @author Raymond Augé
040: *
041: */
042: public class JournalContentFriendlyURLMapper implements
043: FriendlyURLMapper {
044:
045: public String getMapping() {
046: return _MAPPING;
047: }
048:
049: public String buildPath(LiferayPortletURL portletURL) {
050: String friendlyURLPath = null;
051:
052: String strutsAction = GetterUtil.getString(portletURL
053: .getParameter("struts_action"));
054:
055: if (strutsAction.equals("/journal_content/view")) {
056: String portletId = portletURL.getPortletId();
057: String groupId = portletURL.getParameter("groupId");
058: String articleId = portletURL.getParameter("articleId");
059: String templateId = portletURL.getParameter("templateId");
060:
061: if (Validator.isNotNull(portletId)
062: && Validator.isNotNull(groupId)
063: && Validator.isNotNull(articleId)) {
064:
065: if (portletId.equals(_PORTLET_DEFAULT_INSTANCE)) {
066: portletId = _PORTLET_ID;
067: }
068:
069: friendlyURLPath = "/journal_content/" + portletId + "/"
070: + groupId + "/" + articleId;
071:
072: portletURL.addParameterIncludedInPath("groupId");
073: portletURL.addParameterIncludedInPath("articleId");
074:
075: if (Validator.isNotNull(templateId)) {
076: friendlyURLPath += "/" + templateId;
077:
078: portletURL.addParameterIncludedInPath("templateId");
079: }
080: }
081: }
082:
083: if (Validator.isNotNull(friendlyURLPath)) {
084: portletURL.addParameterIncludedInPath("p_p_id");
085: portletURL.addParameterIncludedInPath("struts_action");
086: }
087:
088: return friendlyURLPath;
089: }
090:
091: public void populateParams(String friendlyURLPath, Map params) {
092: int w = friendlyURLPath.indexOf("/", 1);
093: int x = friendlyURLPath.indexOf("/", w + 1);
094: int y = friendlyURLPath.indexOf("/", x + 1);
095: int z = friendlyURLPath.indexOf("/", y + 1);
096:
097: if (x == -1) {
098: return;
099: }
100:
101: String portletId = friendlyURLPath.substring(w + 1, x);
102:
103: String namespace = StringPool.UNDERLINE + portletId
104: + StringPool.UNDERLINE;
105:
106: if (Validator.equals(portletId, _PORTLET_ID)) {
107: portletId = _PORTLET_DEFAULT_INSTANCE;
108:
109: namespace = StringPool.UNDERLINE + portletId
110: + StringPool.UNDERLINE;
111:
112: params.put("p_p_id", portletId);
113: params.put("p_p_state", WindowState.MAXIMIZED.toString());
114: } else {
115: params.put("p_p_id", portletId);
116: params.put("p_p_state", WindowState.NORMAL.toString());
117: }
118:
119: params.put("p_p_action", "0");
120: params.put("p_p_mode", PortletMode.VIEW.toString());
121:
122: String groupId = friendlyURLPath.substring(x + 1, y);
123:
124: params.put(namespace + "groupId", groupId);
125:
126: String articleId = null;
127:
128: if (z == -1) {
129: articleId = friendlyURLPath.substring(y + 1,
130: friendlyURLPath.length());
131:
132: params.put(namespace + "articleId", articleId);
133: } else {
134: articleId = friendlyURLPath.substring(y + 1, z);
135:
136: params.put(namespace + "articleId", articleId);
137:
138: String templateId = friendlyURLPath.substring(z + 1,
139: friendlyURLPath.length());
140:
141: params.put(namespace + "templateId", templateId);
142: }
143:
144: params
145: .put(namespace + "struts_action",
146: "/journal_content/view");
147: }
148:
149: private static final String _MAPPING = "journal_content";
150:
151: private static final String _PORTLET_DEFAULT_INSTANCE = PortletKeys.JOURNAL_CONTENT
152: + "_INSTANCE_0000";
153:
154: private static final String _PORTLET_ID = PortletKeys.JOURNAL_CONTENT;
155:
156: }
|