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.wiki;
016    
017    import com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper;
018    import com.liferay.portal.kernel.portlet.LiferayPortletURL;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.util.Validator;
021    
022    import java.util.HashMap;
023    import java.util.Map;
024    
025    /**
026     * @author Shinn Lok
027     */
028    public class WikiFriendlyURLMapper extends DefaultFriendlyURLMapper {
029    
030            @Override
031            public String buildPath(LiferayPortletURL liferayPortletURL) {
032                    Map<String, String> routeParameters = new HashMap<String, String>();
033    
034                    buildRouteParameters(liferayPortletURL, routeParameters);
035    
036                    if (routeParameters.containsKey("title")) {
037                            String title = routeParameters.get("title");
038    
039                            title = title.replaceAll(StringPool.SLASH, "%2F");
040    
041                            routeParameters.put("title", title);
042                    }
043    
044                    String friendlyURLPath = router.parametersToUrl(routeParameters);
045    
046                    if (Validator.isNull(friendlyURLPath)) {
047                            return null;
048                    }
049    
050                    addParametersIncludedInPath(liferayPortletURL, routeParameters);
051    
052                    friendlyURLPath = StringPool.SLASH.concat(getMapping()).concat(
053                            friendlyURLPath);
054    
055                    return friendlyURLPath;
056            }
057    
058    }