Package org.apache.wiki.url

# Class DefaultURLConstructor

java.lang.Object
org.apache.wiki.url.DefaultURLConstructor

All Implemented Interfaces:
  `org.apache.wiki.api.engine.Initializable`, `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

Fields
Modifier and Type
Field
Description
`protected org.apache.wiki.api.core.Engine`
`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

Constructors
Constructor
Description
`DefaultURLConstructor()`

## Method Summary

Modifier and Type
Method
Description
`protected final String`
`doReplacement(String baseptrn, String name)`
Does replacement of some particular variables.
`String`
`getForwardPage(jakarta.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(org.apache.wiki.api.core.Engine engine, Properties properties)`
`String`
`makeURL(String context, String name, String parameters)`
Constructs the URL with a bunch of parameters.
`String`
`parsePage(String context, jakarta.servlet.http.HttpServletRequest request, Charset encoding)`
Should parse the "page" parameter from the actual request.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### m_engine

protected org.apache.wiki.api.core.Engine 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 Details

### DefaultURLConstructor

public DefaultURLConstructor()

## Method Details

### initialize

public void initialize(org.apache.wiki.api.core.Engine engine, Properties properties)

Specified by:
  `initialize` in interface `org.apache.wiki.api.engine.Initializable`

### doReplacement

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

- "%u" - inserts either the base URL (when absolute is required), or the base path (which is an absolute path without the host name).
- "%U" - always inserts the base URL
- "%p" - always inserts the base path
- "%n" - inserts the page name

Parameters:
  `baseptrn` - The pattern to use
  `name` - The page name
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, 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 &amp;)
  `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.
Returns:
  An URL pointing to the resource. Must never return null - throw an InternalWikiException if something goes wrong.

### parsePage

public String parsePage(String context, jakarta.servlet.http.HttpServletRequest request, Charset encoding)
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.

### getForwardPage

public String getForwardPage(jakarta.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.