org.apache.wiki.url
Class DefaultURLConstructor

java.lang.Object
  extended by org.apache.wiki.url.DefaultURLConstructor
All Implemented Interfaces:
URLConstructor
Direct Known Subclasses:
ShortURLConstructor

public class DefaultURLConstructor
extends Object
implements URLConstructor

Implements the default URL constructor using links directly to the JSP pages. This is what JSPWiki by default is using. For example, WikiContext.VIEW points at "Wiki.jsp", etc.

Since:
2.2

Field Summary
protected  WikiEngine m_engine
           
protected  String m_pathPrefix
          Contains the absolute path of the JSPWiki Web application without the actual servlet (which is the m_urlPrefix).
 
Constructor Summary
DefaultURLConstructor()
           
 
Method Summary
protected  String doReplacement(String baseptrn, String name, boolean absolute)
          Does replacement of some particular variables.
 String getForwardPage(javax.servlet.http.HttpServletRequest request)
          This method is not needed for the DefaultURLConstructor.
static String getURLPattern(String context, String name)
          Returns the URL pattern for a supplied wiki request context.
 void initialize(WikiEngine engine, Properties properties)
          Initializes.
 String makeURL(String context, String name, boolean absolute, String parameters)
          Constructs the URL with a bunch of parameters.
 String parsePage(String context, javax.servlet.http.HttpServletRequest request, String encoding)
          Should parse the "page" parameter from the actual request.
static String parsePageFromURL(javax.servlet.http.HttpServletRequest request, String encoding)
          Takes the name of the page from the request URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_engine

protected WikiEngine m_engine

m_pathPrefix

protected String m_pathPrefix
Contains the absolute path of the JSPWiki Web application without the actual servlet (which is the m_urlPrefix).

Constructor Detail

DefaultURLConstructor

public DefaultURLConstructor()
Method Detail

initialize

public void initialize(WikiEngine engine,
                       Properties properties)
Initializes. Note that the engine is not fully initialized at this point, so don't do anything fancy here - use lazy init, if you have to.

Specified by:
initialize in interface URLConstructor
Parameters:
engine - The WikiEngine that this URLConstructor belongs to
properties - Properties used to initialize

doReplacement

protected final String doReplacement(String baseptrn,
                                     String name,
                                     boolean absolute)
Does replacement of some particular variables. The variables are:

Parameters:
baseptrn - The pattern to use
name - The page name
absolute - If true, %u is always the entire base URL, otherwise it depends on the setting in jspwiki.properties.
Returns:
A replacement.

getURLPattern

public static String getURLPattern(String context,
                                   String name)
                            throws IllegalArgumentException
Returns the URL pattern for a supplied wiki request context.

Parameters:
context - the wiki context
name - the wiki page
Returns:
A pattern for replacement.
Throws:
IllegalArgumentException - if the context cannot be found

makeURL

public String makeURL(String context,
                      String name,
                      boolean absolute,
                      String parameters)
Constructs the URL with a bunch of parameters.

Specified by:
makeURL in interface URLConstructor
Parameters:
parameters - If null or empty, no parameters are added. An URL parameter string (these must be URL-encoded, and separated with &)
context - The request context (@see WikiContext) that you want the URL for
name - The page name (or in case of WikiContext.NONE, the auxiliary JSP page or resource you want to point at. This must be URL encoded. Null is NOT safe.
absolute - True, if you need an absolute URL. False, if both relative and absolute URLs are fine.
Returns:
An URL pointing to the resource. Must never return null - throw an InternalWikiException if something goes wrong.

parsePage

public String parsePage(String context,
                        javax.servlet.http.HttpServletRequest request,
                        String encoding)
                 throws UnsupportedEncodingException
Should parse the "page" parameter from the actual request. Should parse the "page" parameter from the actual request. This is essentially the reverse of makeURL() - whenever a request constructed by calls to makeURL() is passed to this routine, it MUST be able to parse the resource name (WikiPage, Attachment, other resource) from the request.

Specified by:
parsePage in interface URLConstructor
Parameters:
context - In which request context the request was made (this should help in parsing)
request - The HTTP request that was used when coming here
encoding - The encoding with which the request was made (UTF-8 or ISO-8859-1).
Returns:
This method must return the name of the resource.
Throws:
UnsupportedEncodingException

parsePageFromURL

public static String parsePageFromURL(javax.servlet.http.HttpServletRequest request,
                                      String encoding)
                               throws UnsupportedEncodingException
Takes the name of the page from the request URI. The initial slash is also removed. If there is no page, returns null.

Parameters:
request - The request to parse
encoding - The encoding to use
Returns:
a parsed page name, or null, if it cannot be found
Throws:
UnsupportedEncodingException - If the encoding is not recognized.

getForwardPage

public String getForwardPage(javax.servlet.http.HttpServletRequest request)
This method is not needed for the DefaultURLConstructor.

Specified by:
getForwardPage in interface URLConstructor
Parameters:
request - The HTTP Request that was used to end up in this page.
Returns:
"Wiki.jsp", "PageInfo.jsp", etc. Just return the name, JSPWiki will figure out the page.


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.