Class BaseRouter<Controller extends BaseController>

java.lang.Object
com.atlassian.plugin.webresource.impl.support.http.BaseRouter<Controller>
Direct Known Subclasses:
Router

public abstract class BaseRouter<Controller extends BaseController> extends Object
Generates urls and route requests to proper handlers.

Contains basic support for url generation and recognition.

Since:
3.3
  • Field Details

  • Constructor Details

  • Method Details

    • buildUrl

      public static String buildUrl(String path, Map<String,String> params)
      Build url from patch and params.
    • buildUrl

      public static String buildUrl(String path)
      Shortcut for `buildUrl(path, params)`.
    • parseWithRe

      public static List<String> parseWithRe(String string, String re)
      Parses string with regular expressions and returns list of results.
      Returns:
      list of found matches
    • routeToRe

      public 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.
    • interpolate

      public 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)`.
    • joinWithSlashWithoutEmpty

      public static String joinWithSlashWithoutEmpty(String... parts)
      Builds path by joining strings with slashes, skips strings that are null.
    • createController

      protected abstract Controller createController(Globals globals, Request request, Response response)
      Override this method and provide instance of the controller.
    • addRoute

      public void addRoute(String route, BaseRouter<Controller>.Handler handler)
      Add route and its handler.
      Parameters:
      route - use same rules as in Backbone.js to define the route.
    • canDispatch

      @Deprecated public boolean canDispatch(String path)
      Deprecated.
      since 3.3.2
      Deprecated, use dispatch instead.
    • dispatch

      public void dispatch(Request request, Response response)
      Dispatches request to proper handlers.
    • isUrlTooLong

      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.
    • callHandler

      protected void callHandler(BaseRouter<Controller>.Handler handler, Controller controller, Request request, Response response, String... args)