001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.tagscompiler;
016    
017    import com.liferay.portal.kernel.portlet.BaseFriendlyURLMapper;
018    import com.liferay.portal.kernel.portlet.LiferayPortletURL;
019    import com.liferay.portal.kernel.util.StringBundler;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.kernel.util.StringUtil;
022    
023    import java.util.Map;
024    
025    import javax.portlet.PortletMode;
026    import javax.portlet.WindowState;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class TagsCompilerFriendlyURLMapper extends BaseFriendlyURLMapper {
032    
033            public String buildPath(LiferayPortletURL liferayPortletURL) {
034                    return null;
035            }
036    
037            public boolean isCheckMappingWithPrefix() {
038                    return _CHECK_MAPPING_WITH_PREFIX;
039            }
040    
041            public void populateParams(
042                    String friendlyURLPath, Map<String, String[]> parameterMap,
043                    Map<String, Object> requestContext) {
044    
045                    addParameter(parameterMap, "p_p_id", getPortletId());
046                    addParameter(parameterMap, "p_p_lifecycle", "0");
047                    addParameter(parameterMap, "p_p_state", WindowState.NORMAL);
048                    addParameter(parameterMap, "p_p_mode", PortletMode.VIEW);
049    
050                    int x = friendlyURLPath.indexOf(StringPool.SLASH, 1);
051                    int y = friendlyURLPath.length();
052    
053                    String[] entries = StringUtil.split(
054                            friendlyURLPath.substring(x + 1, y), StringPool.SLASH);
055    
056                    if (entries.length > 0) {
057                            StringBundler sb = new StringBundler(entries.length * 2 - 1);
058    
059                            for (int i = 0; i < entries.length; i++) {
060                                    String entry = StringUtil.replace(
061                                            entries[i], StringPool.PLUS, StringPool.SPACE);
062    
063                                    if (i != 0) {
064                                            sb.append(StringPool.COMMA);
065                                    }
066    
067                                    sb.append(entry);
068                            }
069    
070                            addParameter(parameterMap, "entries", sb.toString());
071                    }
072            }
073    
074            private static final boolean _CHECK_MAPPING_WITH_PREFIX = false;
075    
076    }