Class RouteBuilder

java.lang.Object
org.javalite.activeweb.RouteBuilder

public class RouteBuilder extends Object
Instance of this class represents a single custom route configured in the RouteConfig class of the application.
Author:
Igor Polevoy
  • Constructor Details

    • RouteBuilder

      protected RouteBuilder(AppController controller, String actionName, String id)
      Used for standard and restful routes.
      Parameters:
      controller - controller
      actionName - action name
      id - id
    • RouteBuilder

      protected RouteBuilder(AppController controller, String actionName)
      Used for tests.
      Parameters:
      controller - controller
      actionName - action name
    • RouteBuilder

      protected RouteBuilder(String routeConfig)
      Used for custom routes
      Parameters:
      routeConfig - what was specified in the RouteConfig class
  • Method Details

    • isWildcard

      public boolean isWildcard()
    • getWildcardName

      public String getWildcardName()
    • getWildCardValue

      public String getWildCardValue()
    • getRouteConfig

      public String getRouteConfig()
    • to

      public <T extends AppController> RouteBuilder to(Class<T> controllerClass)
      Allows to wire a route to a controller.
      Parameters:
      controllerClass - class of controller to which a route is mapped
      Returns:
      instance of RouteBuilder.
    • action

      public RouteBuilder action(String action)
      Name of action to which a route is mapped in the underscore format. for example, if the action method of a controller is listTrigger(), than this argument needs to be list_trigger.
      Parameters:
      action - name of action.
      Returns:
      instance of RouteBuilder.
    • get

      public RouteBuilder get()
      Specifies that this route is mapped to HTTP GET method.
      Returns:
      instance of RouteBuilder.
    • post

      public RouteBuilder post()
      Specifies that this route is mapped to HTTP POST method.
      Returns:
      instance of RouteBuilder.
    • patch

      public RouteBuilder patch()
      Specifies that this route is mapped to HTTP PATCH method.
      Returns:
      instance of RouteBuilder.
    • options

      public RouteBuilder options()
      Specifies that this route is mapped to HTTP OPTIONS method.
      Returns:
      instance of RouteBuilder.
    • put

      public RouteBuilder put()
      Specifies that this route is mapped to HTTP PUT method.
      Returns:
      instance of RouteBuilder.
    • delete

      public RouteBuilder delete()
      Specifies that this route is mapped to HTTP DELETE method.
      Returns:
      instance of RouteBuilder.
    • getActionName

      protected String getActionName()
    • getId

      protected String getId()
    • getController

      protected AppController getController()
    • matches

      protected boolean matches(String requestUri, org.javalite.activeweb.ControllerPath controllerPath, HttpMethod httpMethod) throws ClassLoadException
      Returns true if this route matches the request URI, otherwise returns false.
      Parameters:
      requestUri - incoming URI for request.
      httpMethod - HTTP method of the request.
      Returns:
      true if this route matches the request URI
      Throws:
      ClassLoadException - in case could not load controller
    • getUserSegmentName

      protected String getUserSegmentName(String segment)
      Extracts user segment name from route config. Returns null if no pattern match: {xxx}.
      Parameters:
      segment - user segment, such as "{user_id}", "{fav_color}", etc.
      Returns:
      the name inside the braces, "user_id", "fav_color", etc. Returns null if no pattern match: {xxx}.
    • getMethods

      public List<HttpMethod> getMethods()
    • getControllerClass

      public Class<? extends AppController> getControllerClass()
    • toString

      public String toString()
      Overrides:
      toString in class Object