Serves the response for a single request matched against a ControllerMapping, running the mapping's JS handler function for the request method and rendering the result with the configured or returned view. Created by ControllerResource.create when a controller mapping is located for the requested path. Scripts invoked from a ControllerResource have access to global variables including controllerMappings, views (a ViewsBuilder), formatter, log, applications, transactionManager (an AppTransactionManager), and fileManager (a FileManager).
Group: Resources
Extends: AbstractResource
Implements: GetableResource, PostableResource, ReplaceableResource, DeletableResource, TitledPage, HashResource, SeoResource
Properties
| Property | Returns | Description |
|---|---|---|
| appSettings | Map<String,String> | The configuration settings of the owning repository app for the current organisation and branch, lazily loaded and cached on first access. |
| breadCrumbs | Map | The breadcrumb trail for this resource, either taken directly from the controller mapping's configured breadcrumb map or computed by running its breadcrumb function. |
| controllerMappings | ControllerMappingList | The full set of controller mappings registered by the owning app, of which this resource's mapping is one. |
| currentUser | UserResource | Returns the currently authenticated user for this request. |
| hash | String | A hash identifying the current content of this resource, taken from the view resolved for a GET request if that view is a FileHashView. |
| href | String | The URL path this resource was resolved from. |
| method | ControllerMethod | The controller method resolved for the current request's HTTP method, used to run the matching JS handler and select the response view. |
| modifiedDate | Date | The last modified date of this resource, computed by running the controller mapping's modified-date function if one is configured, otherwise delegating to the superclass. |
| name | String | The final path segment of this resource's path. |
| parent | CommonCollectionResource | The root folder this resource was resolved within. |
| path | Path | The Milton path this resource was resolved from. |
| pathParams | Map<String,Object> | The named path parameters extracted from matching this resource's URL against its controller mapping's path pattern, for example an id captured from a path segment. |
| public | boolean | Whether this resource can be accessed without authentication, taken from its controller mapping. |
| repoAppName | String | The instance id of the repository app that registered the controller mapping serving this resource. |
| rolePrivs | Map<String,List<Priviledge>> | The privileges granted to each role by this resource's controller mapping, used by appendPriviledges to calculate a user's effective privileges. |
| seoContent | SeoContentBean | SEO metadata for this resource, populated by running the controller mapping's SEO content function if one is configured. |
| sourceTenantId | long | The id of the organisation that owns this resource, taken from the resource's root folder. |
| title | String | The title of this resource, computed by running the controller mapping's title function if one is configured, falling back to the selected view's title if it implements TitledView, and finally to the resource's name. |
| types | Set<String> | The resource type tags applied to this resource's controller mapping, for example html. |
| uniqueId | String | A unique id for this resource, computed by running the controller mapping's unique-id function if one is configured, otherwise delegating to the superclass. |
| websiteName | String | The name of the website this resource belongs to. |
Inherited from AbstractResource
Properties
| Property | Returns | Description |
|---|---|---|
| accessControlList | Map<Principal,List<Priviledge>> | The access control list of allowed privileges per principal for this resource. This implementation is not populated; access is instead resolved dynamically via the security manager, so this always returns null. |
| asList | ResourceList | This resource wrapped as a single-element ResourceList, convenient for scripts that want to treat a single resource the same way as a list of resources. |
| attributes | Map<String,Object> | A mutable, request-scoped map of arbitrary attributes attached to this resource instance, for passing values between code that shares a reference to the same resource. |
| createDate | Date | The date this resource was created. This base implementation always returns null; subclasses that track creation dates override it. |
| dir | boolean | Whether this resource is a collection (folder-like) resource rather than a single item. |
| link | String | A ready-to-use HTML anchor tag linking to this resource's href, using its name as the link text. |
| oAuth2Providers | Map<String,OAuth2Provider> | The OAuth2 login providers available for this resource, combining the providers configured on the social login app with the platform's built-in social posting services mapped onto their OAuth2 provider templates. |
| principalCollectionHrefs | HrefList | The hrefs of the collections that contain principals, so a WebDAV client can discover where to list users. This base implementation always returns the single href "/users/". |
| principalURL | String | The href of the owning principal resource for this resource, found by walking up the parent chain to the nearest principal resource. |
| readable | boolean | Whether the current user, who may be null for an anonymous request, has READ_CONTENT permission on this resource. |
| realm | String | The HTTP authentication realm used for digest and basic authentication challenges on this resource. |
| writable | boolean | Whether the current user, who may be null for an anonymous request, has WRITE_CONTENT permission on this resource. |
Methods
getRealm() · getPrincipalURL() · getPrincipalCollectionHrefs() · getLink() · find(String path) · find(Path p) · isDir() · getContentType(String accepts) · getCreateDate() · getAccessControlList() · closest(String type) · closest(Class<T> c) · isReadable() · isWritable() · getAsList() · getOAuth2Providers() · getAttributes()
getRealm()
Returns: String
The HTTP authentication realm used for digest and basic authentication challenges on this resource.
getPrincipalURL()
Returns: String
The href of the owning principal resource for this resource, found by walking up the parent chain to the nearest principal resource.
getPrincipalCollectionHrefs()
Returns: HrefList
The hrefs of the collections that contain principals, so a WebDAV client can discover where to list users. This base implementation always returns the single href "/users/".
getLink()
Returns: String
A ready-to-use HTML anchor tag linking to this resource's href, using its name as the link text.
find(String path)
Returns: Resource
Finds a resource within the website by its path. A relative path is evaluated relative to this resource; an absolute path is evaluated from the website root. For example find("/programs/p1") looks up the program p1 from the root, and find("../p1") looks up p1 in the folder above this resource.
| Parameter | Description |
|---|---|
path | the relative or absolute path to resolve |
find(Path p)
Returns: Resource
Finds a resource by walking a Path object one part at a time, following "." and ".." segments and looking up each remaining part as a child of the current resource.
| Parameter | Description |
|---|---|
p | the path to resolve, relative to this resource or absolute |
isDir()
Returns: boolean
Whether this resource is a collection (folder-like) resource rather than a single item.
getContentType(String accepts)
Returns: String
The content type this resource should be served as. This base implementation always returns "text/html; charset=UTF-8" for getable resources (regardless of the accepts header, since XHTML is not used because of CKEditor compatibility) and an empty string otherwise. Subclasses override this where a different content type is needed.
| Parameter | Description |
|---|---|
accepts | the client's Accept header value, currently not used to vary the result |
getCreateDate()
Returns: Date
The date this resource was created. This base implementation always returns null; subclasses that track creation dates override it.
getAccessControlList()
Returns: Map<Principal,List<Priviledge>>
The access control list of allowed privileges per principal for this resource. This implementation is not populated; access is instead resolved dynamically via the security manager, so this always returns null.
closest(String type)
Returns: CommonResource
Finds the closest resource, starting from this one and walking up through its parents, whose is(type) returns true.
| Parameter | Description |
|---|---|
type | the type name to match, as used by is(String) |
closest(Class<T> c)
Returns: T
Finds the closest resource, starting from this one and walking up through its parents, that is an instance of the given class.
| Parameter | Description |
|---|---|
c | the class to match against |
isReadable()
Returns: boolean
Whether the current user, who may be null for an anonymous request, has READ_CONTENT permission on this resource.
isWritable()
Returns: boolean
Whether the current user, who may be null for an anonymous request, has WRITE_CONTENT permission on this resource.
getAsList()
Returns: ResourceList
This resource wrapped as a single-element ResourceList, convenient for scripts that want to treat a single resource the same way as a list of resources.
getOAuth2Providers()
Returns: Map<String,OAuth2Provider>
The OAuth2 login providers available for this resource, combining the providers configured on the social login app with the platform's built-in social posting services mapped onto their OAuth2 provider templates.
getAttributes()
Returns: Map<String,Object>
A mutable, request-scoped map of arbitrary attributes attached to this resource instance, for passing values between code that shares a reference to the same resource.
Methods
getSourceTenantId() · getRepoAppName() · setMenuActive() · getHash() · isPublic() · getWebsiteName() · getCurrentUser() · getParent() · getName() · getTitle() · getModifiedDate() · getUniqueId() · getPathParams() · getMethod() · getAppSettings() · getSeoContent() · jsonView(Object jsonObject) · templateView(String template) · jsonResult(boolean result) · jsonResult(boolean result, String message) · jsonResult(boolean result, String message, String nextHref) · getHref() · getPath() · throwNotFound(String reason) · throwBadRequest(String reason) · throwNotAuthorized(String reason) · getControllerMappings() · dataBind(Object target, Map params) · getTypes() · getBreadCrumbs() · getRolePrivs()
getSourceTenantId()
Returns: long
The id of the organisation that owns this resource, taken from the resource's root folder.
getRepoAppName()
Returns: String
The instance id of the repository app that registered the controller mapping serving this resource.
setMenuActive()
Returns: void
Marks the menu item matching this resource's mapping, or failing that its href, as active for the current request, so the rendered page can highlight the current position in the navigation menu.
getHash()
Returns: String
A hash identifying the current content of this resource, taken from the view resolved for a GET request if that view is a FileHashView.
isPublic()
Returns: boolean
Whether this resource can be accessed without authentication, taken from its controller mapping.
getWebsiteName()
Returns: String
The name of the website this resource belongs to.
getCurrentUser()
Returns: UserResource
Returns the currently authenticated user for this request.
getParent()
Returns: CommonCollectionResource
The root folder this resource was resolved within.
getName()
Returns: String
The final path segment of this resource's path.
getTitle()
Returns: String
The title of this resource, computed by running the controller mapping's title function if one is configured, falling back to the selected view's title if it implements TitledView, and finally to the resource's name.
getModifiedDate()
Returns: Date
The last modified date of this resource, computed by running the controller mapping's modified-date function if one is configured, otherwise delegating to the superclass.
getUniqueId()
Returns: String
A unique id for this resource, computed by running the controller mapping's unique-id function if one is configured, otherwise delegating to the superclass.
getPathParams()
Returns: Map<String,Object>
The named path parameters extracted from matching this resource's URL against its controller mapping's path pattern, for example an id captured from a path segment.
getMethod()
Returns: ControllerMethod
The controller method resolved for the current request's HTTP method, used to run the matching JS handler and select the response view.
getAppSettings()
Returns: Map<String,String>
The configuration settings of the owning repository app for the current organisation and branch, lazily loaded and cached on first access.
getSeoContent()
Returns: SeoContentBean
SEO metadata for this resource, populated by running the controller mapping's SEO content function if one is configured.
jsonView(Object jsonObject)
Returns: JsonView
Creates a view which serialises the given object to JSON. If the object is already a JsonResult it is wrapped as-is.
| Parameter | Description |
|---|---|
jsonObject | the object to serialise as the response body |
templateView(String template)
Returns: TemplateView
Creates a view which renders the given template.
| Parameter | Description |
|---|---|
template | the path of the template to render |
jsonResult(boolean result)
Returns: JsonView
Creates a view which renders a simple JSON result with the given success flag.
| Parameter | Description |
|---|---|
result | true if the operation succeeded, false otherwise |
jsonResult(boolean result, String message)
Returns: JsonView
Creates a view which renders a JSON result with the given success flag and message.
| Parameter | Description |
|---|---|
result | true if the operation succeeded, false otherwise |
message | a message describing the result |
jsonResult(boolean result, String message, String nextHref)
Returns: JsonView
Creates a view which renders a JSON result with the given success flag, message, and a href the client should navigate to next.
| Parameter | Description |
|---|---|
result | true if the operation succeeded, false otherwise |
message | a message describing the result |
nextHref | the href the client should navigate to next |
getHref()
Returns: String
The URL path this resource was resolved from.
getPath()
Returns: Path
The Milton path this resource was resolved from.
throwNotFound(String reason)
Returns: void
Raises a not-found error, for a controller script to signal that the requested item does not exist.
| Parameter | Description |
|---|---|
reason | a message explaining what could not be found |
throwBadRequest(String reason)
Returns: void
Raises a bad-request error, for a controller script to signal that the request is invalid.
| Parameter | Description |
|---|---|
reason | a message explaining why the request is invalid |
throwNotAuthorized(String reason)
Returns: void
Raises a not-authorized error, for a controller script to signal that the current user cannot perform the requested action.
| Parameter | Description |
|---|---|
reason | a message explaining why the request is not authorized |
getControllerMappings()
Returns: ControllerMappingList
The full set of controller mappings registered by the owning app, of which this resource's mapping is one.
dataBind(Object target, Map params)
Returns: void
Populates the given target object's properties from the given request parameters, then saves it: as a Hibernate entity if it is one, or by calling save on it if it is a JsonDocumentResource.
| Parameter | Description |
|---|---|
target | the object to populate and save, must not be null |
params | the request parameters to bind onto target |
getTypes()
Returns: Set<String>
The resource type tags applied to this resource's controller mapping, for example html.
getBreadCrumbs()
Returns: Map
The breadcrumb trail for this resource, either taken directly from the controller mapping's configured breadcrumb map or computed by running its breadcrumb function.
getRolePrivs()
Returns: Map<String,List<Priviledge>>
The privileges granted to each role by this resource's controller mapping, used by appendPriviledges to calculate a user's effective privileges.