Package spark.route
Class Routes
- java.lang.Object
-
- spark.route.Routes
-
- Direct Known Subclasses:
SimpleRouteMatcher
public class Routes extends java.lang.Object
Holds the routes and performs matching from HTTP requests to routes. Works as Sinatra's, ie. if there are more than one match the one that was mapped first is chosen.
-
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.Logger
LOG
private java.util.List<RouteEntry>
routes
private static char
SINGLE_QUOTE
-
Constructor Summary
Constructors Modifier Constructor Description protected
Routes()
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(java.lang.String route, java.lang.String acceptType, java.lang.Object target)
Deprecated.private void
add(HttpMethod method, java.lang.String url, java.lang.String acceptedType, java.lang.Object target)
void
add(HttpMethod httpMethod, FilterImpl filter)
Add a filtervoid
add(HttpMethod httpMethod, RouteImpl route)
Add a routevoid
clear()
¨Clear all routesstatic Routes
create()
RouteMatch
find(HttpMethod httpMethod, java.lang.String path, java.lang.String acceptType)
finds target for a requested routejava.util.List<RouteMatch>
findAll()
java.util.List<RouteMatch>
findMultiple(HttpMethod httpMethod, java.lang.String path, java.lang.String acceptType)
Finds multiple targets for a requested route.private java.util.List<RouteEntry>
findTargetsForRequestedRoute(HttpMethod httpMethod, java.lang.String path)
private RouteEntry
findTargetWithGivenAcceptType(java.util.List<RouteEntry> routeMatches, java.lang.String acceptType)
private java.util.Map<java.lang.String,RouteEntry>
getAcceptedMimeTypes(java.util.List<RouteEntry> routes)
boolean
remove(java.lang.String path)
Removes a particular route from the collection of those that have been previously routed.boolean
remove(java.lang.String path, java.lang.String httpMethod)
Removes a particular route from the collection of those that have been previously routed.private boolean
removeRoute(HttpMethod httpMethod, java.lang.String path)
private boolean
routeWithGivenAcceptType(java.lang.String bestMatch)
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
SINGLE_QUOTE
private static final char SINGLE_QUOTE
- See Also:
- Constant Field Values
-
routes
private java.util.List<RouteEntry> routes
-
-
Method Detail
-
create
public static Routes create()
-
add
public void add(HttpMethod httpMethod, RouteImpl route)
Add a route- Parameters:
httpMethod
- the http-method of the routeroute
- the route to add
-
add
public void add(HttpMethod httpMethod, FilterImpl filter)
Add a filter- Parameters:
httpMethod
- the http-method of the routefilter
- the filter to add
-
find
public RouteMatch find(HttpMethod httpMethod, java.lang.String path, java.lang.String acceptType)
finds target for a requested route- Parameters:
httpMethod
- the http methodpath
- the pathacceptType
- the accept type- Returns:
- the target
-
findMultiple
public java.util.List<RouteMatch> findMultiple(HttpMethod httpMethod, java.lang.String path, java.lang.String acceptType)
Finds multiple targets for a requested route.- Parameters:
httpMethod
- the http methodpath
- the route pathacceptType
- the accept type- Returns:
- the targets
-
findAll
public java.util.List<RouteMatch> findAll()
- Returns:
- the targets
-
clear
public void clear()
¨Clear all routes
-
remove
public boolean remove(java.lang.String path, java.lang.String httpMethod)
Removes a particular route from the collection of those that have been previously routed. Search for a previously established routes using the given path and HTTP method, removing any matches that are found.- Parameters:
path
- the route pathhttpMethod
- the http method- Returns:
- true if this a matching route has been previously routed
- Throws:
java.lang.IllegalArgumentException
- if path is null or blank or if httpMethod is null, blank or an invalid HTTP method- Since:
- 2.2
-
remove
public boolean remove(java.lang.String path)
Removes a particular route from the collection of those that have been previously routed. Search for a previously established routes using the given path and removes any matches that are found.- Parameters:
path
- the route path- Returns:
- true if this a matching route has been previously routed
- Throws:
java.lang.IllegalArgumentException
- if path is null or blank- Since:
- 2.2
-
add
private void add(HttpMethod method, java.lang.String url, java.lang.String acceptedType, java.lang.Object target)
-
getAcceptedMimeTypes
private java.util.Map<java.lang.String,RouteEntry> getAcceptedMimeTypes(java.util.List<RouteEntry> routes)
-
routeWithGivenAcceptType
private boolean routeWithGivenAcceptType(java.lang.String bestMatch)
-
findTargetsForRequestedRoute
private java.util.List<RouteEntry> findTargetsForRequestedRoute(HttpMethod httpMethod, java.lang.String path)
-
findTargetWithGivenAcceptType
private RouteEntry findTargetWithGivenAcceptType(java.util.List<RouteEntry> routeMatches, java.lang.String acceptType)
-
removeRoute
private boolean removeRoute(HttpMethod httpMethod, java.lang.String path)
-
add
@Deprecated public void add(java.lang.String route, java.lang.String acceptType, java.lang.Object target)
Deprecated.Parse and validates a route and adds it- Parameters:
route
- the route pathacceptType
- the accept typetarget
- the invocation target
-
-