001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.StringPool;
021    import com.liferay.portal.kernel.util.StringUtil;
022    import com.liferay.portal.util.PropsValues;
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     * @author Shuyang Zhou
032     */
033    public class TagsCompilerFriendlyURLMapper extends BaseFriendlyURLMapper {
034    
035            @Override
036            public String buildPath(LiferayPortletURL liferayPortletURL) {
037                    return null;
038            }
039    
040            @Override
041            public boolean isCheckMappingWithPrefix() {
042                    return _CHECK_MAPPING_WITH_PREFIX;
043            }
044    
045            @Override
046            public void populateParams(
047                    String friendlyURLPath, Map<String, String[]> parameterMap,
048                    Map<String, Object> requestContext) {
049    
050                    if (PropsValues.TAGS_COMPILER_ENABLED) {
051                            addParameter(parameterMap, "p_p_id", getPortletId());
052                            addParameter(parameterMap, "p_p_lifecycle", "0");
053                            addParameter(parameterMap, "p_p_state", WindowState.NORMAL);
054                            addParameter(parameterMap, "p_p_mode", PortletMode.VIEW);
055    
056                            int x = friendlyURLPath.indexOf(CharPool.SLASH, 1);
057                            int y = friendlyURLPath.length();
058    
059                            String[] entries = StringUtil.split(
060                                    friendlyURLPath.substring(x + 1, y), CharPool.SLASH);
061    
062                            if (entries.length > 0) {
063                                    addParameter(parameterMap, "tags", entries);
064                            }
065                            else {
066                                    addParameter(parameterMap, "tags", StringPool.BLANK);
067                            }
068                    }
069            }
070    
071            private static final boolean _CHECK_MAPPING_WITH_PREFIX = false;
072    
073    }