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  import com.liferay.portlet.wiki.util.WikiUtil;
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          String decodedName = HttpUtil.encodeURL(
48              WikiUtil.decodeJSPWikiName(name));
49  
50          if (Validator.isNotNull(parameters)) {
51              if (context.equals(WikiContext.ATTACH)) {
52                  parameters = StringPool.QUESTION + parameters;
53              }
54              else if (context.equals(WikiContext.NONE)) {
55                  if (decodedName.indexOf(StringPool.QUESTION) != -1) {
56                      parameters = "&amp;" + parameters;
57                  }
58                  else {
59                      parameters = StringPool.QUESTION + parameters;
60                  }
61              }
62              else {
63                  parameters = "&amp;" + parameters;
64              }
65          }
66          else {
67              parameters = StringPool.BLANK;
68          }
69  
70          String path;
71  
72          if (context.equals(WikiContext.EDIT)) {
73              path =
74                  "[$BEGIN_PAGE_TITLE_EDIT$]" + decodedName +
75                      "[$END_PAGE_TITLE_EDIT$]";
76          }
77          else if (context.equals(WikiContext.VIEW)) {
78              path = "[$BEGIN_PAGE_TITLE$]" + decodedName + "[$END_PAGE_TITLE$]";
79          }
80          else if (context.equals(WikiContext.ATTACH)) {
81              if (decodedName.indexOf(StringPool.SLASH) == -1) {
82                  path =
83                      "[$ATTACHMENT_URL_PREFIX$][$WIKI_PAGE_NAME$]/" +
84                          decodedName;
85              }
86              else {
87                  path = "[$ATTACHMENT_URL_PREFIX$]" + decodedName;
88              }
89          }
90          else {
91              path = decodedName;
92          }
93  
94          return path + parameters;
95      }
96  
97      public String parsePage(
98          String context, HttpServletRequest request, String encoding) {
99  
100         return "Wiki.jsp";
101     }
102 
103 }