Class BaseRouter<Controller extends BaseController>
java.lang.Object
com.atlassian.plugin.webresource.impl.support.http.BaseRouter<Controller>
- Direct Known Subclasses:
Router
Generates urls and route requests to proper handlers.
Contains basic support for url generation and recognition.
- Since:
- 3.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassHandler for routes.protected classStructure containing regular expression and handler for the route. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Globalsprotected final List<BaseRouter<Controller>.Route>protected final boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionBaseRouter(Globals globals) protectedBaseRouter(Globals globals, List<BaseRouter<Controller>.Route> routes, boolean useAbsoluteUrl) Needed to support legacy API. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRoute(String route, BaseRouter<Controller>.Handler handler) Add route and its handler.static StringShortcut for `buildUrl(path, params)`.static StringBuild url from patch and params.protected voidcallHandler(BaseRouter<Controller>.Handler handler, Controller controller, Request request, Response response, String... args) booleancanDispatch(String path) Deprecated.since 3.3.2protected abstract ControllercreateController(Globals globals, Request request, Response response) Override this method and provide instance of the controller.voidDispatches request to proper handlers.static Stringinterpolate(String string, String... args) Same as `String.interpolate` but allows to use named parts to improve readability, like `interpolate("/posts/:id", id)`.protected booleanisUrlTooLong(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 StringjoinWithSlashWithoutEmpty(String... parts) Builds path by joining strings with slashes, skips strings that are null.parseWithRe(String string, String re) Parses string with regular expressions and returns list of results.static PatternConvert string expression of the route like `/posts/:id/show` into the regular expression pattern, it uses Backbone.js rules for route expression.
-
Field Details
-
globals
-
routes
-
useAbsoluteUrl
protected final boolean useAbsoluteUrl
-
-
Constructor Details
-
BaseRouter
-
BaseRouter
protected BaseRouter(Globals globals, List<BaseRouter<Controller>.Route> routes, boolean useAbsoluteUrl) Needed to support legacy API.
-
-
Method Details
-
buildUrl
Build url from patch and params. -
buildUrl
Shortcut for `buildUrl(path, params)`. -
parseWithRe
Parses string with regular expressions and returns list of results.- Returns:
- list of found matches
-
routeToRe
Convert string expression of the route like `/posts/:id/show` into the regular expression pattern, it uses Backbone.js rules for route expression. -
interpolate
Same as `String.interpolate` but allows to use named parts to improve readability, like `interpolate("/posts/:id", id)`. -
joinWithSlashWithoutEmpty
Builds path by joining strings with slashes, skips strings that are null. -
createController
Override this method and provide instance of the controller. -
addRoute
Add route and its handler.- Parameters:
route- use same rules as in Backbone.js to define the route.
-
canDispatch
Deprecated.since 3.3.2Deprecated, use dispatch instead. -
dispatch
Dispatches request to proper handlers. -
isUrlTooLong
Protecting from too long urls, it may consume a lot of CPU to regex it, see https://ecosystem.atlassian.net/browse/PLUGWEB-316. -
callHandler
protected void callHandler(BaseRouter<Controller>.Handler handler, Controller controller, Request request, Response response, String... args)
-