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.ViewPatterns
are 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 int
compareTo(ViewPattern o)
boolean
equals(Object obj)
String
evaluate(org.springframework.expression.EvaluationContext context, PathContext data)
Evaluates the givenEvaluationContext
and builds an URL to the appropriate view.List<org.springframework.expression.Expression>
getExpression()
Returns anExpression
for each placeholder in the pattern.ViewInvoker
getInvoker()
Gets theViewInvoker
to be used for rendering.List<String>
getParameters()
Returns a list of parameter strings for each placeholder in the pattern.String
getPattern()
Gets the view's URL pattern.String
getQualifier()
Returns the qualifier of this pattern.Pattern
getRegEx()
Gets a regular expressionPattern
to match a URL against thisViewPattern
.Signature
getSignature()
Gets the signature stored in thisViewPattern
.int
getWeight()
Gets the weight of thisViewPattern
.int
hashCode()
boolean
matches(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
-View
annotationinvoker
-ViewInvoker
for rendering this view
-
-
Method Detail
-
getSignature
public Signature getSignature()
Gets the signature stored in thisViewPattern
.- Returns:
Signature
-
getInvoker
public ViewInvoker getInvoker()
Gets theViewInvoker
to be used for rendering.- Returns:
ViewInvoker
-
getWeight
public int getWeight()
Gets the weight of thisViewPattern
. If more than oneViewPattern
matches 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 expressionPattern
to 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 anExpression
for 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
null
for the default qualifier.
-
matches
public boolean matches(String path)
Matches the requested URL against thisViewPattern
.- Parameters:
path
- the requested URL- Returns:
true
if thisViewPattern
matches 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 givenEvaluationContext
and builds an URL to the appropriate view.- Parameters:
context
-EvaluationContext
to be useddata
-PathContext
containing all data required for building the URL- Returns:
- URL that was built, or
null
if thePathContext
did not contain all necessary data for building the URL
-
compareTo
public int compareTo(ViewPattern o)
- Specified by:
compareTo
in interfaceComparable<ViewPattern>
-
-