| LiferayURLConstructor.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.liferay.portlet.wiki.engines.jspwiki;
24
25 import com.ecyrd.jspwiki.WikiContext;
26 import com.ecyrd.jspwiki.url.URLConstructor;
27
28 import com.liferay.portal.kernel.util.HttpUtil;
29 import com.liferay.portal.kernel.util.StringPool;
30 import com.liferay.portal.kernel.util.Validator;
31
32 import java.util.Properties;
33
34 import javax.servlet.http.HttpServletRequest;
35
36 /**
37 * <a href="LiferayURLConstructor.java.html"><b><i>View Source</i></b></a>
38 *
39 * @author Jorge Ferrer
40 */
41 public class LiferayURLConstructor implements URLConstructor {
42
43 public String getForwardPage(HttpServletRequest request) {
44 return "Wiki.jsp";
45 }
46
47 public void initialize(
48 com.ecyrd.jspwiki.WikiEngine engine, Properties props) {
49 }
50
51 public String makeURL(
52 String context, String name, boolean absolute, String parameters) {
53
54 if (Validator.isNotNull(parameters)) {
55 if (context.equals(WikiContext.ATTACH)) {
56 parameters = StringPool.QUESTION + parameters;
57 }
58 else if (context.equals(WikiContext.NONE)) {
59 if (name.indexOf(StringPool.QUESTION) != -1) {
60 parameters = "&" + parameters;
61 }
62 else {
63 parameters = StringPool.QUESTION + parameters;
64 }
65 }
66 else {
67 parameters = "&" + parameters;
68 }
69 }
70 else {
71 parameters = StringPool.BLANK;
72 }
73
74 String path;
75
76 if (context.equals(WikiContext.EDIT)) {
77 path =
78 "[$BEGIN_PAGE_TITLE_EDIT$]" + name + "[$END_PAGE_TITLE_EDIT$]";
79 }
80 else if (context.equals(WikiContext.VIEW)) {
81 path = "[$BEGIN_PAGE_TITLE$]" + name + "[$END_PAGE_TITLE$]";
82 }
83 else if (context.equals(WikiContext.ATTACH)) {
84 if (name.indexOf(StringPool.SLASH) == -1) {
85 path =
86 "[$ATTACHMENT_URL_PREFIX$][$WIKI_PAGE_NAME$]/" +
87 HttpUtil.encodeURL(name);
88 }
89 else {
90 path = "[$ATTACHMENT_URL_PREFIX$]" + HttpUtil.encodeURL(name);
91 }
92 }
93 else {
94 path = name;
95 }
96
97 return path + parameters;
98 }
99
100 public String parsePage(
101 String context, HttpServletRequest request, String encoding) {
102
103 return "Wiki.jsp";
104 }
105
106 }