com.scooterframework.web.util
Class R

java.lang.Object
  extended by com.scooterframework.web.util.R

public class R
extends java.lang.Object

R(RestfulHelper) class has helper methods for routes and resources.


Constructor Summary
R()
           
 
Method Summary
static java.lang.String addNestedResourcePath(java.lang.String[] parentResourceNames, java.lang.Object[] parentRestfuls, java.lang.String resourceName)
           
static java.lang.String addNestedResourcePath(java.lang.String parentResourceName, RESTified parentRecord, java.lang.String resourceName)
           
static java.lang.String addNestedResourcePath(java.lang.String parentResourceName, java.lang.String parentRestfulId, java.lang.String resourceName)
           
static java.lang.String addResourcePath(java.lang.String resourceName)
          Returns resource path for adding a record.
static java.lang.String editNestedResourceRecordPath(java.lang.String[] parentResourceNames, java.lang.Object[] parentRestfuls, java.lang.String resourceName, RESTified record)
           
static java.lang.String editNestedResourceRecordPath(java.lang.String[] parentResourceNames, java.lang.Object[] parentRestfuls, java.lang.String resourceName, java.lang.String resourceId)
           
static java.lang.String editNestedResourceRecordPath(java.lang.String parentResourceName, RESTified parentRecord, java.lang.String resourceName, RESTified record)
           
static java.lang.String editNestedResourceRecordPath(java.lang.String parentResourceName, RESTified parentRecord, java.lang.String resourceName, java.lang.String resourceId)
           
static java.lang.String editNestedResourceRecordPath(java.lang.String parentResourceName, java.lang.String parentRestfulId, java.lang.String resourceName, RESTified record)
           
static java.lang.String editNestedResourceRecordPath(java.lang.String parentResourceName, java.lang.String parentRestfulId, java.lang.String resourceName, java.lang.String resourceId)
           
static java.lang.String editResourceRecordPath(java.lang.String resourceName, RESTified record)
          Returns resource path for editing a record.
static java.lang.String editResourceRecordPath(java.lang.String resourceName, java.lang.String resourceId)
          Returns resource path for editing a specific resource.
static java.lang.String formForAddNestedResource(java.lang.String[] parentResourceNames, java.lang.Object[] parentRestfuls, java.lang.String resourceName)
           
static java.lang.String formForAddNestedResource(java.lang.String parentResourceName, RESTified parentRecord, java.lang.String resourceName)
           
static java.lang.String formForAddNestedResource(java.lang.String parentResourceName, java.lang.String parentRestfulId, java.lang.String resourceName)
           
static java.lang.String formForAddResource(java.lang.String resourceName)
          Returns form element for adding a resource record.
static java.lang.String formForEditNestedResourceRecord(java.lang.String[] parentResourceNames, java.lang.Object[] parentRestfuls, java.lang.String resourceName, RESTified record)
           
static java.lang.String formForEditNestedResourceRecord(java.lang.String[] parentResourceNames, java.lang.Object[] parentRestfuls, java.lang.String resourceName, java.lang.String resourceId)
           
static java.lang.String formForEditNestedResourceRecord(java.lang.String parentResourceName, RESTified parentRecord, java.lang.String resourceName, RESTified record)
           
static java.lang.String formForEditNestedResourceRecord(java.lang.String parentResourceName, RESTified parentRecord, java.lang.String resourceName, java.lang.String resourceId)
           
static java.lang.String formForEditNestedResourceRecord(java.lang.String parentResourceName, java.lang.String parentRestfulId, java.lang.String resourceName, RESTified record)
           
static java.lang.String formForEditNestedResourceRecord(java.lang.String parentResourceName, java.lang.String parentRestfulId, java.lang.String resourceName, java.lang.String resourceId)
           
static java.lang.String formForEditResourceRecord(java.lang.String resourceName, RESTified record)
          Returns form element for editing a resource record.
static java.lang.String formForEditResourceRecord(java.lang.String resourceName, java.lang.String resourceId)
          Returns form element for editing a specific resource.
static java.lang.String formForNestedResourceRecord(java.lang.String[] parentResourceNames, java.lang.Object[] parentRestfuls, java.lang.String resourceName, RESTified record)
          Returns form element for a nested resource.
static java.lang.String formForNestedResourceRecord(java.lang.String[] parentResourceNames, java.lang.Object[] parentRestfuls, java.lang.String resourceName, java.lang.String restfulId)
          Returns form element for a nested resource.
static java.lang.String formForNestedResourceRecord(java.lang.String parentResourceName, RESTified parentRecord, java.lang.String resourceName, RESTified record)
          Returns form element for a nested resource.
static java.lang.String formForNestedResourceRecord(java.lang.String parentResourceName, RESTified parentRecord, java.lang.String resourceName, java.lang.String restfulId)
          Returns form element for a nested resource.
static java.lang.String formForNestedResourceRecord(java.lang.String parentResourceName, java.lang.String parentRestfulId, java.lang.String resourceName, RESTified record)
          Returns form element for a nested resource.
static java.lang.String formForNestedResourceRecord(java.lang.String parentResourceName, java.lang.String parentRestfulId, java.lang.String resourceName, java.lang.String restfulId)
          Returns form element for a nested resource.
static java.lang.String formForResource(java.lang.String resourceName, RESTified record)
          Returns form element for a resource.
static java.lang.String formForResource(java.lang.String resourceName, java.lang.String restfulId)
          Returns form element for a resource.
static java.lang.String nestedResourcePath(java.lang.String[] parentResourceNames, java.lang.Object[] parentRestfuls, java.lang.String resourceName)
           
static java.lang.String nestedResourcePath(java.lang.String parentResourceName, RESTified parentRecord, java.lang.String resourceName)
           
static java.lang.String nestedResourcePath(java.lang.String parentResourceName, java.lang.String parentRestfulId, java.lang.String resourceName)
           
static java.lang.String nestedResourceRecordPath(java.lang.String[] parentResourceNames, java.lang.Object[] parentRestfuls, java.lang.String resourceName, RESTified record)
           
static java.lang.String nestedResourceRecordPath(java.lang.String[] parentResourceNames, java.lang.Object[] parentRestfuls, java.lang.String resourceName, java.lang.String resourceId)
           
static java.lang.String nestedResourceRecordPath(java.lang.String parentResourceName, RESTified parentRecord, java.lang.String resourceName, RESTified record)
           
static java.lang.String nestedResourceRecordPath(java.lang.String parentResourceName, RESTified parentRecord, java.lang.String resourceName, java.lang.String resourceId)
           
static java.lang.String nestedResourceRecordPath(java.lang.String parentResourceName, java.lang.String parentRestfulId, java.lang.String resourceName, RESTified record)
           
static java.lang.String nestedResourceRecordPath(java.lang.String parentResourceName, java.lang.String parentRestfulId, java.lang.String resourceName, java.lang.String resourceId)
           
static Resource resource(java.lang.String resourceName)
          Returns resource.
static Resource resourceForModel(java.lang.String model)
          Returns resource corresponding to a model name.
static java.lang.String resourcePath(java.lang.String resourceName)
          Returns resource path based on resource name.
static java.lang.String resourceRecordPath(java.lang.String resourceName, RESTified record)
          Returns a resource path.
static java.lang.String resourceRecordPath(java.lang.String resourceName, java.lang.String resourceId)
          Returns a resource path for a specific resource.
static Route route(java.lang.String routeName)
          Returns route.
static java.lang.String routePath(java.lang.String routeName)
          Returns route path based on a route name.
static java.lang.String routeRecordPath(java.lang.String routeName, RESTified record)
          Returns route path based on a record instance.
static java.lang.String simpleForeignKeyResourceRecordLink(java.lang.String columnName, java.lang.String columnValue)
          Returns a label link on the columnName for columnValue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

R

public R()
Method Detail

resource

public static Resource resource(java.lang.String resourceName)
Returns resource.

Parameters:
resourceName - name of the resource
Returns:
resource

resourceForModel

public static Resource resourceForModel(java.lang.String model)
Returns resource corresponding to a model name.

Parameters:
model - model name
Returns:
resource

resourcePath

public static java.lang.String resourcePath(java.lang.String resourceName)

Returns resource path based on resource name.

For example, for resource "posts", the resource path may be "/posts".

Parameters:
resourceName - name of the resource
Returns:
resource path

resourceRecordPath

public static java.lang.String resourceRecordPath(java.lang.String resourceName,
                                                  RESTified record)

Returns a resource path. If the record's RESTful id is empty, an empty string is returned.

For example, for record "Post" with post.id=1, the resource path may be "/posts/1".

Parameters:
resourceName - resource name
record - a restified record
Returns:
resource path

resourceRecordPath

public static java.lang.String resourceRecordPath(java.lang.String resourceName,
                                                  java.lang.String resourceId)

Returns a resource path for a specific resource. If the resourceId is empty, an empty string is returned.

For example, for record "Post" with post.id=1, the resource path may be "/posts/1".

Parameters:
resourceName - resource name
resourceId - a specific resource
Returns:
resource path

addResourcePath

public static java.lang.String addResourcePath(java.lang.String resourceName)
Returns resource path for adding a record. For example, for adding a new record "Post", the resource path may be "/posts/add".

Parameters:
resourceName - name of the resource
Returns:
resource path for adding a new record

editResourceRecordPath

public static java.lang.String editResourceRecordPath(java.lang.String resourceName,
                                                      RESTified record)

Returns resource path for editing a record. If the record's RESTful id is empty, an empty string is returned.

For example, for editing a record "Post" with post.id=1, the resource path may be "/posts/1/edit".

Parameters:
resourceName - resource name
record - a restified record
Returns:
resource path for editing a new record

editResourceRecordPath

public static java.lang.String editResourceRecordPath(java.lang.String resourceName,
                                                      java.lang.String resourceId)

Returns resource path for editing a specific resource. If the resourceId is empty, an empty string is returned.

For example, for editing a record "Post" with post.id=1, the resource path may be "/posts/1/edit".

Parameters:
resourceName - resource name
resourceId - a specific resource
Returns:
resource path for editing a new record

formForResource

public static java.lang.String formForResource(java.lang.String resourceName,
                                               java.lang.String restfulId)
Returns form element for a resource.

Parameters:
resourceName - name of the resource
restfulId - a specific object in the resource
Returns:
form element for a resource record

formForResource

public static java.lang.String formForResource(java.lang.String resourceName,
                                               RESTified record)
Returns form element for a resource.

Parameters:
resourceName - name of the resource
record - a restified record
Returns:
form element for a resource record

formForNestedResourceRecord

public static java.lang.String formForNestedResourceRecord(java.lang.String parentResourceName,
                                                           RESTified parentRecord,
                                                           java.lang.String resourceName,
                                                           RESTified record)
Returns form element for a nested resource.

Parameters:
parentResourceName - name of parent resource
parentRecord - parent restified record
resourceName - name of the resource
record - a restified record
Returns:
form element for a resource record

formForNestedResourceRecord

public static java.lang.String formForNestedResourceRecord(java.lang.String parentResourceName,
                                                           java.lang.String parentRestfulId,
                                                           java.lang.String resourceName,
                                                           RESTified record)
Returns form element for a nested resource.

Parameters:
parentResourceName - name of parent resource
parentRestfulId - parent restful id
resourceName - name of the resource
record - a restified record
Returns:
form element for a resource record

formForNestedResourceRecord

public static java.lang.String formForNestedResourceRecord(java.lang.String[] parentResourceNames,
                                                           java.lang.Object[] parentRestfuls,
                                                           java.lang.String resourceName,
                                                           RESTified record)
Returns form element for a nested resource. parentResourceNames is an array of ancestors. parentRestfuls is an array of either restful id strings or RESTified records of ancestors.

Parameters:
parentResourceNames - names of parent resources
parentRestfuls - parent restfuls
resourceName - name of the resource
record - a restified record
Returns:
form element for a resource record

formForNestedResourceRecord

public static java.lang.String formForNestedResourceRecord(java.lang.String parentResourceName,
                                                           RESTified parentRecord,
                                                           java.lang.String resourceName,
                                                           java.lang.String restfulId)
Returns form element for a nested resource.

Parameters:
parentResourceName - name of parent resource
parentRecord - parent restified record
resourceName - name of the resource
restfulId - restful id
Returns:
form element for a resource record

formForNestedResourceRecord

public static java.lang.String formForNestedResourceRecord(java.lang.String parentResourceName,
                                                           java.lang.String parentRestfulId,
                                                           java.lang.String resourceName,
                                                           java.lang.String restfulId)
Returns form element for a nested resource.

Parameters:
parentResourceName - name of parent resource
parentRestfulId - parent restful id
resourceName - name of the resource
restfulId - restful id
Returns:
form element for a resource record

formForNestedResourceRecord

public static java.lang.String formForNestedResourceRecord(java.lang.String[] parentResourceNames,
                                                           java.lang.Object[] parentRestfuls,
                                                           java.lang.String resourceName,
                                                           java.lang.String restfulId)
Returns form element for a nested resource. parentResourceNames is an array of ancestors. parentRestfuls is an array of either restful id strings or RESTified records of ancestors.

Parameters:
parentResourceNames - names of parent resources
parentRestfuls - parent restfuls
resourceName - name of the resource
restfulId - restful id
Returns:
form element for a resource record

formForAddResource

public static java.lang.String formForAddResource(java.lang.String resourceName)
Returns form element for adding a resource record.

Parameters:
resourceName - name of the resource
Returns:
form element for adding a resource record

formForEditResourceRecord

public static java.lang.String formForEditResourceRecord(java.lang.String resourceName,
                                                         RESTified record)
Returns form element for editing a resource record.

Parameters:
resourceName - resource name
record - a restified record
Returns:
form element for editing a resource record

formForEditResourceRecord

public static java.lang.String formForEditResourceRecord(java.lang.String resourceName,
                                                         java.lang.String resourceId)
Returns form element for editing a specific resource.

Parameters:
resourceName - resource name
resourceId - a specific resource
Returns:
form element for editing a resource record

nestedResourcePath

public static java.lang.String nestedResourcePath(java.lang.String parentResourceName,
                                                  RESTified parentRecord,
                                                  java.lang.String resourceName)

nestedResourcePath

public static java.lang.String nestedResourcePath(java.lang.String parentResourceName,
                                                  java.lang.String parentRestfulId,
                                                  java.lang.String resourceName)

nestedResourcePath

public static java.lang.String nestedResourcePath(java.lang.String[] parentResourceNames,
                                                  java.lang.Object[] parentRestfuls,
                                                  java.lang.String resourceName)

nestedResourceRecordPath

public static java.lang.String nestedResourceRecordPath(java.lang.String parentResourceName,
                                                        RESTified parentRecord,
                                                        java.lang.String resourceName,
                                                        RESTified record)

nestedResourceRecordPath

public static java.lang.String nestedResourceRecordPath(java.lang.String parentResourceName,
                                                        java.lang.String parentRestfulId,
                                                        java.lang.String resourceName,
                                                        RESTified record)

nestedResourceRecordPath

public static java.lang.String nestedResourceRecordPath(java.lang.String parentResourceName,
                                                        RESTified parentRecord,
                                                        java.lang.String resourceName,
                                                        java.lang.String resourceId)

nestedResourceRecordPath

public static java.lang.String nestedResourceRecordPath(java.lang.String parentResourceName,
                                                        java.lang.String parentRestfulId,
                                                        java.lang.String resourceName,
                                                        java.lang.String resourceId)

nestedResourceRecordPath

public static java.lang.String nestedResourceRecordPath(java.lang.String[] parentResourceNames,
                                                        java.lang.Object[] parentRestfuls,
                                                        java.lang.String resourceName,
                                                        RESTified record)

nestedResourceRecordPath

public static java.lang.String nestedResourceRecordPath(java.lang.String[] parentResourceNames,
                                                        java.lang.Object[] parentRestfuls,
                                                        java.lang.String resourceName,
                                                        java.lang.String resourceId)

addNestedResourcePath

public static java.lang.String addNestedResourcePath(java.lang.String parentResourceName,
                                                     RESTified parentRecord,
                                                     java.lang.String resourceName)

addNestedResourcePath

public static java.lang.String addNestedResourcePath(java.lang.String parentResourceName,
                                                     java.lang.String parentRestfulId,
                                                     java.lang.String resourceName)

addNestedResourcePath

public static java.lang.String addNestedResourcePath(java.lang.String[] parentResourceNames,
                                                     java.lang.Object[] parentRestfuls,
                                                     java.lang.String resourceName)

editNestedResourceRecordPath

public static java.lang.String editNestedResourceRecordPath(java.lang.String parentResourceName,
                                                            RESTified parentRecord,
                                                            java.lang.String resourceName,
                                                            RESTified record)

editNestedResourceRecordPath

public static java.lang.String editNestedResourceRecordPath(java.lang.String parentResourceName,
                                                            RESTified parentRecord,
                                                            java.lang.String resourceName,
                                                            java.lang.String resourceId)

editNestedResourceRecordPath

public static java.lang.String editNestedResourceRecordPath(java.lang.String parentResourceName,
                                                            java.lang.String parentRestfulId,
                                                            java.lang.String resourceName,
                                                            RESTified record)

editNestedResourceRecordPath

public static java.lang.String editNestedResourceRecordPath(java.lang.String parentResourceName,
                                                            java.lang.String parentRestfulId,
                                                            java.lang.String resourceName,
                                                            java.lang.String resourceId)

editNestedResourceRecordPath

public static java.lang.String editNestedResourceRecordPath(java.lang.String[] parentResourceNames,
                                                            java.lang.Object[] parentRestfuls,
                                                            java.lang.String resourceName,
                                                            RESTified record)

editNestedResourceRecordPath

public static java.lang.String editNestedResourceRecordPath(java.lang.String[] parentResourceNames,
                                                            java.lang.Object[] parentRestfuls,
                                                            java.lang.String resourceName,
                                                            java.lang.String resourceId)

formForAddNestedResource

public static java.lang.String formForAddNestedResource(java.lang.String parentResourceName,
                                                        RESTified parentRecord,
                                                        java.lang.String resourceName)

formForAddNestedResource

public static java.lang.String formForAddNestedResource(java.lang.String parentResourceName,
                                                        java.lang.String parentRestfulId,
                                                        java.lang.String resourceName)

formForAddNestedResource

public static java.lang.String formForAddNestedResource(java.lang.String[] parentResourceNames,
                                                        java.lang.Object[] parentRestfuls,
                                                        java.lang.String resourceName)

formForEditNestedResourceRecord

public static java.lang.String formForEditNestedResourceRecord(java.lang.String parentResourceName,
                                                               RESTified parentRecord,
                                                               java.lang.String resourceName,
                                                               RESTified record)

formForEditNestedResourceRecord

public static java.lang.String formForEditNestedResourceRecord(java.lang.String parentResourceName,
                                                               RESTified parentRecord,
                                                               java.lang.String resourceName,
                                                               java.lang.String resourceId)

formForEditNestedResourceRecord

public static java.lang.String formForEditNestedResourceRecord(java.lang.String parentResourceName,
                                                               java.lang.String parentRestfulId,
                                                               java.lang.String resourceName,
                                                               RESTified record)

formForEditNestedResourceRecord

public static java.lang.String formForEditNestedResourceRecord(java.lang.String parentResourceName,
                                                               java.lang.String parentRestfulId,
                                                               java.lang.String resourceName,
                                                               java.lang.String resourceId)

formForEditNestedResourceRecord

public static java.lang.String formForEditNestedResourceRecord(java.lang.String[] parentResourceNames,
                                                               java.lang.Object[] parentRestfuls,
                                                               java.lang.String resourceName,
                                                               RESTified record)

formForEditNestedResourceRecord

public static java.lang.String formForEditNestedResourceRecord(java.lang.String[] parentResourceNames,
                                                               java.lang.Object[] parentRestfuls,
                                                               java.lang.String resourceName,
                                                               java.lang.String resourceId)

route

public static Route route(java.lang.String routeName)
Returns route.

Parameters:
routeName - route name
Returns:
route

routePath

public static java.lang.String routePath(java.lang.String routeName)
Returns route path based on a route name. For example, for named route "login", the route path may be "/login".

Parameters:
routeName - route name
Returns:
route path

routeRecordPath

public static java.lang.String routeRecordPath(java.lang.String routeName,
                                               RESTified record)

Returns route path based on a record instance. If the record's RESTful id is empty, an empty string is returned.

For example, for record "Post" with post.getRestfulId()=1, the route path is "/posts/1".

Parameters:
routeName - route name
record - a restified record
Returns:
route path

simpleForeignKeyResourceRecordLink

public static java.lang.String simpleForeignKeyResourceRecordLink(java.lang.String columnName,
                                                                  java.lang.String columnValue)

Returns a label link on the columnName for columnValue.

There are several restrictions of the use of this method.

First, the column name must be of the '{referencedModelName}_id' format where the referencedModelName is the model name of the referenced entity. Second, the primary key of the referenced model must be id.

If the above conditions are violated, the original columnName is returned.

 Examples:
      column    value    link
      ------    -----    ----
      user_id   10       10
 

See method W.simpleForeignKeyRecordShowActionLink(String, String) for action (non resource) case.

Parameters:
columnName - a column name ended with "_id"
columnValue - the value on the column
Returns:
a label link