Class ViewPattern
- java.lang.Object
-
- org.shredzone.commons.view.manager.ViewPattern
-
- All Implemented Interfaces:
Comparable<ViewPattern>
@ParametersAreNonnullByDefault @Immutable public class ViewPattern extends Object implements Comparable<ViewPattern>
A view pattern is a URL pattern for a view. It is used to detect which view is used for handling a HTTP request, and what parameters are used.ViewPatternsare immutable.- Author:
- Richard "Shred" Körber
-
-
Constructor Summary
Constructors Constructor Description ViewPattern(View anno, ViewInvoker invoker)Instantiates a new view pattern.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(ViewPattern o)booleanequals(Object obj)Stringevaluate(org.springframework.expression.EvaluationContext context, PathContext data)Evaluates the givenEvaluationContextand builds an URL to the appropriate view.List<org.springframework.expression.Expression>getExpression()Returns anExpressionfor each placeholder in the pattern.ViewInvokergetInvoker()Gets theViewInvokerto be used for rendering.List<String>getParameters()Returns a list of parameter strings for each placeholder in the pattern.StringgetPattern()Gets the view's URL pattern.StringgetQualifier()Returns the qualifier of this pattern.PatterngetRegEx()Gets a regular expressionPatternto match a URL against thisViewPattern.SignaturegetSignature()Gets the signature stored in thisViewPattern.intgetWeight()Gets the weight of thisViewPattern.inthashCode()booleanmatches(String path)Matches the requested URL against thisViewPattern.Map<String,String>resolve(String path)Resolves a requested URL path.
-
-
-
Constructor Detail
-
ViewPattern
public ViewPattern(View anno, ViewInvoker invoker)
Instantiates a new view pattern.- Parameters:
anno-Viewannotationinvoker-ViewInvokerfor rendering this view
-
-
Method Detail
-
getSignature
public Signature getSignature()
Gets the signature stored in thisViewPattern.- Returns:
Signature
-
getInvoker
public ViewInvoker getInvoker()
Gets theViewInvokerto be used for rendering.- Returns:
ViewInvoker
-
getWeight
public int getWeight()
Gets the weight of thisViewPattern. If more than oneViewPatternmatches the requested URL, the one with the highest weight is taken.- Returns:
- weight
-
getPattern
public String getPattern()
Gets the view's URL pattern.- Returns:
- URL pattern
-
getRegEx
@Nonnull public Pattern getRegEx()
Gets a regular expressionPatternto match a URL against thisViewPattern. This regular expression can be used to quickly find view candidates for a request URL.- Returns:
- regular expression
Pattern.
-
getExpression
@Nonnull public List<org.springframework.expression.Expression> getExpression()
Returns anExpressionfor each placeholder in the pattern. The expressions are used for building an URL to this view.- Returns:
- List of
Expression
-
getParameters
@Nonnull public List<String> getParameters()
Returns a list of parameter strings for each placeholder in the pattern.- Returns:
- List of parameters
-
getQualifier
public String getQualifier()
Returns the qualifier of this pattern.- Returns:
- Qualifier of this pattern, or
nullfor the default qualifier.
-
matches
public boolean matches(String path)
Matches the requested URL against thisViewPattern.- Parameters:
path- the requested URL- Returns:
trueif thisViewPatternmatches the given URL, and thus is a candidate for rendering
-
resolve
public Map<String,String> resolve(String path)
Resolves a requested URL path. For each placeholder in the view pattern, the placeholder name and its value in the URL path is returned in a map.- Parameters:
path- the requested URL to be resolved- Returns:
- Map containing the placeholder names and its values
-
evaluate
public String evaluate(org.springframework.expression.EvaluationContext context, PathContext data)
Evaluates the givenEvaluationContextand builds an URL to the appropriate view.- Parameters:
context-EvaluationContextto be useddata-PathContextcontaining all data required for building the URL- Returns:
- URL that was built, or
nullif thePathContextdid not contain all necessary data for building the URL
-
compareTo
public int compareTo(ViewPattern o)
- Specified by:
compareToin interfaceComparable<ViewPattern>
-
-