001    /**
002     * Copyright (c) 2000-2012 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.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            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            public void populateParams(
045                    String friendlyURLPath, Map<String, String[]> parameterMap,
046                    Map<String, Object> requestContext) {
047    
048                    if (PropsValues.TAGS_COMPILER_ENABLED) {
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                                    addParameter(parameterMap, "tags", entries);
062                            }
063                            else {
064                                    addParameter(parameterMap, "tags", StringPool.BLANK);
065                            }
066                    }
067            }
068    
069            private static final boolean _CHECK_MAPPING_WITH_PREFIX = false;
070    
071    }