public abstract class AbstractContentRegExParamBuilder extends AbstractParamBuilder
This is an abstract base class for ParamBuilder implementations that use regular expressions to extract parameters from some content. The content needs to be defined by a ParamBuilder earlier in the chain; it will be retrieved using the parameter name as specified by the contentParam property.
Regular expressions need to contain one or more group names; these group names will be mapped to parameter names. As an example, suppose the regular expression is 'abc(?<myParam>.+?)xyz'. For content containing 'abcMYVALUExyz', this ParamBuilder would add a parameter named 'myParam' with the value 'MYVALUE'.Subclasses need to return a collection of patterns by implementing the
getPatterns(Map, HttpServletRequest)
method. They can optionally
override the getGroupNames(Pattern)
method, for example
if they have already determined the group names.
Modifier and Type | Field and Description |
---|---|
protected String |
contentParam |
Constructor and Description |
---|
AbstractContentRegExParamBuilder() |
Modifier and Type | Method and Description |
---|---|
protected void |
addRegExValues(String content,
Map<String,String> params,
Pattern pattern)
Match the given pattern against the given content, and add all matches to the
given parameters map.
|
void |
buildParams(Map<String,String> params,
javax.servlet.http.HttpServletRequest request)
Build the parameters.
|
String |
getContentParam()
Get the parameter name from which content will be retrieved.
|
protected Set<String> |
getGroupNames(Pattern pattern)
Get the group names for the given pattern.
|
protected abstract Collection<Pattern> |
getPatterns(Map<String,String> params,
javax.servlet.http.HttpServletRequest request)
Implementing classes must implement this method to return a collection
of regular expressions to be used to match against the content.
|
void |
setContentParam(String contentParam)
Set the parameter name from which content will be retrieved.
|
afterPropertiesSet, compareTo, extraAfterPropertiesSet, getOrder, setOrder
getBeanName, setBeanName
protected String contentParam
public void buildParams(Map<String,String> params, javax.servlet.http.HttpServletRequest request)
getPatterns(Map, HttpServletRequest)
method, match those patterns
with the content specified by contentParam, and add all matched groups to
the parameters map.params
- The parameters map to which parameters can be added or existing parameters can be retrieved.request
- The original request, useful to retrieve request parameters for example.public String getContentParam()
public void setContentParam(String contentParam)
contentParam
- protected void addRegExValues(String content, Map<String,String> params, Pattern pattern)
content
- params
- pattern
- protected Set<String> getGroupNames(Pattern pattern)
pattern
- protected abstract Collection<Pattern> getPatterns(Map<String,String> params, javax.servlet.http.HttpServletRequest request)
getGroupNames(Pattern)
),
or dynamically determine the regular expressions to use based on the
given parameter map and/or request.params
- request
- Copyright © 2013. All rights reserved.