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