1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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.CharPool;
21  import com.liferay.portal.kernel.util.HttpUtil;
22  import com.liferay.portal.kernel.util.StringPool;
23  import com.liferay.portal.kernel.util.Validator;
24  
25  import java.util.Properties;
26  
27  import javax.servlet.http.HttpServletRequest;
28  
29  /**
30   * <a href="LiferayURLConstructor.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Jorge Ferrer
33   */
34  public class LiferayURLConstructor implements URLConstructor {
35  
36      public String getForwardPage(HttpServletRequest request) {
37          return "Wiki.jsp";
38      }
39  
40      public void initialize(
41          com.ecyrd.jspwiki.WikiEngine engine, Properties props) {
42      }
43  
44      public String makeURL(
45          String context, String name, boolean absolute, String parameters) {
46  
47          if (Validator.isNotNull(parameters)) {
48              if (context.equals(WikiContext.ATTACH)) {
49                  parameters = StringPool.QUESTION + parameters;
50              }
51              else if (context.equals(WikiContext.NONE)) {
52                  if (name.indexOf(CharPool.QUESTION) != -1) {
53                      parameters = "&amp;" + parameters;
54                  }
55                  else {
56                      parameters = StringPool.QUESTION + parameters;
57                  }
58              }
59              else {
60                  parameters = "&amp;" + parameters;
61              }
62          }
63          else {
64              parameters = StringPool.BLANK;
65          }
66  
67          String path;
68  
69          if (context.equals(WikiContext.EDIT)) {
70              path =
71                  "[$BEGIN_PAGE_TITLE_EDIT$]" + name + "[$END_PAGE_TITLE_EDIT$]";
72          }
73          else if (context.equals(WikiContext.VIEW)) {
74              path = "[$BEGIN_PAGE_TITLE$]" + name + "[$END_PAGE_TITLE$]";
75          }
76          else if (context.equals(WikiContext.ATTACH)) {
77              if (name.indexOf(CharPool.SLASH) == -1) {
78                  path =
79                      "[$ATTACHMENT_URL_PREFIX$][$WIKI_PAGE_NAME$]/" +
80                          HttpUtil.encodeURL(name);
81              }
82              else {
83                  path = "[$ATTACHMENT_URL_PREFIX$]" + HttpUtil.encodeURL(name);
84              }
85          }
86          else {
87              path = name;
88          }
89  
90          return path + parameters;
91      }
92  
93      public String parsePage(
94          String context, HttpServletRequest request, String encoding) {
95  
96          return "Wiki.jsp";
97      }
98  
99  }