001    /**
002     * Copyright (c) 2000-2010 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.wiki.engines.jspwiki;
016    
017    import com.ecyrd.jspwiki.WikiContext;
018    import com.ecyrd.jspwiki.url.URLConstructor;
019    
020    import com.liferay.portal.kernel.util.CharPool;
021    import com.liferay.portal.kernel.util.HttpUtil;
022    import com.liferay.portal.kernel.util.StringPool;
023    import com.liferay.portal.kernel.util.Validator;
024    import com.liferay.portlet.wiki.util.WikiUtil;
025    
026    import java.util.Properties;
027    
028    import javax.servlet.http.HttpServletRequest;
029    
030    /**
031     * @author Jorge Ferrer
032     */
033    public class LiferayURLConstructor implements URLConstructor {
034    
035            public String getForwardPage(HttpServletRequest request) {
036                    return "Wiki.jsp";
037            }
038    
039            public void initialize(
040                    com.ecyrd.jspwiki.WikiEngine engine, Properties props) {
041            }
042    
043            public String makeURL(
044                    String context, String name, boolean absolute, String parameters) {
045    
046                    if (Validator.isNotNull(parameters)) {
047                            if (context.equals(WikiContext.ATTACH)) {
048                                    parameters = StringPool.QUESTION + parameters;
049                            }
050                            else if (context.equals(WikiContext.NONE)) {
051                                    if (name.indexOf(CharPool.QUESTION) != -1) {
052                                            parameters = "&" + parameters;
053                                    }
054                                    else {
055                                            parameters = StringPool.QUESTION + parameters;
056                                    }
057                            }
058                            else {
059                                    parameters = "&" + parameters;
060                            }
061                    }
062                    else {
063                            parameters = StringPool.BLANK;
064                    }
065    
066                    String path;
067    
068                    if (context.equals(WikiContext.EDIT)) {
069                            path =
070                                    "[$BEGIN_PAGE_TITLE_EDIT$]" + WikiUtil.decodeJSPWikiName(name) +
071                                            "[$END_PAGE_TITLE_EDIT$]";
072                            }
073                    else if (context.equals(WikiContext.VIEW)) {
074                            path =
075                                    "[$BEGIN_PAGE_TITLE$]" + WikiUtil.decodeJSPWikiName(name) +
076                                            "[$END_PAGE_TITLE$]";
077                    }
078                    else if (context.equals(WikiContext.ATTACH)) {
079                            if (name.indexOf(CharPool.SLASH) == -1) {
080                                    path =
081                                            "[$ATTACHMENT_URL_PREFIX$][$WIKI_PAGE_NAME$]/" +
082                                                    HttpUtil.encodeURL(WikiUtil.decodeJSPWikiName(name));
083                            }
084                            else {
085                                    path =
086                                            "[$ATTACHMENT_URL_PREFIX$]" +
087                                                    HttpUtil.encodeURL(WikiUtil.decodeJSPWikiName(name));
088                            }
089                    }
090                    else {
091                            path = WikiUtil.decodeJSPWikiName(name);
092                    }
093    
094                    return path + parameters;
095            }
096    
097            public String parsePage(
098                    String context, HttpServletRequest request, String encoding) {
099    
100                    return "Wiki.jsp";
101            }
102    
103    }