001    /**
002     * Copyright (c) 2000-2013 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.CharPool;
020    import com.liferay.portal.kernel.util.StringBundler;
021    import com.liferay.portal.kernel.util.StringPool;
022    import com.liferay.portal.kernel.util.StringUtil;
023    
024    import java.util.Map;
025    
026    import javax.portlet.PortletMode;
027    import javax.portlet.WindowState;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     */
032    public class TagsCompilerFriendlyURLMapper extends BaseFriendlyURLMapper {
033    
034            @Override
035            public String buildPath(LiferayPortletURL liferayPortletURL) {
036                    return null;
037            }
038    
039            @Override
040            public boolean isCheckMappingWithPrefix() {
041                    return _CHECK_MAPPING_WITH_PREFIX;
042            }
043    
044            @Override
045            public void populateParams(
046                    String friendlyURLPath, Map<String, String[]> parameterMap,
047                    Map<String, Object> requestContext) {
048    
049                    addParameter(parameterMap, "p_p_id", getPortletId());
050                    addParameter(parameterMap, "p_p_lifecycle", "0");
051                    addParameter(parameterMap, "p_p_state", WindowState.NORMAL);
052                    addParameter(parameterMap, "p_p_mode", PortletMode.VIEW);
053    
054                    int x = friendlyURLPath.indexOf(CharPool.SLASH, 1);
055                    int y = friendlyURLPath.length();
056    
057                    String[] entries = StringUtil.split(
058                            friendlyURLPath.substring(x + 1, y), CharPool.SLASH);
059    
060                    if (entries.length > 0) {
061                            StringBundler sb = new StringBundler(entries.length * 2 - 1);
062    
063                            for (int i = 0; i < entries.length; i++) {
064                                    String entry = StringUtil.replace(
065                                            entries[i], CharPool.PLUS, CharPool.SPACE);
066    
067                                    if (i != 0) {
068                                            sb.append(StringPool.COMMA);
069                                    }
070    
071                                    sb.append(entry);
072                            }
073    
074                            addParameter(parameterMap, "entries", sb.toString());
075                    }
076            }
077    
078            private static final boolean _CHECK_MAPPING_WITH_PREFIX = false;
079    
080    }