01: /*
02: JSPWiki - a JSP-based WikiWiki clone.
03:
04: Copyright (C) 2001-2005 Janne Jalkanen (Janne.Jalkanen@iki.fi)
05:
06: This program is free software; you can redistribute it and/or modify
07: it under the terms of the GNU Lesser General Public License as published by
08: the Free Software Foundation; either version 2.1 of the License, or
09: (at your option) any later version.
10:
11: This program is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU Lesser General Public License for more details.
15:
16: You should have received a copy of the GNU Lesser General Public License
17: along with this program; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package com.ecyrd.jspwiki.url;
21:
22: import java.util.Properties;
23:
24: import javax.servlet.http.HttpServletRequest;
25:
26: import com.ecyrd.jspwiki.WikiContext;
27: import com.ecyrd.jspwiki.WikiEngine;
28:
29: /**
30: * A specific URL constructor that returns easy-to-grok URLs for
31: * VIEW and ATTACH contexts, but goes through JSP pages otherwise.
32: *
33: * @author jalkanen
34: *
35: * @since 2.2
36: */
37: public class ShortViewURLConstructor extends ShortURLConstructor {
38: /**
39: * {@inheritDoc}
40: */
41: public void initialize(WikiEngine engine, Properties properties) {
42: super .initialize(engine, properties);
43: }
44:
45: private String makeURL(String context, String name, boolean absolute) {
46: String viewurl = "%p" + m_urlPrefix + "%n";
47:
48: if (absolute)
49: viewurl = "%u" + m_urlPrefix + "%n";
50:
51: if (context.equals(WikiContext.VIEW)) {
52: if (name == null)
53: return doReplacement("%u", "", absolute);
54: return doReplacement(viewurl, name, absolute);
55: }
56:
57: return doReplacement(DefaultURLConstructor.getURLPattern(
58: context, name), name, absolute);
59: }
60:
61: /**
62: * {@inheritDoc}
63: */
64: public String makeURL(String context, String name,
65: boolean absolute, String parameters) {
66: if (parameters != null && parameters.length() > 0) {
67: if (context.equals(WikiContext.ATTACH)
68: || context.equals(WikiContext.VIEW) || name == null) {
69: parameters = "?" + parameters;
70: } else if (context.equals(WikiContext.NONE)) {
71: parameters = (name.indexOf('?') != -1) ? "&" : "?"
72: + parameters;
73: } else {
74: parameters = "&" + parameters;
75: }
76: } else {
77: parameters = "";
78: }
79: return makeURL(context, name, absolute) + parameters;
80: }
81:
82: /**
83: * Since we're only called from WikiServlet, where we get the VIEW requests,
84: * we can safely return this.
85: *
86: * @param {@inheritDoc}
87: * @return {@inheritDoc}
88: */
89: public String getForwardPage(HttpServletRequest req) {
90: return "Wiki.jsp";
91: }
92: }
|