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 String decodedName = HttpUtil.encodeURL(
046 WikiUtil.decodeJSPWikiName(name));
047
048 if (Validator.isNotNull(parameters)) {
049 if (context.equals(WikiContext.ATTACH)) {
050 parameters = StringPool.QUESTION + parameters;
051 }
052 else if (context.equals(WikiContext.NONE)) {
053 if (decodedName.indexOf(StringPool.QUESTION) != -1) {
054 parameters = "&" + parameters;
055 }
056 else {
057 parameters = StringPool.QUESTION + parameters;
058 }
059 }
060 else {
061 parameters = "&" + parameters;
062 }
063 }
064 else {
065 parameters = StringPool.BLANK;
066 }
067
068 String path;
069
070 if (context.equals(WikiContext.EDIT)) {
071 path =
072 "[$BEGIN_PAGE_TITLE_EDIT$]" + decodedName +
073 "[$END_PAGE_TITLE_EDIT$]";
074 }
075 else if (context.equals(WikiContext.VIEW)) {
076 path = "[$BEGIN_PAGE_TITLE$]" + decodedName + "[$END_PAGE_TITLE$]";
077 }
078 else if (context.equals(WikiContext.ATTACH)) {
079 if (decodedName.indexOf(StringPool.SLASH) == -1) {
080 path =
081 "[$ATTACHMENT_URL_PREFIX$][$WIKI_PAGE_NAME$]/" +
082 decodedName;
083 }
084 else {
085 path = "[$ATTACHMENT_URL_PREFIX$]" + decodedName;
086 }
087 }
088 else {
089 path = decodedName;
090 }
091
092 return path + parameters;
093 }
094
095 public String parsePage(
096 String context, HttpServletRequest request, String encoding) {
097
098 return "Wiki.jsp";
099 }
100
101 }