1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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[]> params) {
78  
79          String[] parts = StringUtil.split(friendlyURLPath, StringPool.SLASH);
80  
81          if ((parts.length >= 4) && parts[2].equals("rss")) {
82              addParam(params, "p_p_id", _PORTLET_ID);
83              addParam(params, "p_p_lifecycle", "2");
84              addParam(params, "p_p_cacheability", ResourceURL.FULL);
85  
86              addParam(params, "struts_action", "/journal/rss");
87  
88              if (parts.length == 4) {
89                  addParam(params, "feedId", parts[3]);
90              }
91              else if (parts.length == 5) {
92                  addParam(params, "groupId", parts[3]);
93                  addParam(params, "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 }