1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.wiki.engines.jspwiki;
16  
17  import com.ecyrd.jspwiki.WikiContext;
18  import com.ecyrd.jspwiki.url.URLConstructor;
19  
20  import com.liferay.portal.kernel.util.HttpUtil;
21  import com.liferay.portal.kernel.util.StringPool;
22  import com.liferay.portal.kernel.util.Validator;
23  
24  import java.util.Properties;
25  
26  import javax.servlet.http.HttpServletRequest;
27  
28  /**
29   * <a href="LiferayURLConstructor.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Jorge Ferrer
32   */
33  public class LiferayURLConstructor implements URLConstructor {
34  
35      public String getForwardPage(HttpServletRequest request) {
36          return "Wiki.jsp";
37      }
38  
39      public void initialize(
40          com.ecyrd.jspwiki.WikiEngine engine, Properties props) {
41      }
42  
43      public String makeURL(
44          String context, String name, boolean absolute, String parameters) {
45  
46          if (Validator.isNotNull(parameters)) {
47              if (context.equals(WikiContext.ATTACH)) {
48                  parameters = StringPool.QUESTION + parameters;
49              }
50              else if (context.equals(WikiContext.NONE)) {
51                  if (name.indexOf(StringPool.QUESTION) != -1) {
52                      parameters = "&amp;" + parameters;
53                  }
54                  else {
55                      parameters = StringPool.QUESTION + parameters;
56                  }
57              }
58              else {
59                  parameters = "&amp;" + parameters;
60              }
61          }
62          else {
63              parameters = StringPool.BLANK;
64          }
65  
66          String path;
67  
68          if (context.equals(WikiContext.EDIT)) {
69              path =
70                  "[$BEGIN_PAGE_TITLE_EDIT$]" + name + "[$END_PAGE_TITLE_EDIT$]";
71          }
72          else if (context.equals(WikiContext.VIEW)) {
73              path = "[$BEGIN_PAGE_TITLE$]" + name + "[$END_PAGE_TITLE$]";
74          }
75          else if (context.equals(WikiContext.ATTACH)) {
76              if (name.indexOf(StringPool.SLASH) == -1) {
77                  path =
78                      "[$ATTACHMENT_URL_PREFIX$][$WIKI_PAGE_NAME$]/" +
79                          HttpUtil.encodeURL(name);
80              }
81              else {
82                  path = "[$ATTACHMENT_URL_PREFIX$]" + HttpUtil.encodeURL(name);
83              }
84          }
85          else {
86              path = name;
87          }
88  
89          return path + parameters;
90      }
91  
92      public String parsePage(
93          String context, HttpServletRequest request, String encoding) {
94  
95          return "Wiki.jsp";
96      }
97  
98  }