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.tagscompiler;
16  
17  import com.liferay.portal.kernel.portlet.BaseFriendlyURLMapper;
18  import com.liferay.portal.kernel.portlet.LiferayPortletURL;
19  import com.liferay.portal.kernel.util.StringBundler;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portal.kernel.util.StringUtil;
22  import com.liferay.portal.util.PortletKeys;
23  
24  import java.util.Map;
25  
26  import javax.portlet.PortletMode;
27  import javax.portlet.WindowState;
28  
29  /**
30   * <a href="TagsCompilerFriendlyURLMapper.java.html"><b><i>View Source</i></b>
31   * </a>
32   *
33   * @author Brian Wing Shun Chan
34   */
35  public class TagsCompilerFriendlyURLMapper extends BaseFriendlyURLMapper {
36  
37      public String buildPath(LiferayPortletURL portletURL) {
38          return null;
39      }
40  
41      public String getMapping() {
42          return _MAPPING;
43      }
44  
45      public String getPortletId() {
46          return _PORTLET_ID;
47      }
48  
49      public boolean isCheckMappingWithPrefix() {
50          return _CHECK_MAPPING_WITH_PREFIX;
51      }
52  
53      public void populateParams(
54          String friendlyURLPath, Map<String, String[]> parameterMap,
55          Map<String, Object> requestContext) {
56  
57          addParameter(parameterMap, "p_p_id", _PORTLET_ID);
58          addParameter(parameterMap, "p_p_lifecycle", "0");
59          addParameter(parameterMap, "p_p_state", WindowState.NORMAL);
60          addParameter(parameterMap, "p_p_mode", PortletMode.VIEW);
61  
62          int x = friendlyURLPath.indexOf(StringPool.SLASH, 1);
63          int y = friendlyURLPath.length();
64  
65          String[] entries = StringUtil.split(
66              friendlyURLPath.substring(x + 1, y), StringPool.SLASH);
67  
68          if (entries.length > 0) {
69              StringBundler sb = new StringBundler(entries.length * 2 - 1);
70  
71              for (int i = 0; i < entries.length; i++) {
72                  String entry = StringUtil.replace(
73                      entries[i], StringPool.PLUS, StringPool.SPACE);
74  
75                  if (i != 0) {
76                      sb.append(StringPool.COMMA);
77                  }
78  
79                  sb.append(entry);
80              }
81  
82              addParameter(parameterMap, "entries", sb.toString());
83          }
84      }
85  
86      private static final boolean _CHECK_MAPPING_WITH_PREFIX = false;
87  
88      private static final String _MAPPING = "tags";
89  
90      private static final String _PORTLET_ID = PortletKeys.TAGS_COMPILER;
91  
92  }