Class Router

java.lang.Object
org.javalite.activeweb.Router

public class Router extends Object
Responsible for looking at a URI and creating a route to controller if one is found. This is a thread - safe class.
Author:
Igor Polevoy
  • Constructor Details

    • Router

      protected Router(String rootControllerName)
  • Method Details

    • setRoutes

      public void setRoutes(List<RouteBuilder> routes)
      Sets custom routes
      Parameters:
      routes - se of custom routes defined for app.
    • generate

      public static String generate(String controllerPath, String action, String id, boolean restful, Map params)
      Generates a URI for a controller.
      Parameters:
      controllerPath - path to controller.
      action - action for a controller
      id - id on a URI
      restful - true if a route for a restful controller is needed, false for non-restful.
      params - name/value pairs to be used to form a query string.
      Returns:
      formed URI based on arguments.
    • getControllerPathByURI

      protected org.javalite.activeweb.ControllerPath getControllerPathByURI(String uri)
      Finds a controller path from URI. Controller path includes a package prefix taken from URI, similar to:

      http://host/context/admin/printers/show/1, where "admin" is a "package_suffix", "printers" is a "controller_name".

      for example above, the method will Map with two keys: "package_suffix" and "controller_name"

      Parameters:
      uri - this is a URI - the information after context : "controller/action/whatever".
      Returns:
      map with two keys: "controller_name" and "package_suffix", both of which can be null.
    • getControllerPath

      public static <T extends AppController> String getControllerPath(Class<T> controllerClass)
      Generates a path to a controller based on its package and class name. The path always starts with a slash: "/". Examples:

      • For class: app.controllers.Simple the path will be: /simple.
      • For class: app.controllers.admin.PeopleAdmin the path will be: /admin/people_admin.
      • For class: app.controllers.admin.simple.PeopleAdmin the path will be: /admin/simple/people_admin.

      Class name looses the "Controller" suffix and gets converted to underscore format, while packages stay unchanged.

      Parameters:
      controllerClass - class of a controller.
      Returns:
      standard path for a controller.
    • getControllerPath

      public static <T extends AppController> String getControllerPath(String controllerClassName, String controllerSimpleName)
    • findControllerNamePart

      protected static String findControllerNamePart(String pack, String uri)
      Now that we know that this controller is under a package, need to find the controller short name.
      Parameters:
      pack - part of the package of the controller, taken from URI: value between "app.controllers" and controller name.
      uri - uri from request
      Returns:
      controller name
    • findPackageSuffix

      protected String findPackageSuffix(String uri)
      Finds a part of a package name which can be found in between "app.controllers" and short name of class.
      Parameters:
      uri - uri from request
      Returns:
      a part of a package name which can be found in between "app.controllers" and short name of class, or null if not found
    • setIgnoreSpecs

      public void setIgnoreSpecs(List<IgnoreSpec> ignoreSpecs)
    • setStrictMode

      public void setStrictMode(boolean strictMode)