Class DefaultCommandResolver
- java.lang.Object
-
- org.apache.wiki.ui.DefaultCommandResolver
-
- All Implemented Interfaces:
CommandResolver
public class DefaultCommandResolver extends java.lang.Object implements CommandResolver
Default implementation for
CommandResolver
- Since:
- 2.4.22
-
-
Field Summary
-
Fields inherited from interface org.apache.wiki.ui.CommandResolver
PROP_SPECIALPAGE
-
-
Constructor Summary
Constructors Constructor Description DefaultCommandResolver(Engine engine, java.util.Properties properties)
Constructs a CommandResolver for a given Engine.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Command
extractCommandFromPath(javax.servlet.http.HttpServletRequest request)
Extracts a Command based on the JSP path of an HTTP request.java.lang.String
extractPageFromParameter(java.lang.String requestContext, javax.servlet.http.HttpServletRequest request)
Determines the correct wiki page based on a supplied request context and HTTP request.Command
findCommand(javax.servlet.http.HttpServletRequest request, java.lang.String defaultContext)
Attempts to locate a Command for a supplied wiki context and HTTP request, incorporating the correct WikiPage into the command if required.java.lang.String
getFinalPageName(java.lang.String page)
Returns the correct page name, ornull
, if no such page can be found.java.lang.String
getSpecialPageReference(java.lang.String page)
If the page is a special page, this method returns a direct URL to that page; otherwise, it returnsnull
.Page
resolvePage(javax.servlet.http.HttpServletRequest request, java.lang.String page)
Looks up and returns the correct, versioned WikiPage based on a supplied page name and optionalversion
parameter passed in an HTTP request.protected boolean
simplePageExists(java.lang.String page)
Determines whether a "page" exists by examining the list of special pages and querying the page manager.
-
-
-
Constructor Detail
-
DefaultCommandResolver
public DefaultCommandResolver(Engine engine, java.util.Properties properties)
Constructs a CommandResolver for a given Engine. This constructor will extract the special page references for this wiki and store them in a cache used for resolution.- Parameters:
engine
- the wiki engineproperties
- the properties used to initialize the wiki
-
-
Method Detail
-
findCommand
public Command findCommand(javax.servlet.http.HttpServletRequest request, java.lang.String defaultContext)
Attempts to locate a Command for a supplied wiki context and HTTP request, incorporating the correct WikiPage into the command if required. This method will first determine what page the user requested by delegating to
CommandResolver.extractPageFromParameter(String, HttpServletRequest)
. If this page equates to a special page, we return the Command corresponding to that page. Otherwise, this method simply returns the Command for the supplied request context.The reason this method attempts to resolve against special pages is because some of them resolve to contexts that may be different from the one supplied. For example, a VIEW request context for the special page "UserPreferences" should return a PREFS context instead.
When the caller supplies a request context and HTTP request that specifies an actual wiki page (rather than a special page), this method will return a "targeted" Command that includes the resolved WikiPage as the target. (See
CommandResolver.resolvePage(HttpServletRequest, String)
for the resolution algorithm). Specifically, the Command will return a non-null
value for itsAbstractCommand.getTarget()
method.Note: if this method determines that the Command is the VIEW PageCommand, then the Command returned will always be targeted to the front page.
- Specified by:
findCommand
in interfaceCommandResolver
- Parameters:
request
- the HTTP request; ifnull
, delegates toCommandResolver.findCommand(String)
defaultContext
- the request context to use by default- Returns:
- the resolved wiki command
-
getFinalPageName
public java.lang.String getFinalPageName(java.lang.String page) throws ProviderException
Returns the correct page name, or
null
, if no such page can be found. Aliases are considered.In some cases, page names can refer to other pages. For example, when you have matchEnglishPlurals set, then a page name "Foobars" will be transformed into "Foobar", should a page "Foobars" not exist, but the page "Foobar" would. This method gives you the correct page name to refer to.
This facility can also be used to rewrite any page name, for example, by using aliases. It can also be used to check the existence of any page.
- Specified by:
getFinalPageName
in interfaceCommandResolver
- Parameters:
page
- the page name.- Returns:
- The rewritten page name, or
null
, if the page does not exist. - Throws:
ProviderException
- if the underlyng page provider that locates pages throws an exception
-
getSpecialPageReference
public java.lang.String getSpecialPageReference(java.lang.String page)
If the page is a special page, this method returns a direct URL to that page; otherwise, it returns
null
.Special pages are non-existant references to other pages. For example, you could define a special page reference "RecentChanges" which would always be redirected to "RecentChanges.jsp" instead of trying to find a Wiki page called "RecentChanges".
- Specified by:
getSpecialPageReference
in interfaceCommandResolver
- Parameters:
page
- the page name ro search for- Returns:
- the URL of the special page, if the supplied page is one, or
null
-
extractCommandFromPath
protected Command extractCommandFromPath(javax.servlet.http.HttpServletRequest request)
Extracts a Command based on the JSP path of an HTTP request. If the JSP requested matches a Command'sgetJSP()
value, that Command is returned.- Parameters:
request
- the HTTP request- Returns:
- the resolved Command, or
null
if not found
-
extractPageFromParameter
public java.lang.String extractPageFromParameter(java.lang.String requestContext, javax.servlet.http.HttpServletRequest request)
Determines the correct wiki page based on a supplied request context and HTTP request. This method attempts to determine the page requested by a user, taking into acccount special pages. The resolution algorithm will:- Extract the page name from the URL according to the rules for the current
URLConstructor
. If a page name was passed in the request, return the correct name after taking into account potential plural matches. - If the extracted page name is
null
, attempt to see if a "special page" was intended by examining the servlet path. For example, the request path "/UserPreferences.jsp" will resolve to "UserPreferences." - If neither of these methods work, this method returns
null
- Specified by:
extractPageFromParameter
in interfaceCommandResolver
- Parameters:
requestContext
- the request contextrequest
- the HTTP request- Returns:
- the resolved page name
- Extract the page name from the URL according to the rules for the current
-
resolvePage
public Page resolvePage(javax.servlet.http.HttpServletRequest request, java.lang.String page)
Looks up and returns the correct, versioned WikiPage based on a supplied page name and optionalversion
parameter passed in an HTTP request. If theversion
parameter does not exist in the request, the latest version is returned.- Specified by:
resolvePage
in interfaceCommandResolver
- Parameters:
request
- the HTTP requestpage
- the name of the page to look up; this page must exist- Returns:
- the wiki page
-
simplePageExists
protected boolean simplePageExists(java.lang.String page) throws ProviderException
Determines whether a "page" exists by examining the list of special pages and querying the page manager.- Parameters:
page
- the page to seek- Returns:
true
if the page exists,false
otherwise- Throws:
ProviderException
- if the underlyng page provider that locates pages throws an exception
-
-