1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.journal;
16  
17  import com.liferay.portal.kernel.portlet.BaseFriendlyURLMapper;
18  import com.liferay.portal.kernel.portlet.LiferayPortletURL;
19  import com.liferay.portal.kernel.util.GetterUtil;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portal.kernel.util.StringUtil;
22  import com.liferay.portal.kernel.util.Validator;
23  import com.liferay.portal.util.PortletKeys;
24  
25  import java.util.Map;
26  
27  import javax.portlet.PortletRequest;
28  import javax.portlet.ResourceURL;
29  
30  /**
31   * <a href="JournalFriendlyURLMapper.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Raymond Augé
34   */
35  public class JournalFriendlyURLMapper extends BaseFriendlyURLMapper {
36  
37      public String buildPath(LiferayPortletURL portletURL) {
38          String friendlyURLPath = null;
39  
40          String strutsAction = GetterUtil.getString(
41              portletURL.getParameter("struts_action"));
42  
43          if (strutsAction.equals("/journal/rss") &&
44              portletURL.getLifecycle().equals(PortletRequest.RESOURCE_PHASE)) {
45  
46              String groupId = portletURL.getParameter("groupId");
47              String feedId = portletURL.getParameter("feedId");
48  
49              if (Validator.isNotNull(groupId) && Validator.isNotNull(feedId)) {
50                  friendlyURLPath = "/journal/rss/" + groupId + "/" + feedId;
51  
52                  portletURL.addParameterIncludedInPath("groupId");
53                  portletURL.addParameterIncludedInPath("feedId");
54              }
55          }
56  
57          if (Validator.isNotNull(friendlyURLPath)) {
58              portletURL.addParameterIncludedInPath("p_p_id");
59              portletURL.addParameterIncludedInPath("p_p_lifecycle");
60              portletURL.addParameterIncludedInPath("p_p_cacheability");
61  
62              portletURL.addParameterIncludedInPath("struts_action");
63          }
64  
65          return friendlyURLPath;
66      }
67  
68      public String getMapping() {
69          return _MAPPING;
70      }
71  
72      public String getPortletId() {
73          return _PORTLET_ID;
74      }
75  
76      public void populateParams(
77          String friendlyURLPath, Map<String, String[]> parameterMap) {
78  
79          String[] parts = StringUtil.split(friendlyURLPath, StringPool.SLASH);
80  
81          if ((parts.length >= 4) && parts[2].equals("rss")) {
82              addParameter(parameterMap, "p_p_id", _PORTLET_ID);
83              addParameter(parameterMap, "p_p_lifecycle", "2");
84              addParameter(parameterMap, "p_p_cacheability", ResourceURL.FULL);
85  
86              addParameter(parameterMap, "struts_action", "/journal/rss");
87  
88              if (parts.length == 4) {
89                  addParameter(parameterMap, "feedId", parts[3]);
90              }
91              else if (parts.length == 5) {
92                  addParameter(parameterMap, "groupId", parts[3]);
93                  addParameter(parameterMap, "feedId", parts[4]);
94              }
95          }
96      }
97  
98      private static final String _MAPPING = "journal";
99  
100     private static final String _PORTLET_ID = PortletKeys.JOURNAL;
101 
102 }