public abstract class BaseRouter<Controller extends BaseController> extends Object
Contains basic support for url generation and recognition.
| Modifier and Type | Class and Description |
|---|---|
class |
BaseRouter.Handler
Handler for routes.
|
protected class |
BaseRouter.Route
Structure containing regular expression and handler for the route.
|
| Modifier and Type | Field and Description |
|---|---|
protected Globals |
globals |
protected List<BaseRouter.Route> |
routes |
protected boolean |
useAbsoluteUrl |
| Modifier | Constructor and Description |
|---|---|
|
BaseRouter(Globals globals) |
protected |
BaseRouter(Globals globals,
List<BaseRouter.Route> routes,
boolean useAbsoluteUrl)
Needed to support legacy API.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRoute(String route,
BaseRouter.Handler handler)
Add route and its handler.
|
static String |
buildUrl(String path)
Shortcut for `buildUrl(path, params)`.
|
static String |
buildUrl(String path,
Map<String,String> params)
Build url from patch and params.
|
protected void |
callHandler(BaseRouter.Handler handler,
Controller controller,
Request request,
Response response,
String... args) |
boolean |
canDispatch(String path)
Deprecated.
since 3.3.2
|
protected abstract Controller |
createController(Globals globals,
Request request,
Response response)
Override this method and provide instance of the controller.
|
void |
dispatch(Request request,
Response response)
Dispatches request to proper handlers.
|
static String |
interpolate(String string,
String... args)
Same as `String.interpolate` but allows to use named parts to improve readability, like
`interpolate("/posts/:id", id)`.
|
protected boolean |
isUrlTooLong(String url)
Protecting from too long urls, it may consume a lot of CPU to regex it,
see https://ecosystem.atlassian.net/browse/PLUGWEB-316.
|
static String |
joinWithSlashWithoutEmpty(String... parts)
Builds path by joining strings with slashes, skips strings that are null.
|
static List<String> |
parseWithRe(String string,
String re)
Parses string with regular expressions and returns list of results.
|
static Pattern |
routeToRe(String route)
Convert string expression of the route like `/posts/:id/show` into the regular expression pattern, it uses
Backbone.js rules for route expression.
|
protected final Globals globals
protected final List<BaseRouter.Route> routes
protected final boolean useAbsoluteUrl
public BaseRouter(Globals globals)
protected BaseRouter(Globals globals, List<BaseRouter.Route> routes, boolean useAbsoluteUrl)
protected abstract Controller createController(Globals globals, Request request, Response response)
public void addRoute(String route, BaseRouter.Handler handler)
route - use same rules as in Backbone.js to define the route.@Deprecated public boolean canDispatch(String path)
public void dispatch(Request request, Response response)
protected boolean isUrlTooLong(String url)
protected void callHandler(BaseRouter.Handler handler, Controller controller, Request request, Response response, String... args)
public static String buildUrl(String path, Map<String,String> params)
public static List<String> parseWithRe(String string, String re)
public static Pattern routeToRe(String route)
public static String interpolate(String string, String... args)
Copyright © 2018 Atlassian. All rights reserved.