Project Wonder 5.0

er.rest.routes
Class ERXRouteController

java.lang.Object
  extended by com.webobjects.appserver.WOAction
      extended by com.webobjects.appserver.WODirectAction
          extended by er.rest.routes.ERXRouteController
All Implemented Interfaces:
com.webobjects.foundation.NSKeyValueCoding, com.webobjects.foundation.NSKeyValueCoding.ErrorHandling, com.webobjects.foundation.NSKeyValueCodingAdditions, com.webobjects.foundation.NSValidation
Direct Known Subclasses:
ERXDefaultRouteController, ERXGianduiaController, ERXMissingRouteController, ERXReadOnlyRouteController, SEController

public class ERXRouteController
extends com.webobjects.appserver.WODirectAction

ERXRouteController is equivalent to a Rails controller class. It's actually a direct action, and has the same naming rules as a direct action, so your controller action methods must end in the name "Action". There are several utility methods for manipulating restful requests and responses (update(..), create(..), requestNode(), response(..), etc) , and it supports multiple formats for you.

Author:
mschrag

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions
com.webobjects.foundation.NSKeyValueCodingAdditions.DefaultImplementation, com.webobjects.foundation.NSKeyValueCodingAdditions.Utility
 
Nested classes/interfaces inherited from interface com.webobjects.foundation.NSKeyValueCoding
com.webobjects.foundation.NSKeyValueCoding._BooleanFieldBinding, com.webobjects.foundation.NSKeyValueCoding._BooleanMethodBinding, com.webobjects.foundation.NSKeyValueCoding._FieldBinding, com.webobjects.foundation.NSKeyValueCoding._ForwardingBinding, com.webobjects.foundation.NSKeyValueCoding._KeyBinding, com.webobjects.foundation.NSKeyValueCoding._KeyBindingCreation, com.webobjects.foundation.NSKeyValueCoding._MethodBinding, com.webobjects.foundation.NSKeyValueCoding._NumberFieldBinding, com.webobjects.foundation.NSKeyValueCoding._NumberMethodBinding, com.webobjects.foundation.NSKeyValueCoding._ReflectionKeyBindingCreation, com.webobjects.foundation.NSKeyValueCoding.ErrorHandling, com.webobjects.foundation.NSKeyValueCoding.Null, com.webobjects.foundation.NSKeyValueCoding.UnknownKeyException, com.webobjects.foundation.NSKeyValueCoding.ValueAccessor
 
Nested classes/interfaces inherited from interface com.webobjects.foundation.NSValidation
com.webobjects.foundation.NSValidation._MethodBinding, com.webobjects.foundation.NSValidation._ValidationBinding, com.webobjects.foundation.NSValidation.DefaultImplementation, com.webobjects.foundation.NSValidation.Utility, com.webobjects.foundation.NSValidation.ValidationException
 
Field Summary
protected static org.apache.log4j.Logger log
           
 
Fields inherited from class com.webobjects.appserver.WODirectAction
actionText
 
Fields inherited from class com.webobjects.appserver.WOAction
_actionClasses, _context
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding.ErrorHandling
_CLASS
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions
_CLASS, _KeyPathSeparatorChar, KeyPathSeparator
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding
NullValue
 
Fields inherited from interface com.webobjects.foundation.NSValidation
_CLASS
 
Constructor Summary
ERXRouteController(com.webobjects.appserver.WORequest request)
          Constructs a new ERXRouteController.
 
Method Summary
protected  boolean _canSetHeaderForActionResults(com.webobjects.appserver.WOActionResults results)
          Returns whether or not headers can be added to the given action results.
static com.webobjects.foundation.NSMutableArray<ERXRouteController> _controllersForRequest(com.webobjects.appserver.WORequest request)
          Returns the controllers that have been used on the given request.
static void _disposeControllersForRequest(com.webobjects.appserver.WORequest request)
          Disposes all of the controllers that were used on the given request.
protected static void _registerControllerForRequest(ERXRouteController controller, com.webobjects.appserver.WORequest request)
          Registers the given controller with the given request, so it can be later disposed.
 void _setContext(com.webobjects.appserver.WOContext context)
          WODirectAction doesn't expose API for setting the context, which can be useful for passing data between controller.
 void _setEntityName(java.lang.String entityName)
          Sets the entity name for this controller.
 void _setFormat(ERXRestFormat format)
          Sets the format that will be used by this route controller.
protected  void _setHeaderForActionResults(java.lang.String value, java.lang.String key, com.webobjects.appserver.WOActionResults results)
          Attempt to set the header for the given results object.
 void _setRequestContent(ERXRestFormat format, java.lang.String requestContent)
          Sets the request content that this controller will use for processing.
 void _setRequestContent(java.lang.String requestContent)
          Sets the request content that this controller will use for processing -- this requires that a format() is specified.
 void _setRequestHandler(ERXRouteRequestHandler requestHandler)
          Sets the request handler that processed this route.
 void _setRequestNode(ERXRestRequestNode requestNode)
          Sets the request node that this controller will use for processing.
 void _setRoute(ERXRoute route)
          Sets the route that is associated with this request.
 void _setRouteKeys(com.webobjects.foundation.NSDictionary<ERXRoute.Key,java.lang.String> routeKeys)
          Sets the unprocessed keys from the route.
 void _setRouteObjects(com.webobjects.foundation.NSDictionary<ERXRoute.Key,java.lang.Object> objects)
          Sets the processed objects for the current route.
protected  void _takeRouteParametersFromRequest(com.webobjects.appserver.WOActionResults results)
          Enumerates the route keys, looks for @ERXRouteParameter annotated methods, and sets the value of the routeKey with the corresponding method if it exists.
protected  java.lang.String accessControlAllowOrigin()
          Returns the allowed origin for cross-site requests.
protected  com.webobjects.foundation.NSArray<java.lang.String> accessControlAllowRequestHeaders(com.webobjects.foundation.NSArray<java.lang.String> requestHeaders)
          Returns the allowed request headers given the requested headers.Set the property ERXRest.accessControlAllowRequestHeaders to override the default of just returning the requested headers.
protected  com.webobjects.foundation.NSArray<java.lang.String> accessControlAllowRequestMethods(java.lang.String requestMethod)
          Returns the allowed request methods given the requested method.
protected  long accessControlMaxAage()
          Returns the maximum age in seconds for the preflight options cache.
protected  boolean allowWindowNameCrossDomainTransport()
          Returns whether or not the window.name cross-domain transport is allowed.
protected  void checkAccess()
          Override to provide custom security checks.
 boolean containsRouteKey(java.lang.String key)
          Returns whether or not there is a route key with the given name.
<T extends ERXRouteController>
T
controller(java.lang.Class<T> controllerClass)
          Returns another controller, passing the required state on.
<T extends ERXRouteController>
T
controller(java.lang.String entityName)
          Returns another controller, passing the required state on.
<T> T
create(ERXKeyFilter filter)
          Creates a new object from the request data that is of the routed entity name and is filtered with the given filter.
<T> T
create(ERXKeyFilter filter, IERXRestDelegate delegate)
          Creates a new object from the request data that is of the routed entity name and is filtered with the given filter.
<T> T
create(java.lang.String entityName, ERXKeyFilter filter)
          Creates a new object from the request data that is of the given entity name and is filtered with the given filter.
<T> T
create(java.lang.String entityName, ERXKeyFilter filter, IERXRestDelegate delegate)
          Creates a new object from the request data that is of the given entity name and is filtered with the given filter.
protected  ERXRestFormat defaultFormat()
          Returns the default format to use if no other format is found, or if the requested format is invalid.
protected  IERXRestDelegate delegate()
          Returns the default rest delegate for this controller (an ERXRestRequestNode.EODelegate using the editing context returned from editingContext()).
 void dispose()
          Disposes any resources the route controller may be holding onto (like its editing context).
 com.webobjects.eocontrol.EOEditingContext editingContext()
          The controller maintains an editing context for the duration of the request.
protected  java.lang.String entityName()
          Returns the name of the entity that this controller is currently handling.
 com.webobjects.appserver.WOActionResults errorResponse(java.lang.String errorMessage, int status)
          Returns an error response with the given HTTP status.
 com.webobjects.appserver.WOActionResults errorResponse(java.lang.Throwable t, int status)
          Returns an error response with the given HTTP status.
 ERXRestFormat format()
          Returns the format that the user requested (usually based on the request file extension).
 com.webobjects.appserver.WOActionResults headAction()
          Returns the response from a HEAD call to this controller.
protected  ERXKeyFilter includeOptional(ERXKey<?> key, ERXKeyFilter filter)
          Includes the key in the given filter if isKeyPathRequested returns true.
protected  boolean isAutomaticHtmlRoutingEnabled()
          If this method returns true, all HTML format requests will be automatically routed to the corresponding IERXRouteComponent implementation based on the name returned by pageNameForAction(String).
protected  boolean isKeyPathRequested(ERXKey<?> key)
          Returns whether or not the prefetchingKeyPaths option includes the given keypath (meaning, the client requested to include the given keypath).
protected  boolean isKeyPathRequested(java.lang.String keyPath)
          Returns whether or not the prefetchingKeyPaths option includes the given keypath (meaning, the client requested to include the given keypath).
protected  boolean isSchemaRequest()
          Returns whether or not this request is for a schema.
 com.webobjects.appserver.WOActionResults json(com.webobjects.eocontrol.EOClassDescription entity, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as a JSON response.
 com.webobjects.appserver.WOActionResults json(com.webobjects.eocontrol.EOEditingContext editingContext, java.lang.String entityName, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as a JSON response.
 com.webobjects.appserver.WOActionResults json(java.lang.Object value, ERXKeyFilter filter)
          Returns the given object as a JSON response.
 com.webobjects.appserver.WOActionResults json(java.lang.String entityName, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as a JSON response.
protected  com.webobjects.eocontrol.EOEditingContext newEditingContext()
          Creates a new editing context.
protected  com.webobjects.eocontrol.EOEditingContext newEditingContext(com.webobjects.eocontrol.EOObjectStore objectStore)
          Creates a new editing context with a parent object store.
<T> T
object(ERXKeyFilter filter)
          Returns the object from the request data that is of the routed entity name and is filtered with the given filter.
<T> T
object(ERXKeyFilter filter, IERXRestDelegate delegate)
          Returns the object from the request data that is of the routed entity name and is filtered with the given filter.
<T> T
object(java.lang.String entityName, ERXKeyFilter filter)
          Returns the object from the request data that is of the given entity name and is filtered with the given filter.
<T> T
object(java.lang.String entityName, ERXKeyFilter filter, IERXRestDelegate delegate)
          Returns the object from the request data that is of the given entity name and is filtered with the given filter.
 com.webobjects.foundation.NSKeyValueCoding options()
          Returns the options for this controller.
 com.webobjects.appserver.WOActionResults optionsAction()
          A default options action that implements access control policy.
protected  java.lang.String pageNameForAction(java.lang.String actionName)
          Returns the name of the page component for this entity and the given action.
<T extends com.webobjects.appserver.WOComponent>
T
pageWithName(java.lang.Class<T> componentClass)
          Calls pageWithName.
 com.webobjects.appserver.WOActionResults performActionNamed(java.lang.String actionName)
           
 com.webobjects.appserver.WOActionResults performActionNamed(java.lang.String actionName, boolean throwExceptions)
          Performs the given action, optionally throwing exceptions instead of converting to http response codes.
protected  com.webobjects.appserver.WOActionResults performUnknownAction(java.lang.String actionName)
          Called when no standard action method can be found to handle the requested route.
 com.webobjects.appserver.WOActionResults plist(com.webobjects.eocontrol.EOClassDescription entity, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as a JSON response.
 com.webobjects.appserver.WOActionResults plist(com.webobjects.eocontrol.EOEditingContext editingContext, java.lang.String entityName, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as a JSON response.
 com.webobjects.appserver.WOActionResults plist(java.lang.Object value, ERXKeyFilter filter)
          Returns the given object as a PList response.
 com.webobjects.appserver.WOActionResults plist(java.lang.String entityName, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as a PList response.
 ERXRouteRequestHandler requestHandler()
          Returns the request handler that processed this route.
 ERXRestRequestNode requestNode()
          Returns the request data in the form of an ERXRestRequestNode (which is a format-independent wrapper around hierarchical data).
 com.webobjects.appserver.WOActionResults response(com.webobjects.eocontrol.EOClassDescription entity, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as an response in the format returned from the format() method.
 com.webobjects.appserver.WOActionResults response(com.webobjects.eocontrol.EOEditingContext editingContext, java.lang.String entityName, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as an response in the format returned from the format() method.
 com.webobjects.appserver.WOActionResults response(ERXRestFetchSpecification<?> fetchSpec, ERXKeyFilter filter)
          Returns the results of the rest fetch spec as an response in the format returned from the format() method.
 com.webobjects.appserver.WOActionResults response(ERXRestFormat format, com.webobjects.eocontrol.EOClassDescription entity, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as a response in the given format.
 com.webobjects.appserver.WOActionResults response(ERXRestFormat format, com.webobjects.eocontrol.EOEditingContext editingContext, java.lang.String entityName, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as a response in the given format.
 com.webobjects.appserver.WOActionResults response(ERXRestFormat format, ERXRestRequestNode responseNode)
          Returns the given ERXRestRequestNode as a response in the given format.
 com.webobjects.appserver.WOActionResults response(ERXRestFormat format, java.lang.Object value, ERXKeyFilter filter)
          Returns the given object as a WOResponse in the given format.
 com.webobjects.appserver.WOActionResults response(ERXRestFormat format, java.lang.String entityName, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as a response in the given format.
 com.webobjects.appserver.WOActionResults response(java.lang.Object value, ERXKeyFilter filter)
          Returns the given object as a response in the format returned from the format() method.
 com.webobjects.appserver.WOActionResults response(java.lang.String entityName, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as an response in the format returned from the format() method.
 java.lang.String responseContentForActionNamed(java.lang.String actionName)
          Returns the response content generated from performing the action with the given name.
 ERXRestRequestNode responseNodeForActionNamed(java.lang.String actionName)
          Returns the response node generated from performing the action with the given name.
 ERXRoute route()
          Returns the route associated with this request.
 com.webobjects.foundation.NSDictionary<ERXRoute.Key,java.lang.String> routeKeys()
          Returns the unprocessed keys from the route (the values are the original value from the URL).
<T> T
routeObjectForKey(java.lang.String key)
          Returns the processed object from the route keys with the given name.
 com.webobjects.foundation.NSDictionary<ERXRoute.Key,java.lang.Object> routeObjects()
          Returns all the processed objects from the route keys.
 com.webobjects.foundation.NSDictionary<ERXRoute.Key,java.lang.Object> routeObjects(IERXRestDelegate delegate)
          Returns all the processed objects from the route keys.
 java.lang.String routeStringForKey(java.lang.String key)
          Returns the unprocessed value from the route with the given key name.
protected  com.webobjects.appserver.WOActionResults schemaResponse(ERXKeyFilter filter)
          Returns the schema response for the current entity with the given filter.
protected  com.webobjects.appserver.WOActionResults schemaResponseForEntityNamed(java.lang.String entityName, ERXKeyFilter filter)
          Returns the schema response for the given entity with the given filter.
 void setOptions(com.webobjects.foundation.NSKeyValueCoding options)
          Sets the options for this controller.
protected  boolean shouldFailOnMissingHtmlPage()
          If automatic html routing is enabled and there is no page component found that matches the current route, should that result in a 404?
 com.webobjects.appserver.WOResponse stringResponse(java.lang.String str)
          Returns the given string wrapped in a WOResponse.
 java.lang.String toString()
           
 void update(java.lang.Object obj, ERXKeyFilter filter)
          Updates the given object from the request data with the given filter.
 void update(java.lang.Object obj, ERXKeyFilter filter, IERXRestDelegate delegate)
          Updates the given object from the request data with the given filter.
 com.webobjects.appserver.WOActionResults xml(com.webobjects.eocontrol.EOClassDescription entity, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as an XML response.
 com.webobjects.appserver.WOActionResults xml(com.webobjects.eocontrol.EOEditingContext editingContext, java.lang.String entityName, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as an XML response.
 com.webobjects.appserver.WOActionResults xml(java.lang.Object value, ERXKeyFilter filter)
          Returns the given object as an XML response.
 com.webobjects.appserver.WOActionResults xml(java.lang.String entityName, com.webobjects.foundation.NSArray<?> values, ERXKeyFilter filter)
          Returns the given array as an XML response.
 
Methods inherited from class com.webobjects.appserver.WODirectAction
_componentAction, defaultAction, getSessionIDForRequest, takeFormValueArraysForKeyArray, takeFormValuesForKeyArray
 
Methods inherited from class com.webobjects.appserver.WOAction
_isActionOnClass, _methodForAction, _preloadAllActionsOnClass, canAccessFieldsDirectly, context, debugString, existingSession, handleQueryWithUnboundKey, handleTakeValueForUnboundKey, initializeRequestSessionIDInContext, languages, logString, pageWithName, request, session, setLanguages, takeValueForKey, takeValueForKeyPath, unableToSetNullForKey, validateTakeValueForKeyPath, validateValueForKey, valueForKey, valueForKeyPath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.webobjects.foundation.NSKeyValueCoding.ErrorHandling
handleQueryWithUnboundKey, handleTakeValueForUnboundKey, unableToSetNullForKey
 
Methods inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions
takeValueForKeyPath, valueForKeyPath
 
Methods inherited from interface com.webobjects.foundation.NSKeyValueCoding
takeValueForKey, valueForKey
 
Methods inherited from interface com.webobjects.foundation.NSValidation
validateTakeValueForKeyPath, validateValueForKey
 

Field Detail

log

protected static org.apache.log4j.Logger log
Constructor Detail

ERXRouteController

public ERXRouteController(com.webobjects.appserver.WORequest request)
Constructs a new ERXRouteController.

Parameters:
request - the request
Method Detail

includeOptional

protected ERXKeyFilter includeOptional(ERXKey<?> key,
                                       ERXKeyFilter filter)
Includes the key in the given filter if isKeyPathRequested returns true.

Parameters:
key - the key to lookup
filter - the filter to include into
Returns:
the nested filter (or null if the key was not requested)

isKeyPathRequested

protected boolean isKeyPathRequested(ERXKey<?> key)
Returns whether or not the prefetchingKeyPaths option includes the given keypath (meaning, the client requested to include the given keypath).

Parameters:
key - the ERXKey to check on
Returns:
true if the keyPath is in the prefetchingKeyPaths option

isKeyPathRequested

protected boolean isKeyPathRequested(java.lang.String keyPath)
Returns whether or not the prefetchingKeyPaths option includes the given keypath (meaning, the client requested to include the given keypath).

Parameters:
keyPath - the keyPath to check on
Returns:
true if the keyPath is in the prefetchingKeyPaths option

setOptions

public void setOptions(com.webobjects.foundation.NSKeyValueCoding options)
Sets the options for this controller.

Parameters:
options - options for this controller

options

public com.webobjects.foundation.NSKeyValueCoding options()
Returns the options for this controller. Options are an abstraction on request form values.

Returns:
the options for this controller (default to be ERXRequestFormValues)

_setContext

public void _setContext(com.webobjects.appserver.WOContext context)
WODirectAction doesn't expose API for setting the context, which can be useful for passing data between controller.

Parameters:
context - the new context

_setRequestHandler

public void _setRequestHandler(ERXRouteRequestHandler requestHandler)
Sets the request handler that processed this route.

Parameters:
requestHandler - the request handler that processed this route

requestHandler

public ERXRouteRequestHandler requestHandler()
Returns the request handler that processed this route.

Returns:
the request handler that processed this route

checkAccess

protected void checkAccess()
                    throws java.lang.SecurityException
Override to provide custom security checks. It is not necessary to call super on this method.

Throws:
java.lang.SecurityException - if the security check fails

editingContext

public com.webobjects.eocontrol.EOEditingContext editingContext()
The controller maintains an editing context for the duration of the request. The first time you call this method, you will get a new EOEditingContext. Subsequent calls will return the same instance. This makes it a little more convenient when you're using update, create, etc methods.

Returns:
an EOEditingContext

newEditingContext

protected com.webobjects.eocontrol.EOEditingContext newEditingContext()
Creates a new editing context.

Returns:
a new editing context

newEditingContext

protected com.webobjects.eocontrol.EOEditingContext newEditingContext(com.webobjects.eocontrol.EOObjectStore objectStore)
Creates a new editing context with a parent object store.

Parameters:
objectStore - the parent object store
Returns:
a new editing context

_setRoute

public void _setRoute(ERXRoute route)
Sets the route that is associated with this request. This is typically only set by the request handler.

Parameters:
route - the route that is associated with this controller

route

public ERXRoute route()
Returns the route associated with this request.

Returns:
the route associated with this request

_setRouteKeys

public void _setRouteKeys(com.webobjects.foundation.NSDictionary<ERXRoute.Key,java.lang.String> routeKeys)
Sets the unprocessed keys from the route.

Parameters:
routeKeys - the parsed keys from the route

routeKeys

public com.webobjects.foundation.NSDictionary<ERXRoute.Key,java.lang.String> routeKeys()
Returns the unprocessed keys from the route (the values are the original value from the URL).

Returns:
the unprocessed keys from the route

routeStringForKey

public java.lang.String routeStringForKey(java.lang.String key)
Returns the unprocessed value from the route with the given key name.

Parameters:
key - the key name to lookup
Returns:
the unprocessed value from the route with the given key name

containsRouteKey

public boolean containsRouteKey(java.lang.String key)
Returns whether or not there is a route key with the given name.

Parameters:
key - the key name to lookup
Returns:
whether or not there is a route key with the given name

routeObjectForKey

public <T> T routeObjectForKey(java.lang.String key)
Returns the processed object from the route keys with the given name. For instance, if your route specifies that you have a {person:Person}, routeObjectForKey("person") will return a Person object.

Parameters:
key - the key name to lookup
Returns:
the processed object from the route keys with the given name

_setRouteObjects

public void _setRouteObjects(com.webobjects.foundation.NSDictionary<ERXRoute.Key,java.lang.Object> objects)
Sets the processed objects for the current route. For instance, if your route specifies that you have a {person:Person}, this dictionary should contain a mapping from that route key to a person instance.

Parameters:
objects - the route objects to override

routeObjects

public com.webobjects.foundation.NSDictionary<ERXRoute.Key,java.lang.Object> routeObjects()
Returns all the processed objects from the route keys. For instance, if your route specifies that you have a {person:Person}, routeObjectForKey("person") will return a Person object.

Returns:
the processed objects from the route keys

routeObjects

public com.webobjects.foundation.NSDictionary<ERXRoute.Key,java.lang.Object> routeObjects(IERXRestDelegate delegate)
Returns all the processed objects from the route keys. For instance, if your route specifies that you have a {person:Person}, routeObjectForKey("person") will return a Person object. This method does NOT cache the results.

Parameters:
delegate - the delegate to fetch with
Returns:
the processed objects from the route keys

defaultFormat

protected ERXRestFormat defaultFormat()
Returns the default format to use if no other format is found, or if the requested format is invalid.

Returns:
the default format to use if no other format is found, or if the requested format is invalid

_setFormat

public void _setFormat(ERXRestFormat format)
Sets the format that will be used by this route controller.

Parameters:
format - the format to be used by this route controller

format

public ERXRestFormat format()
Returns the format that the user requested (usually based on the request file extension).

Returns:
the format that the user requested

delegate

protected IERXRestDelegate delegate()
Returns the default rest delegate for this controller (an ERXRestRequestNode.EODelegate using the editing context returned from editingContext()). Override this method to provide a custom delegate implementation for this controller.

Returns:
a default rest delegate

_setRequestContent

public void _setRequestContent(ERXRestFormat format,
                               java.lang.String requestContent)
Sets the request content that this controller will use for processing.

Parameters:
format - the requested format
requestContent - the content of the incoming request

_setRequestContent

public void _setRequestContent(java.lang.String requestContent)
Sets the request content that this controller will use for processing -- this requires that a format() is specified.

Parameters:
requestContent - the content of the incoming request

_setRequestNode

public void _setRequestNode(ERXRestRequestNode requestNode)
Sets the request node that this controller will use for processing.

Parameters:
requestNode - the node reprsenting the incoming request

requestNode

public ERXRestRequestNode requestNode()
Returns the request data in the form of an ERXRestRequestNode (which is a format-independent wrapper around hierarchical data).

Returns:
the request data as an ERXRestRequestNode

object

public <T> T object(ERXKeyFilter filter)
Returns the object from the request data that is of the routed entity name and is filtered with the given filter. This will use the delegate returned from this controller's delegate() method.

Parameters:
filter - the filter to apply to the object for the purposes of updating (or null to not update)
Returns:
the object from the request data

object

public <T> T object(java.lang.String entityName,
                    ERXKeyFilter filter)
Returns the object from the request data that is of the given entity name and is filtered with the given filter. This will use the delegate returned from this controller's delegate() method.

Parameters:
entityName - the entity name of the object in the request
filter - the filter to apply to the object for the purposes of updating (or null to not update)
Returns:
the object from the request data

object

public <T> T object(ERXKeyFilter filter,
                    IERXRestDelegate delegate)
Returns the object from the request data that is of the routed entity name and is filtered with the given filter.

Parameters:
filter - the filter to apply to the object for the purposes of updating (or null to not update)
delegate - the delegate to use
Returns:
the object from the request data

object

public <T> T object(java.lang.String entityName,
                    ERXKeyFilter filter,
                    IERXRestDelegate delegate)
Returns the object from the request data that is of the given entity name and is filtered with the given filter.

Parameters:
entityName - the entity name of the object in the request
filter - the filter to apply to the object for the purposes of updating (or null to not update)
delegate - the delegate to use
Returns:
the object from the request data

create

public <T> T create(ERXKeyFilter filter)
Creates a new object from the request data that is of the routed entity name and is filtered with the given filter. This will use the delegate returned from this controller's delegate() method.

Parameters:
filter - the filter to apply to the object for the purposes of updating (or null to just create a blank one)
Returns:
the object from the request data

create

public <T> T create(java.lang.String entityName,
                    ERXKeyFilter filter)
Creates a new object from the request data that is of the given entity name and is filtered with the given filter. This will use the delegate returned from this controller's delegate() method.

Parameters:
entityName - the entity name of the object in the request
filter - the filter to apply to the object for the purposes of updating (or null to just create a blank one)
Returns:
the object from the request data

create

public <T> T create(ERXKeyFilter filter,
                    IERXRestDelegate delegate)
Creates a new object from the request data that is of the routed entity name and is filtered with the given filter.

Parameters:
filter - the filter to apply to the object for the purposes of updating (or null to just create a blank one)
delegate - the delegate to use
Returns:
the object from the request data

create

public <T> T create(java.lang.String entityName,
                    ERXKeyFilter filter,
                    IERXRestDelegate delegate)
Creates a new object from the request data that is of the given entity name and is filtered with the given filter.

Parameters:
entityName - the entity name of the object in the request
filter - the filter to apply to the object for the purposes of updating (or null to just create a blank one)
delegate - the delegate to use
Returns:
the object from the request data

update

public void update(java.lang.Object obj,
                   ERXKeyFilter filter)
Updates the given object from the request data with the given filter. This will use the delegate returned from this controller's delegate() method.

Parameters:
obj - the object to update
filter - the filter to apply to the object for the purposes of updating (or null to not update)

update

public void update(java.lang.Object obj,
                   ERXKeyFilter filter,
                   IERXRestDelegate delegate)
Updates the given object from the request data with the given filter.

Parameters:
obj - object to update
filter - the filter to apply to the object for the purposes of updating (or null to not update)
delegate - delegate to use

stringResponse

public com.webobjects.appserver.WOResponse stringResponse(java.lang.String str)
Returns the given string wrapped in a WOResponse.

Parameters:
str - the string to return
Returns:
a WOResponse

json

public com.webobjects.appserver.WOActionResults json(java.lang.String entityName,
                                                     com.webobjects.foundation.NSArray<?> values,
                                                     ERXKeyFilter filter)
Returns the given array as a JSON response. This uses the editing context returned by editingContext().

Parameters:
entityName - the name of the entities in the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
a JSON WOResponse

json

public com.webobjects.appserver.WOActionResults json(com.webobjects.eocontrol.EOEditingContext editingContext,
                                                     java.lang.String entityName,
                                                     com.webobjects.foundation.NSArray<?> values,
                                                     ERXKeyFilter filter)
Returns the given array as a JSON response.

Parameters:
editingContext - the editing context to use
entityName - the name of the entities in the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
a JSON WOResponse

json

public com.webobjects.appserver.WOActionResults json(com.webobjects.eocontrol.EOClassDescription entity,
                                                     com.webobjects.foundation.NSArray<?> values,
                                                     ERXKeyFilter filter)
Returns the given array as a JSON response.

Parameters:
entity - the entity type of the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
a JSON WOResponse

plist

public com.webobjects.appserver.WOActionResults plist(java.lang.String entityName,
                                                      com.webobjects.foundation.NSArray<?> values,
                                                      ERXKeyFilter filter)
Returns the given array as a PList response. This uses the editing context returned by editingContext().

Parameters:
entityName - the name of the entities in the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
a PList WOResponse

plist

public com.webobjects.appserver.WOActionResults plist(com.webobjects.eocontrol.EOEditingContext editingContext,
                                                      java.lang.String entityName,
                                                      com.webobjects.foundation.NSArray<?> values,
                                                      ERXKeyFilter filter)
Returns the given array as a JSON response.

Parameters:
editingContext - the editing context to use
entityName - the name of the entities in the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
a JSON WOResponse

plist

public com.webobjects.appserver.WOActionResults plist(com.webobjects.eocontrol.EOClassDescription entity,
                                                      com.webobjects.foundation.NSArray<?> values,
                                                      ERXKeyFilter filter)
Returns the given array as a JSON response.

Parameters:
entity - the entity type of the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
a JSON WOResponse

xml

public com.webobjects.appserver.WOActionResults xml(java.lang.String entityName,
                                                    com.webobjects.foundation.NSArray<?> values,
                                                    ERXKeyFilter filter)
Returns the given array as an XML response. This uses the editing context returned by editingContext().

Parameters:
entityName - the name of the entities in the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
an XML WOResponse

xml

public com.webobjects.appserver.WOActionResults xml(com.webobjects.eocontrol.EOEditingContext editingContext,
                                                    java.lang.String entityName,
                                                    com.webobjects.foundation.NSArray<?> values,
                                                    ERXKeyFilter filter)
Returns the given array as an XML response.

Parameters:
editingContext - the editing context to use
entityName - the name of the entities in the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
an XML WOResponse

xml

public com.webobjects.appserver.WOActionResults xml(com.webobjects.eocontrol.EOClassDescription entity,
                                                    com.webobjects.foundation.NSArray<?> values,
                                                    ERXKeyFilter filter)
Returns the given array as an XML response.

Parameters:
entity - the entity type of the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
an XML WOResponse

_canSetHeaderForActionResults

protected boolean _canSetHeaderForActionResults(com.webobjects.appserver.WOActionResults results)
Returns whether or not headers can be added to the given action results.

Parameters:
results - the results to test
Returns:
whether or not headers can be added to the given action results

_setHeaderForActionResults

protected void _setHeaderForActionResults(java.lang.String value,
                                          java.lang.String key,
                                          com.webobjects.appserver.WOActionResults results)
Attempt to set the header for the given results object.

Parameters:
value - the value
key - the key
results - the results object

response

public com.webobjects.appserver.WOActionResults response(ERXRestFetchSpecification<?> fetchSpec,
                                                         ERXKeyFilter filter)
Returns the results of the rest fetch spec as an response in the format returned from the format() method. This uses the editing context returned by editingContext().

Parameters:
fetchSpec - the rest fetch specification to execute
filter - the filter to apply to the objects
Returns:
a WOResponse of the format returned from the format() method

response

public com.webobjects.appserver.WOActionResults response(java.lang.String entityName,
                                                         com.webobjects.foundation.NSArray<?> values,
                                                         ERXKeyFilter filter)
Returns the given array as an response in the format returned from the format() method. This uses the editing context returned by editingContext().

Parameters:
entityName - the name of the entities in the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
a WOResponse of the format returned from the format() method

response

public com.webobjects.appserver.WOActionResults response(com.webobjects.eocontrol.EOEditingContext editingContext,
                                                         java.lang.String entityName,
                                                         com.webobjects.foundation.NSArray<?> values,
                                                         ERXKeyFilter filter)
Returns the given array as an response in the format returned from the format() method.

Parameters:
editingContext - the editing context to use
entityName - the name of the entities in the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
a WOResponse of the format returned from the format() method

response

public com.webobjects.appserver.WOActionResults response(com.webobjects.eocontrol.EOClassDescription entity,
                                                         com.webobjects.foundation.NSArray<?> values,
                                                         ERXKeyFilter filter)
Returns the given array as an response in the format returned from the format() method.

Parameters:
entity - the entity type of the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
a WOResponse of the format returned from the format() method

response

public com.webobjects.appserver.WOActionResults response(ERXRestFormat format,
                                                         java.lang.String entityName,
                                                         com.webobjects.foundation.NSArray<?> values,
                                                         ERXKeyFilter filter)
Returns the given array as a response in the given format.

Parameters:
format - the format to use
entityName - the name of the entity type of the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
a WOResponse in the given format

response

public com.webobjects.appserver.WOActionResults response(ERXRestFormat format,
                                                         com.webobjects.eocontrol.EOEditingContext editingContext,
                                                         java.lang.String entityName,
                                                         com.webobjects.foundation.NSArray<?> values,
                                                         ERXKeyFilter filter)
Returns the given array as a response in the given format.

Parameters:
format - the format to use
editingContext - the editing context to use
entityName - the name of the entities in the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
a WOResponse in the given format

response

public com.webobjects.appserver.WOActionResults response(ERXRestFormat format,
                                                         com.webobjects.eocontrol.EOClassDescription entity,
                                                         com.webobjects.foundation.NSArray<?> values,
                                                         ERXKeyFilter filter)
Returns the given array as a response in the given format.

Parameters:
format - the format to use
entity - the entity type of the array
values - the values in the array
filter - the filter to apply to the objects
Returns:
a WOResponse in the given format

response

public com.webobjects.appserver.WOActionResults response(ERXRestFormat format,
                                                         ERXRestRequestNode responseNode)
Returns the given ERXRestRequestNode as a response in the given format.

Parameters:
format - the format to use
responseNode - the request node to render
Returns:
a WOResponse in the given format

json

public com.webobjects.appserver.WOActionResults json(java.lang.Object value,
                                                     ERXKeyFilter filter)
Returns the given object as a JSON response.

Parameters:
value - the value to return
filter - the filter to apply
Returns:
a WOResponse in JSON format

plist

public com.webobjects.appserver.WOActionResults plist(java.lang.Object value,
                                                      ERXKeyFilter filter)
Returns the given object as a PList response.

Parameters:
value - the value to return
filter - the filter to apply
Returns:
a WOResponse in PList format

xml

public com.webobjects.appserver.WOActionResults xml(java.lang.Object value,
                                                    ERXKeyFilter filter)
Returns the given object as an XML response.

Parameters:
value - the value to return
filter - the filter to apply
Returns:
a WOResponse in XML format

response

public com.webobjects.appserver.WOActionResults response(java.lang.Object value,
                                                         ERXKeyFilter filter)
Returns the given object as a response in the format returned from the format() method.

Parameters:
value - the value to return
filter - the filter to apply
Returns:
a WOResponse in the format returned from the format() method.

response

public com.webobjects.appserver.WOActionResults response(ERXRestFormat format,
                                                         java.lang.Object value,
                                                         ERXKeyFilter filter)
Returns the given object as a WOResponse in the given format.

Parameters:
format - the format to use
value - the value to return
filter - the filter to apply
Returns:
a WOResponse in the given format

errorResponse

public com.webobjects.appserver.WOActionResults errorResponse(java.lang.Throwable t,
                                                              int status)
Returns an error response with the given HTTP status.

Parameters:
t - the exception
status - the HTTP status code
Returns:
an error WOResponse

errorResponse

public com.webobjects.appserver.WOActionResults errorResponse(java.lang.String errorMessage,
                                                              int status)
Returns an error response with the given HTTP status.

Parameters:
errorMessage - the error message
status - the HTTP status code
Returns:
an error WOResponse

headAction

public com.webobjects.appserver.WOActionResults headAction()
Returns the response from a HEAD call to this controller.

Returns:
a head response

_takeRouteParametersFromRequest

protected void _takeRouteParametersFromRequest(com.webobjects.appserver.WOActionResults results)
Enumerates the route keys, looks for @ERXRouteParameter annotated methods, and sets the value of the routeKey with the corresponding method if it exists.

Parameters:
results - the results to apply route parameter to

isAutomaticHtmlRoutingEnabled

protected boolean isAutomaticHtmlRoutingEnabled()
If this method returns true, all HTML format requests will be automatically routed to the corresponding IERXRouteComponent implementation based on the name returned by pageNameForAction(String).

Returns:
true if HTML format requests should be automatically routed to the corresponding page component

shouldFailOnMissingHtmlPage

protected boolean shouldFailOnMissingHtmlPage()
If automatic html routing is enabled and there is no page component found that matches the current route, should that result in a 404?

Returns:
whether or not a missing page is a failure

_setEntityName

public void _setEntityName(java.lang.String entityName)
Sets the entity name for this controller.

Parameters:
entityName - this controller's entity name

entityName

protected java.lang.String entityName()
Returns the name of the entity that this controller is currently handling. The default implementation retrieves the entity name from the ERXRoute.

Returns:
the entity name for the current route

pageNameForAction

protected java.lang.String pageNameForAction(java.lang.String actionName)
Returns the name of the page component for this entity and the given action. The default implementation of this returns entityName + Action + Page ("PersonEditPage", "PersonViewPage", etc).

Parameters:
actionName - the name of the action
Returns:
the name of the page component for this action

performUnknownAction

protected com.webobjects.appserver.WOActionResults performUnknownAction(java.lang.String actionName)
                                                                 throws java.lang.Throwable
Called when no standard action method can be found to handle the requested route. The default implementation just throws an exception.

Parameters:
actionName - the unknown action name
Returns:
WOActionResults
Throws:
java.lang.Throwable

performActionNamed

public com.webobjects.appserver.WOActionResults performActionNamed(java.lang.String actionName)
Overrides:
performActionNamed in class com.webobjects.appserver.WODirectAction

responseNodeForActionNamed

public ERXRestRequestNode responseNodeForActionNamed(java.lang.String actionName)
Returns the response node generated from performing the action with the given name.

Parameters:
actionName - the name of the action to perform
Returns:
the response node

responseContentForActionNamed

public java.lang.String responseContentForActionNamed(java.lang.String actionName)
Returns the response content generated from performing the action with the given name.

Parameters:
actionName - the name of the action to perform
Returns:
the response content

performActionNamed

public com.webobjects.appserver.WOActionResults performActionNamed(java.lang.String actionName,
                                                                   boolean throwExceptions)
                                                            throws java.lang.RuntimeException
Performs the given action, optionally throwing exceptions instead of converting to http response codes.

Parameters:
actionName - the name of the action to perform
throwExceptions - whether or not to throw exceptions
Returns:
the action results
Throws:
java.lang.RuntimeException - if a failure occurs

allowWindowNameCrossDomainTransport

protected boolean allowWindowNameCrossDomainTransport()
Returns whether or not the window.name cross-domain transport is allowed.

Returns:
whether or not the window.name cross-domain transport is allowed

accessControlAllowOrigin

protected java.lang.String accessControlAllowOrigin()
Returns the allowed origin for cross-site requests. Set the property ERXRest.accessControlAllowOrigin=* to enable all origins.

Returns:
the allowed origin for cross-site requests

accessControlAllowRequestMethods

protected com.webobjects.foundation.NSArray<java.lang.String> accessControlAllowRequestMethods(java.lang.String requestMethod)
Returns the allowed request methods given the requested method. Set the property ERXRest.accessControlAllowRequestMethods to override the default of returning OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE,CONNECT.

Parameters:
requestMethod - the requested method
Returns:
the array of allowed request methods

accessControlAllowRequestHeaders

protected com.webobjects.foundation.NSArray<java.lang.String> accessControlAllowRequestHeaders(com.webobjects.foundation.NSArray<java.lang.String> requestHeaders)
Returns the allowed request headers given the requested headers.Set the property ERXRest.accessControlAllowRequestHeaders to override the default of just returning the requested headers.

Parameters:
requestHeaders - the requested headers
Returns:
the array of allowed request headers

accessControlMaxAage

protected long accessControlMaxAage()
Returns the maximum age in seconds for the preflight options cache.

Returns:
the maximum age for the preflight options cache

optionsAction

public com.webobjects.appserver.WOActionResults optionsAction()
                                                       throws java.lang.Throwable
A default options action that implements access control policy.

Returns:
the response
Throws:
java.lang.Throwable

pageWithName

public <T extends com.webobjects.appserver.WOComponent> T pageWithName(java.lang.Class<T> componentClass)
Calls pageWithName.

Type Parameters:
T - the type of component to return
Parameters:
componentClass - the component class to lookup
Returns:
the created component

controller

public <T extends ERXRouteController> T controller(java.lang.String entityName)
Returns another controller, passing the required state on.

Type Parameters:
T - the type of controller to return
Parameters:
entityName - the entity name of the controller to lookup
Returns:
the created controller

controller

public <T extends ERXRouteController> T controller(java.lang.Class<T> controllerClass)
Returns another controller, passing the required state on.

Type Parameters:
T - the type of controller to return
Parameters:
controllerClass - the controller class to lookup
Returns:
the created controller

dispose

public void dispose()
Disposes any resources the route controller may be holding onto (like its editing context).


isSchemaRequest

protected boolean isSchemaRequest()
Returns whether or not this request is for a schema.

Returns:
whether or not this request is for a schema

schemaResponse

protected com.webobjects.appserver.WOActionResults schemaResponse(ERXKeyFilter filter)
Returns the schema response for the current entity with the given filter.

Parameters:
filter - the filter to apply
Returns:
the schema response for the current entity with the given filter

schemaResponseForEntityNamed

protected com.webobjects.appserver.WOActionResults schemaResponseForEntityNamed(java.lang.String entityName,
                                                                                ERXKeyFilter filter)
Returns the schema response for the given entity with the given filter.

Parameters:
entityName - the entity name
filter - the filter to apply
Returns:
the schema response for the given entity with the given filter

toString

public java.lang.String toString()
Overrides:
toString in class com.webobjects.appserver.WOAction

_registerControllerForRequest

protected static void _registerControllerForRequest(ERXRouteController controller,
                                                    com.webobjects.appserver.WORequest request)
Registers the given controller with the given request, so it can be later disposed. This can be a very useful performance optimization for apps that gets a large number of requests.

Parameters:
controller - the controller to register
request - the request to register with

_controllersForRequest

public static com.webobjects.foundation.NSMutableArray<ERXRouteController> _controllersForRequest(com.webobjects.appserver.WORequest request)
Returns the controllers that have been used on the given request.

Parameters:
request - the request

_disposeControllersForRequest

public static void _disposeControllersForRequest(com.webobjects.appserver.WORequest request)
Disposes all of the controllers that were used on the given request.

Parameters:
request - the request

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.