Package org.grails.web.mapping
Class RegexUrlMapping
- java.lang.Object
-
- org.grails.web.mapping.AbstractUrlMapping
-
- org.grails.web.mapping.RegexUrlMapping
-
- All Implemented Interfaces:
UrlCreator,UrlMapping,java.lang.Comparable
public class RegexUrlMapping extends AbstractUrlMapping
A UrlMapping implementation that takes a Grails URL pattern and turns it into a regex matcher so that URLs can be matched and information captured from the match.
A Grails URL pattern is not a regex, but is an extension to the form defined by Apache Ant and used by Spring AntPathMatcher. Unlike regular Ant paths Grails URL patterns allow for capturing groups in the form:
/blog/(*)/**The parenthesis define a capturing group. This implementation transforms regular Ant paths into regular expressions that are able to use capturing groups
- Since:
- 0.5
- See Also:
AntPathMatcher
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.PatternDOUBLE_WILDCARD_PATTERNstatic java.lang.StringFORMAT_PARAMETERstatic java.util.regex.PatternOPTIONAL_EXTENSION_WILDCARD_PATTERN-
Fields inherited from class org.grails.web.mapping.AbstractUrlMapping
actionName, constraints, controllerName, forwardURI, grailsApplication, httpMethod, mappingName, namespace, parameterValues, parseRequest, pluginIndex, pluginName, redirectInfo, servletContext, version, viewName
-
Fields inherited from interface grails.web.mapping.UrlMapping
ACTION, AMPERSAND, ANY_HTTP_METHOD, ANY_VERSION, CAPTURED_DOUBLE_WILDCARD, CAPTURED_WILDCARD, CONTROLLER, DOUBLE_WILDCARD, EXCEPTION, EXCLUDES, HTTP_METHOD, INCLUDES, KEYWORDS, NAMESPACE, OPTIONAL_EXTENSION_WILDCARD, PERMANENT, PLUGIN, QUESTION_MARK, REDIRECT_INFO, RESOURCES, SLASH, URI, VERSION, VIEW, WILDCARD
-
-
Constructor Summary
Constructors Constructor Description RegexUrlMapping(UrlMappingData data, java.lang.Object controllerName, java.lang.Object actionName, java.lang.Object namespace, java.lang.Object pluginName, java.lang.Object viewName, java.lang.String httpMethod, java.lang.String version, grails.gorm.validation.ConstrainedProperty[] constraints, grails.core.GrailsApplication grailsApplication)RegexUrlMapping(UrlMappingData data, java.net.URI uri, grails.gorm.validation.ConstrainedProperty[] constraints, grails.core.GrailsApplication grailsApplication)Constructs a new RegexUrlMapping for the given pattern that maps to the specified URIRegexUrlMapping(java.lang.Object redirectInfo, UrlMappingData data, java.lang.Object controllerName, java.lang.Object actionName, java.lang.Object namespace, java.lang.Object pluginName, java.lang.Object viewName, java.lang.String httpMethod, java.lang.String version, grails.gorm.validation.ConstrainedProperty[] constraints, grails.core.GrailsApplication grailsApplication)Constructs a new RegexUrlMapping for the given pattern, controller name, action name and constraints.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(java.lang.Object o)Compares this UrlMapping instance with the specified UrlMapping instance and deals with URL mapping precedence rules.protected java.util.regex.PatternconvertToRegex(java.lang.String url)Converts a Grails URL provides via the UrlMappingData interface to a regular expression.java.lang.StringcreateRelativeURL(java.lang.String controller, java.lang.String action, java.lang.String namespace, java.lang.String pluginName, java.util.Map paramValues, java.lang.String encoding)Creates a URL for the given parameters values, controller and action names without the context path informationjava.lang.StringcreateRelativeURL(java.lang.String controller, java.lang.String action, java.lang.String namespace, java.lang.String pluginName, java.util.Map paramValues, java.lang.String encoding, java.lang.String fragment)Creates a URL for the given parameters values, controller and action names without the context path informationjava.lang.StringcreateRelativeURL(java.lang.String controller, java.lang.String action, java.lang.String pluginName, java.util.Map paramValues, java.lang.String encoding)Creates a URL for the given parameters values, controller and action names without the context path informationjava.lang.StringcreateRelativeURL(java.lang.String controller, java.lang.String action, java.util.Map paramValues, java.lang.String encoding)Creates a URL for the given parameters values, controller and action names without the context path informationjava.lang.StringcreateRelativeURL(java.lang.String controller, java.lang.String action, java.util.Map paramValues, java.lang.String encoding, java.lang.String fragment)Creates a URL for the given parameters values, controller and action names without the context path informationjava.lang.StringcreateURL(java.lang.String controller, java.lang.String action, java.lang.String namespace, java.lang.String pluginName, java.util.Map paramValues, java.lang.String encoding)Creates a URL for the given parameters values, controller and action namesjava.lang.StringcreateURL(java.lang.String controller, java.lang.String action, java.lang.String namespace, java.lang.String pluginName, java.util.Map paramValues, java.lang.String encoding, java.lang.String fragment)Creates a URL for the given parameters values, controller and action namesjava.lang.StringcreateURL(java.lang.String controller, java.lang.String action, java.lang.String pluginName, java.util.Map parameterValues, java.lang.String encoding)Creates a URL for the given parameters values, controller and action namesjava.lang.StringcreateURL(java.lang.String controller, java.lang.String action, java.util.Map paramValues, java.lang.String encoding)Creates a URL for the given parameters values, controller and action namesjava.lang.StringcreateURL(java.lang.String controller, java.lang.String action, java.util.Map paramValues, java.lang.String encoding, java.lang.String fragment)Creates a URL for the given parameters values, controller and action namesjava.lang.StringcreateURL(java.util.Map paramValues, java.lang.String encoding)Creates a URL for the given parameter valuesjava.lang.StringcreateURL(java.util.Map paramValues, java.lang.String encoding, java.lang.String fragment)Creates a URL for the given parameter valuesprotected java.lang.Stringencode(java.lang.String s, java.lang.String encoding)java.lang.String[]getLogicalMappings()UrlMappingDatagetUrlData()Retrieves the UrlMappingData instance that describes this UrlMappingUrlMappingInfomatch(java.lang.String uri)Matches the given URI and returns a DefaultUrlMappingInfo instance or nulljava.lang.StringtoString()-
Methods inherited from class org.grails.web.mapping.AbstractUrlMapping
getActionName, getConstraints, getControllerName, getHttpMethod, getMappingName, getNamespace, getPluginIndex, getPluginName, getRedirectInfo, getVersion, getViewName, hasRuntimeVariable, isDefinedInPlugin, setMappingName, setParameterValues, setParseRequest, setPluginIndex
-
-
-
-
Field Detail
-
FORMAT_PARAMETER
public static final java.lang.String FORMAT_PARAMETER
- See Also:
- Constant Field Values
-
DOUBLE_WILDCARD_PATTERN
public static final java.util.regex.Pattern DOUBLE_WILDCARD_PATTERN
-
OPTIONAL_EXTENSION_WILDCARD_PATTERN
public static final java.util.regex.Pattern OPTIONAL_EXTENSION_WILDCARD_PATTERN
-
-
Constructor Detail
-
RegexUrlMapping
public RegexUrlMapping(UrlMappingData data, java.net.URI uri, grails.gorm.validation.ConstrainedProperty[] constraints, grails.core.GrailsApplication grailsApplication)
Constructs a new RegexUrlMapping for the given pattern that maps to the specified URI- Parameters:
data- The patternuri- The URIconstraints- Any constraints etc.grailsApplication- The GrailsApplication instance
-
RegexUrlMapping
public RegexUrlMapping(UrlMappingData data, java.lang.Object controllerName, java.lang.Object actionName, java.lang.Object namespace, java.lang.Object pluginName, java.lang.Object viewName, java.lang.String httpMethod, java.lang.String version, grails.gorm.validation.ConstrainedProperty[] constraints, grails.core.GrailsApplication grailsApplication)
-
RegexUrlMapping
public RegexUrlMapping(java.lang.Object redirectInfo, UrlMappingData data, java.lang.Object controllerName, java.lang.Object actionName, java.lang.Object namespace, java.lang.Object pluginName, java.lang.Object viewName, java.lang.String httpMethod, java.lang.String version, grails.gorm.validation.ConstrainedProperty[] constraints, grails.core.GrailsApplication grailsApplication)Constructs a new RegexUrlMapping for the given pattern, controller name, action name and constraints.- Parameters:
data- An instance of the UrlMappingData class that holds necessary information of the URL mappingcontrollerName- The name of the controller the URL maps to (required)actionName- The name of the action the URL maps tonamespace- The controller namespacepluginName- The name of the plugin which provided the controllerviewName- The name of the view as an alternative to the name of the action. If the action is specified it takes precedence over the view name during mappinghttpMethod- The http methodversion- The versionconstraints- A list of ConstrainedProperty instances that relate to tokens in the URLgrailsApplication- The Grails application- See Also:
ConstrainedProperty
-
-
Method Detail
-
convertToRegex
protected java.util.regex.Pattern convertToRegex(java.lang.String url)
Converts a Grails URL provides via the UrlMappingData interface to a regular expression.- Parameters:
url- The URL to convert- Returns:
- A regex Pattern objet
-
match
public UrlMappingInfo match(java.lang.String uri)
Matches the given URI and returns a DefaultUrlMappingInfo instance or null- Parameters:
uri- The URI to match- Returns:
- A UrlMappingInfo instance or null
- See Also:
UrlMappingInfo
-
createURL
public java.lang.String createURL(java.util.Map paramValues, java.lang.String encoding)Description copied from interface:UrlCreatorCreates a URL for the given parameter values- Parameters:
paramValues- The parameter valuesencoding- The encoding to use for parameters- Returns:
- Returns the created URL for the given parameter values
- See Also:
UrlMapping
-
encode
protected java.lang.String encode(java.lang.String s, java.lang.String encoding) throws java.io.UnsupportedEncodingException- Throws:
java.io.UnsupportedEncodingException
-
createURL
public java.lang.String createURL(java.util.Map paramValues, java.lang.String encoding, java.lang.String fragment)Description copied from interface:UrlCreatorCreates a URL for the given parameter values- Parameters:
paramValues- The parameter valuesencoding- The encoding to use for parametersfragment- The URL fragment to be appended to the URL following a #- Returns:
- Returns the created URL for the given parameter values
-
createURL
public java.lang.String createURL(java.lang.String controller, java.lang.String action, java.util.Map paramValues, java.lang.String encoding)Description copied from interface:UrlCreatorCreates a URL for the given parameters values, controller and action names- Parameters:
controller- The controller nameaction- The action nameparamValues- The parameter valuesencoding- The encoding to use for parameters- Returns:
- The created URL for the given arguments
-
createURL
public java.lang.String createURL(java.lang.String controller, java.lang.String action, java.lang.String pluginName, java.util.Map parameterValues, java.lang.String encoding)Description copied from interface:UrlCreatorCreates a URL for the given parameters values, controller and action names- Parameters:
controller- The controller nameaction- The action namepluginName- The name of the plugin which provides the controllerparameterValues- The parameter valuesencoding- The encoding to use for parameters- Returns:
- The created URL for the given arguments
-
createURL
public java.lang.String createURL(java.lang.String controller, java.lang.String action, java.lang.String namespace, java.lang.String pluginName, java.util.Map paramValues, java.lang.String encoding)Description copied from interface:UrlCreatorCreates a URL for the given parameters values, controller and action names- Parameters:
controller- The controller nameaction- The action namenamespace- The controller namespacepluginName- The name of the plugin which provides the controllerparamValues- The parameter valuesencoding- The encoding to use for parameters- Returns:
- The created URL for the given arguments
-
createRelativeURL
public java.lang.String createRelativeURL(java.lang.String controller, java.lang.String action, java.util.Map paramValues, java.lang.String encoding)Description copied from interface:UrlCreatorCreates a URL for the given parameters values, controller and action names without the context path information- Parameters:
controller- The controller nameaction- The action nameparamValues- The parameter valuesencoding- The encoding to use for parameters- Returns:
- The created URL for the given arguments
-
createRelativeURL
public java.lang.String createRelativeURL(java.lang.String controller, java.lang.String action, java.lang.String pluginName, java.util.Map paramValues, java.lang.String encoding)Description copied from interface:UrlCreatorCreates a URL for the given parameters values, controller and action names without the context path information- Parameters:
controller- The controller nameaction- The action namepluginName- The name of the plugin which provides the controllerparamValues- The parameter valuesencoding- The encoding to use for parameters- Returns:
- The created URL for the given arguments
-
createRelativeURL
public java.lang.String createRelativeURL(java.lang.String controller, java.lang.String action, java.lang.String namespace, java.lang.String pluginName, java.util.Map paramValues, java.lang.String encoding)Description copied from interface:UrlCreatorCreates a URL for the given parameters values, controller and action names without the context path information- Parameters:
controller- The controller nameaction- The action namenamespace- The controller namespacepluginName- The name of the plugin which provides the controllerparamValues- The parameter valuesencoding- The encoding to use for parameters- Returns:
- The created URL for the given arguments
-
createRelativeURL
public java.lang.String createRelativeURL(java.lang.String controller, java.lang.String action, java.util.Map paramValues, java.lang.String encoding, java.lang.String fragment)Description copied from interface:UrlCreatorCreates a URL for the given parameters values, controller and action names without the context path information- Parameters:
controller- The controller nameaction- The action nameparamValues- The parameter valuesencoding- The encoding to use for parametersfragment- The fragment to append to the end- Returns:
- The created URL for the given arguments
-
createRelativeURL
public java.lang.String createRelativeURL(java.lang.String controller, java.lang.String action, java.lang.String namespace, java.lang.String pluginName, java.util.Map paramValues, java.lang.String encoding, java.lang.String fragment)Description copied from interface:UrlCreatorCreates a URL for the given parameters values, controller and action names without the context path information- Parameters:
controller- The controller nameaction- The action namenamespace- The controller namespacepluginName- The name of the plugin which provides the controllerparamValues- The parameter valuesencoding- The encoding to use for parametersfragment- The fragment to append to the end- Returns:
- The created URL for the given arguments
-
createURL
public java.lang.String createURL(java.lang.String controller, java.lang.String action, java.util.Map paramValues, java.lang.String encoding, java.lang.String fragment)Description copied from interface:UrlCreatorCreates a URL for the given parameters values, controller and action names- Parameters:
controller- The controller nameaction- The action nameparamValues- The parameter valuesencoding- The encoding to use for parametersfragment- The URL fragment to be appended to the URL following a #- Returns:
- The created URL for the given arguments
-
createURL
public java.lang.String createURL(java.lang.String controller, java.lang.String action, java.lang.String namespace, java.lang.String pluginName, java.util.Map paramValues, java.lang.String encoding, java.lang.String fragment)Description copied from interface:UrlCreatorCreates a URL for the given parameters values, controller and action names- Parameters:
controller- The controller nameaction- The action namenamespace- The controller namespacepluginName- The name of the plugin which provides the controllerparamValues- The parameter valuesencoding- The encoding to use for parametersfragment- The URL fragment to be appended to the URL following a #- Returns:
- The created URL for the given arguments
-
getUrlData
public UrlMappingData getUrlData()
Description copied from interface:UrlMappingRetrieves the UrlMappingData instance that describes this UrlMapping- Returns:
- The UrlMappingData instance
-
getLogicalMappings
public java.lang.String[] getLogicalMappings()
-
compareTo
public int compareTo(java.lang.Object o)
Compares this UrlMapping instance with the specified UrlMapping instance and deals with URL mapping precedence rules. URL Mapping Precedence Order 1. Less wildcard tokens. /foo <- match /foo/(*) /foo/(*)/bar/ <- match /foo/(*)/(*) 2. More static tokens. /foo/(*)/bar <- match /foo/(*)- Parameters:
o- An instance of the UrlMapping interface- Returns:
- greater than 0 if this UrlMapping should match before the specified UrlMapping. 0 if they are equal or less than 0 if this UrlMapping should match after the given UrlMapping
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-