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.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    }