| LiferayURLConstructor.java |
1 /**
2 * Copyright (c) 2000-2008 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.io.IOException;
33
34 import java.util.Properties;
35
36 import javax.servlet.http.HttpServletRequest;
37
38 /**
39 * <a href="LiferayURLConstructor.java.html"><b><i>View Source</i></b></a>
40 *
41 * @author Jorge Ferrer
42 *
43 */
44 public class LiferayURLConstructor implements URLConstructor {
45
46 public String getForwardPage(HttpServletRequest req) {
47 return "Wiki.jsp";
48 }
49
50 public void initialize(
51 com.ecyrd.jspwiki.WikiEngine engine, Properties props) {
52 }
53
54 public String makeURL(
55 String context, String name, boolean absolute, String parameters) {
56
57 if (Validator.isNotNull(parameters)) {
58 if (context.equals(WikiContext.ATTACH)) {
59 parameters = StringPool.QUESTION + parameters;
60 }
61 else if (context.equals(WikiContext.NONE)) {
62 if (name.indexOf(StringPool.QUESTION) != -1) {
63 parameters = "&" + parameters;
64 }
65 else {
66 parameters = StringPool.QUESTION + parameters;
67 }
68 }
69 else {
70 parameters = "&" + parameters;
71 }
72 }
73 else {
74 parameters = StringPool.BLANK;
75 }
76
77 String path;
78
79 if (context.equals(WikiContext.EDIT)) {
80 path =
81 "[$BEGIN_PAGE_TITLE_EDIT$]" + name + "[$END_PAGE_TITLE_EDIT$]";
82 }
83 else if (context.equals(WikiContext.VIEW)) {
84 path = "[$BEGIN_PAGE_TITLE$]" + name + "[$END_PAGE_TITLE$]";
85 }
86 else if (context.equals(WikiContext.ATTACH)) {
87 if (name.indexOf(StringPool.SLASH) == -1) {
88 path =
89 "[$ATTACHMENT_URL_PREFIX$][$WIKI_PAGE_NAME$]/" +
90 HttpUtil.encodeURL(name);
91 }
92 else {
93 path = "[$ATTACHMENT_URL_PREFIX$]" + HttpUtil.encodeURL(name);
94 }
95 }
96 else {
97 path = name;
98 }
99
100 return path + parameters;
101 }
102
103 public String parsePage(
104 String context, HttpServletRequest req, String encoding)
105 throws IOException {
106
107 return "Wiki.jsp";
108 }
109
110 }