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.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.CharPool;
20  import com.liferay.portal.kernel.util.StringBundler;
21  import com.liferay.portal.kernel.util.StringPool;
22  import com.liferay.portal.kernel.util.StringUtil;
23  import com.liferay.portal.util.PortletKeys;
24  
25  import java.util.Map;
26  
27  import javax.portlet.PortletMode;
28  import javax.portlet.WindowState;
29  
30  /**
31   * <a href="TagsCompilerFriendlyURLMapper.java.html"><b><i>View Source</i></b>
32   * </a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class TagsCompilerFriendlyURLMapper extends BaseFriendlyURLMapper {
37  
38      public String buildPath(LiferayPortletURL portletURL) {
39          return null;
40      }
41  
42      public String getMapping() {
43          return _MAPPING;
44      }
45  
46      public String getPortletId() {
47          return _PORTLET_ID;
48      }
49  
50      public boolean isCheckMappingWithPrefix() {
51          return _CHECK_MAPPING_WITH_PREFIX;
52      }
53  
54      public void populateParams(
55          String friendlyURLPath, Map<String, String[]> parameterMap) {
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(CharPool.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], CharPool.PLUS, CharPool.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  }