Package org.javalite.activeweb
Class Router
java.lang.Object
org.javalite.activeweb.Router
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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.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.static String
Generates a URI for a controller.static <T extends AppController>
StringgetControllerPath(Class<T> controllerClass)
Generates a path to a controller based on its package and class name.static <T extends AppController>
StringgetControllerPath(String controllerClassName, String controllerSimpleName)
protected org.javalite.activeweb.ControllerPath
getControllerPathByURI(String uri)
Finds a controller path from URI.void
setIgnoreSpecs(List<IgnoreSpec> ignoreSpecs)
void
setRoutes(List<RouteBuilder> routes)
Sets custom routesvoid
setStrictMode(boolean strictMode)
-
Constructor Details
-
Router
-
-
Method Details
-
setRoutes
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 controllerid
- id on a URIrestful
- 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
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
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
.
- Parameters:
controllerClass
- class of a controller.- Returns:
- standard path for a controller.
- For class:
-
getControllerPath
public static <T extends AppController> String getControllerPath(String controllerClassName, String controllerSimpleName) -
findControllerNamePart
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
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
-
setStrictMode
public void setStrictMode(boolean strictMode)
-