org.inria.ns.reflex.modules.web
Class MappingAction

java.lang.Object
  extended by org.inria.ns.reflex.processor.core.AbstractAction
      extended by org.inria.ns.reflex.modules.web.MappingAction
All Implemented Interfaces:
Executable, Presentable, NamespaceContextFactory

public class MappingAction
extends AbstractAction

The <web:mapping> element defines mapping between URLs and procedures.

A mapping matches an HTTP request if matchesHTTPMethod(HttpServletRequest) return true AND getMatcher(HttpServletRequest, DataSet) return null or a matcher that matched.

Author:
Philippe Poulard
See Also:
Matcher.matches()

Nested Class Summary
 
Nested classes/interfaces inherited from class org.inria.ns.reflex.processor.core.AbstractAction
AbstractAction.ParameterAdapter, AbstractAction.UselessAction
 
Field Summary
 
Fields inherited from class org.inria.ns.reflex.processor.core.AbstractAction
actions, parent, processorInstance
 
Constructor Summary
MappingAction(Pattern matchPattern, Expression use, String[] methods, Node node, AbstractAction parent)
          Creates a new instance of MappingAction.
 
Method Summary
 Matcher getMatcher(HttpServletRequest request, DataSet dataSet)
          Return the matcher for the request's URL on this mapping.
 boolean matchesHTTPMethod(HttpServletRequest request)
          Indicates whether this mapping matches the HTTP method or not.
 void setMIMEType(ServletContext context, HttpServletRequest request, HttpServletResponse response)
          Set the MIME type of the HTTP response according to the extension of the request's URL.
static AbstractAction unmarshal(AbstractAction parent, Element element)
          XML unmarshaller for MappingAction.
 
Methods inherited from class org.inria.ns.reflex.processor.core.AbstractAction
addAction, addFallbackAction, createContext, getCanonicalPath, getFallbackAction, getLocalFallbackAction, getLogger, getNamespaceContext, getNode, getParent, recover, recover, removeFallbackAction, reorganize, run, runAction, runActions, toPrettyString, toPrettyString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MappingAction

public MappingAction(Pattern matchPattern,
                     Expression use,
                     String[] methods,
                     Node node,
                     AbstractAction parent)
Creates a new instance of MappingAction.

Parameters:
matchPattern - The pattern used to test if an URL matches. null = matches any.
use - The URL material to use for matching.
methods - The list of HTTP methods to match. null = matches any.
node - The node from which the action has been unmarshalled. Used for namespace prefix resolution when performing XPath expressions.
parent - The action depending from.
Method Detail

unmarshal

public static AbstractAction unmarshal(AbstractAction parent,
                                       Element element)
                                throws XMLException
XML unmarshaller for MappingAction.

Parameters:
parent - The action depending from
element - The XML element to unmarshall.
Returns:
The MappingAction created.
Throws:
XMLException - When the element and its content is not those expected.

getMatcher

public Matcher getMatcher(HttpServletRequest request,
                          DataSet dataSet)
                   throws XPathException
Return the matcher for the request's URL on this mapping.

Notice that according to the mapping definition, the material specified in the @use attribute will be used for matching instead of the URL, if this attribute is present.

Note : the default URL starts after the application path, and begin with a "/".

Parameters:
request - The HTTP request.
dataSet - The data set to use to compute the material to use for matching.
Returns:
The matcher used to match request's URL, or null if this mapping matches any URL.
Throws:
XPathException - If the material to match can't be evaluated.

matchesHTTPMethod

public boolean matchesHTTPMethod(HttpServletRequest request)
Indicates whether this mapping matches the HTTP method or not.

Parameters:
request - The HTTP request.
Returns:
true if this mapping matches the HTTP request, false otherwise.

setMIMEType

public void setMIMEType(ServletContext context,
                        HttpServletRequest request,
                        HttpServletResponse response)
Set the MIME type of the HTTP response according to the extension of the request's URL. This default implementation does nothing.

Parameters:
context - The context.
request - The HTTP request.
response - The HTTP response.