
Classes | |
| class | NameFormat |
Public Member Functions | |
| void | _clearCaches () |
| void | _putComponentsToSleepInContext (WOContext wocontext) |
| void | addDefaultRoutes (String entityName, String entityType, boolean numericPKs, Class<?extends ERXRouteController > controllerClass) |
| void | addDefaultRoutes (String entityName, boolean numericPKs, Class<?extends ERXRouteController > controllerClass) |
| void | addDefaultRoutes (String entityName, Class<?extends ERXRouteController > controllerClass) |
| void | addDefaultRoutes (String entityName) |
| void | addRoute (ERXRoute route) |
| void | addRoutes (String entityName, Class<?extends ERXRouteController > routeControllerClass) |
| void | addRoutes (String entityName) |
| String | controllerPathForEntityNamed (String entityName) |
| ERXRouteRequestHandler (NameFormat entityNameFormat) | |
| ERXRouteRequestHandler () | |
| WOAction | getActionInstance (Class class1, Class[] aclass, Object[] aobj) |
| Object[] | getRequestActionClassAndNameForPath (NSArray requestHandlerPath) |
| NSArray | getRequestHandlerPathForRequest (WORequest request) |
| void | insertRoute (ERXRoute route) |
| void | removeRoute (ERXRoute route) |
| Class<?extends ERXRouteController > | routeControllerClassForEntityNamed (String entityName) |
| ERXRoute | routeForMethodAndPath (String method, String path, NSMutableDictionary< String, Object > userInfo) |
| NSArray< ERXRoute > | routes () |
| NSArray< ERXRoute > | routesForControllerClass (Class<?extends ERXRouteController > routeController) |
| ERXRoute | setupRequestWithRouteForMethodAndPath (WORequest request, String method, String path) |
| void | setupRouteControllerFromUserInfo (ERXRouteController controller, NSDictionary< String, Object > userInfo) |
Static Public Member Functions | |
| static void | register (ERXRouteRequestHandler requestHandler) |
Static Public Attributes | |
| static final String | ExtensionKey = "ERXRouteRequestHandler.extension" |
| static final String | Key = "ra" |
| static final String | KeysKey = "ERXRouteRequestHandler.keys" |
| static final Logger | log = Logger.getLogger(ERXRouteRequestHandler.class) |
| static final String | PathKey = "ERXRouteRequestHandler.path" |
| static NameFormat | RAILS = new NameFormat(true, true, NameFormat.Case.LowercaseUnderscore) |
| static final String | RouteKey = "ERXRouteRequestHandler.route" |
| static final String | TypeKey = "ERXRouteRequestHandler.type" |
| static NameFormat | WO = new NameFormat(false, false, NameFormat.Case.CamelCase) |
| static NameFormat | WO_LOWER = new NameFormat(false, false, NameFormat.Case.LowerCamelCase) |
Protected Member Functions | |
| void | addDeclaredRoutes (String entityName, Class<?extends ERXRouteController > routeControllerClass, boolean addDefaultRoutesIfNoDeclaredRoutesFound) |
Package Functions | |
| public< T extends ERXRouteController > T | controller (Class< T > controllerClass, WORequest request, WOContext context) |
| public< T extends ERXRouteController > T | controller (Class< T > controllerClass, WOContext context) |
| public< T extends ERXRouteController > T | controller (String entityName, WORequest request, WOContext context) |
Private Attributes | |
| NameFormat | _entityNameFormat |
| NSMutableArray< ERXRoute > | _routes |
in Application:
ERXRouteRequestHandler routeRequestHandler = new ERXRouteRequestHandler(); routeRequestHandler.addDefaultRoutes(Person.ENTITY_NAME); ERXRouteRequestHandler.register(routeRequestHandler);
or
ERXRouteRequestHandler routeRequestHandler = new ERXRouteRequestHandler(); routeRequestHandler.addRoute(new ERXRoute("/people/{action}", PeopleController.class)); routeRequestHandler.addRoute(new ERXRoute("/person/{person:Person}", PeopleController.class, "show")); ... ERXRouteRequestHandler.register(routeRequestHandler);
Note that addDefaultRoutes sets up many routes automatically (not just the 2 that are shown above), and for most cases should be your starting point for adding new entities rather than manually adding them.
in PeopleController:
public class PeopleController extends ERXRouteController { public PeopleController(WORequest request) { super(request); }
public Person person() {
Person person = (Person) routeObjectForKey("person");
return person;
}
public ERXKeyFilter showFilter() {
ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes();
filter.include(Person.COMPANY).includeAttributes();
return filter;
}
public ERXKeyFilter updateFilter() {
ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes();
filter.include(Person.COMPANY);
return filter;
}
public WOActionResults createAction() {
Person person = (Person) create(Person.ENTITY_NAME, updateFilter());
editingContext().saveChanges();
return response(person, showFilter());
}
public WOActionResults updateAction() {
Person person = person();
update(person, updateFilter());
editingContext().saveChanges();
return response(person, showFilter());
}
public WOActionResults showAction() {
return response(person(), showFilter());
}
public WOActionResults indexAction() {
NSArray<Person> people = Person.fetchPersons(editingContext(), null, Person.LAST_NAME.asc().then(Person.FIRST_NAME.asc()));
return response(editingContext(), Person.ENTITY_NAME, people, showFilter());
}
}
in browser:
http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/people.xml http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/people.json http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/people.plist http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/person/100.json http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/person/100/edit.json
Constructs a new ERXRouteRequestHandler with the default entity name format.
| ERXRouteRequestHandler | ( | NameFormat | entityNameFormat | ) |
Constructs a new ERXRouteRequestHandler.
| entityNameFormat | the format to use for entity names in URLs |
| void _clearCaches | ( | ) |
Clears any caches that may exist on ERXRoutes (probably only useful to JRebel, to clear the route parameter method cache).
| void _putComponentsToSleepInContext | ( | WOContext | wocontext | ) |
| void addDeclaredRoutes | ( | String | entityName, | |
| Class<?extends ERXRouteController > | routeControllerClass, | |||
| boolean | addDefaultRoutesIfNoDeclaredRoutesFound | |||
| ) | [protected] |
| void addDefaultRoutes | ( | String | entityName, | |
| String | entityType, | |||
| boolean | numericPKs, | |||
| Class<?extends ERXRouteController > | controllerClass | |||
| ) |
| void addDefaultRoutes | ( | String | entityName, | |
| boolean | numericPKs, | |||
| Class<?extends ERXRouteController > | controllerClass | |||
| ) |
| void addDefaultRoutes | ( | String | entityName, | |
| Class<?extends ERXRouteController > | controllerClass | |||
| ) |
Adds list and view routes for the given entity. For instance, if you provide the entity name "Reminder" you will get the routes:
/reminders
/reminders/{action}
/reminder/{reminder:Reminder}
/reminder/{reminder:Reminder}/{action}
| entityName | the entity name to route with | |
| controllerClass | the controller class |
| void addDefaultRoutes | ( | String | entityName | ) |
| void addRoute | ( | ERXRoute | route | ) |
Adds a new route to this request handler.
| route | the route to add |
| void addRoutes | ( | String | entityName, | |
| Class<?extends ERXRouteController > | routeControllerClass | |||
| ) |
Calls the static method 'addRoutes(entityName, routeRequetHandler)' on the given route controller class, giving it the opportunity to add routes for the given entity. Additionally, this method looks for all methods annotated with or annotations and adds the corresponding routes. If no addRoutes method is found and no
annotated methods exist, it will log a warning and add default routes instead.
| entityName | the name of the entity | |
| routeControllerClass | the name of the route controller |
| void addRoutes | ( | String | entityName | ) |
Calls the static method 'addRoutes(entityName, routeRequetHandler)' on the route controller for the given entity name, giving it the opportunity to add routes for this entity. Additionally, this method looks for all methods annotated with or annotations and adds the corresponding routes. If no addRoutes method is found and no
annotated methods exist, it will log a warning and add default routes instead.
| entityName | the name of the entity |
| public<T extends ERXRouteController> T controller | ( | Class< T > | controllerClass, | |
| WORequest | request, | |||
| WOContext | context | |||
| ) | [package] |
Returns the corresponding controller instance.
| <T> | the type of controller to return | |
| controllerClass | the controller class to lookup | |
| request | the current request | |
| context | the current context |
| public<T extends ERXRouteController> T controller | ( | Class< T > | controllerClass, | |
| WOContext | context | |||
| ) | [package] |
Returns the corresponding controller instance (with no request specified).
| <T> | the type of controller to return | |
| controllerClass | the controller class to lookup | |
| context | the current context |
| public<T extends ERXRouteController> T controller | ( | String | entityName, | |
| WORequest | request, | |||
| WOContext | context | |||
| ) | [package] |
Returns the corresponding controller instance.
| <T> | the type of controller to return | |
| entityName | the entity name of the controller to lookup | |
| request | the current request | |
| context | the current context |
Return the controller path name for an entity name based on the entity name format.
| entityName | the entity name |
| WOAction getActionInstance | ( | Class | class1, | |
| Class[] | aclass, | |||
| Object[] | aobj | |||
| ) |
| Object [] getRequestActionClassAndNameForPath | ( | NSArray | requestHandlerPath | ) |
| NSArray getRequestHandlerPathForRequest | ( | WORequest | request | ) |
| void insertRoute | ( | ERXRoute | route | ) |
Inserts a route at the beginning of the route list.
| route | the route to insert |
| static void register | ( | ERXRouteRequestHandler | requestHandler | ) | [static] |
Registers an ERXRestRequestHandler with the WOApplication for the handler key "rest".
| requestHandler | the rest request handler to register |
| void removeRoute | ( | ERXRoute | route | ) |
Removes the given route from this request handler.
| route | the route to remove |
| Class<? extends ERXRouteController> routeControllerClassForEntityNamed | ( | String | entityName | ) |
Returns the default route controller class for the given entity name.
| entityName | the name of the entity |
| ERXRoute routeForMethodAndPath | ( | String | method, | |
| String | path, | |||
| NSMutableDictionary< String, Object > | userInfo | |||
| ) |
Returns the route that matches the request method and path, storing metadata about the route in the given userInfo dictionary.
| method | the request method | |
| path | the request path | |
| userInfo | a mutable userInfo |
| NSArray<ERXRoute> routes | ( | ) |
| NSArray<ERXRoute> routesForControllerClass | ( | Class<?extends ERXRouteController > | routeController | ) |
Sets up the request userInfo for the given request for a request of the given method and path.
| request | the request to configure the userInfo on | |
| method | the request method | |
| path | the request path |
| void setupRouteControllerFromUserInfo | ( | ERXRouteController | controller, | |
| NSDictionary< String, Object > | userInfo | |||
| ) |
Sets up a route controller based on a request userInfo that came from routeForMethodAndPath.
| controller | the controller to setup | |
| userInfo | the request userInfo |
NameFormat _entityNameFormat [private] |
NSMutableArray<ERXRoute> _routes [private] |
final String ExtensionKey = "ERXRouteRequestHandler.extension" [static] |
final Logger log = Logger.getLogger(ERXRouteRequestHandler.class) [static] |
NameFormat RAILS = new NameFormat(true, true, NameFormat.Case.LowercaseUnderscore) [static] |
A NameFormat that behaves like Rails -- plural entities, plural routes, lowercase underscore names (names_like_this).
NameFormat WO = new NameFormat(false, false, NameFormat.Case.CamelCase) [static] |
A NameFormat that behaves like WO -- singular entities, singular routes, camel names (NamesLikeThis).
NameFormat WO_LOWER = new NameFormat(false, false, NameFormat.Case.LowerCamelCase) [static] |
A NameFormat that behaves like WO -- singular entities, singular routes, lowercase camel names (namesLikeThis).
1.5.8