1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.tagscompiler;
21  
22  import com.liferay.portal.kernel.portlet.BaseFriendlyURLMapper;
23  import com.liferay.portal.kernel.portlet.LiferayPortletURL;
24  import com.liferay.portal.kernel.util.StringPool;
25  import com.liferay.portal.kernel.util.StringUtil;
26  import com.liferay.portal.util.PortletKeys;
27  
28  import java.util.Map;
29  
30  import javax.portlet.PortletMode;
31  import javax.portlet.WindowState;
32  
33  /**
34   * <a href="TagsCompilerFriendlyURLMapper.java.html"><b><i>View Source</i></b>
35   * </a>
36   *
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class TagsCompilerFriendlyURLMapper extends BaseFriendlyURLMapper {
41  
42      public String buildPath(LiferayPortletURL portletURL) {
43          return null;
44      }
45  
46      public String getMapping() {
47          return _MAPPING;
48      }
49  
50      public String getPortletId() {
51          return _PORTLET_ID;
52      }
53  
54      public boolean isCheckMappingWithPrefix() {
55          return _CHECK_MAPPING_WITH_PREFIX;
56      }
57  
58      public void populateParams(
59          String friendlyURLPath, Map<String, String[]> params) {
60  
61          addParam(params, "p_p_id", _PORTLET_ID);
62          addParam(params, "p_p_lifecycle", "0");
63          addParam(params, "p_p_state", WindowState.NORMAL);
64          addParam(params, "p_p_mode", PortletMode.VIEW);
65  
66          int x = friendlyURLPath.indexOf(StringPool.SLASH, 1);
67          int y = friendlyURLPath.length();
68  
69          String[] entries = StringUtil.split(
70              friendlyURLPath.substring(x + 1, y), StringPool.SLASH);
71  
72          if (entries.length > 0) {
73              StringBuilder sb = new StringBuilder();
74  
75              for (int i = 0; i < entries.length; i++) {
76                  String entry = StringUtil.replace(
77                      entries[i], StringPool.PLUS, StringPool.SPACE);
78  
79                  if (i != 0) {
80                      sb.append(StringPool.COMMA);
81                  }
82  
83                  sb.append(entry);
84              }
85  
86              addParam(params, "entries", sb.toString());
87          }
88      }
89  
90      private static final boolean _CHECK_MAPPING_WITH_PREFIX = false;
91  
92      private static final String _MAPPING = "tags";
93  
94      private static final String _PORTLET_ID = PortletKeys.TAGS_COMPILER;
95  
96  }