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   */
42  public class LiferayURLConstructor implements URLConstructor {
43  
44      public String getForwardPage(HttpServletRequest request) {
45          return "Wiki.jsp";
46      }
47  
48      public void initialize(
49          com.ecyrd.jspwiki.WikiEngine engine, Properties props) {
50      }
51  
52      public String makeURL(
53          String context, String name, boolean absolute, String parameters) {
54  
55          if (Validator.isNotNull(parameters)) {
56              if (context.equals(WikiContext.ATTACH)) {
57                  parameters = StringPool.QUESTION + parameters;
58              }
59              else if (context.equals(WikiContext.NONE)) {
60                  if (name.indexOf(StringPool.QUESTION) != -1) {
61                      parameters = "&amp;" + parameters;
62                  }
63                  else {
64                      parameters = StringPool.QUESTION + parameters;
65                  }
66              }
67              else {
68                  parameters = "&amp;" + parameters;
69              }
70          }
71          else {
72              parameters = StringPool.BLANK;
73          }
74  
75          String path;
76  
77          if (context.equals(WikiContext.EDIT)) {
78              path =
79                  "[$BEGIN_PAGE_TITLE_EDIT$]" + name + "[$END_PAGE_TITLE_EDIT$]";
80          }
81          else if (context.equals(WikiContext.VIEW)) {
82              path = "[$BEGIN_PAGE_TITLE$]" + name + "[$END_PAGE_TITLE$]";
83          }
84          else if (context.equals(WikiContext.ATTACH)) {
85              if (name.indexOf(StringPool.SLASH) == -1) {
86                  path =
87                      "[$ATTACHMENT_URL_PREFIX$][$WIKI_PAGE_NAME$]/" +
88                          HttpUtil.encodeURL(name);
89              }
90              else {
91                  path = "[$ATTACHMENT_URL_PREFIX$]" + HttpUtil.encodeURL(name);
92              }
93          }
94          else {
95              path = name;
96          }
97  
98          return path + parameters;
99      }
100 
101     public String parsePage(
102         String context, HttpServletRequest request, String encoding) {
103 
104         return "Wiki.jsp";
105     }
106 
107 }