Represents a file, such as an image, video, or HTML page, within a website or admin content branch. For a HTML page it also parses and exposes structured content such as the title, body and script parameters embedded in the page markup, and supports templated rendering, in-place editing and posted form updates to those properties.

Group: Resources

Extends: AbstractContentResource

Implements: ReplaceableResource, ParameterisedResource, ContentResource, HashResource, PostableResource, TextResource, IVoucherResource


Properties

PropertyReturnsDescription
aBitStringReads a small leading fragment of this file's content (the first 30 bytes), used to sniff whether the file starts with a DOCTYPE declaration. Returns null if the content could not be read.
bodyStringThe body content of the HTML page, if this resource is a HTML page.
contentManagedPermissionsbooleanWhether this resource's permissions are managed as content permissions. Always true for a FileResource.
cssPathsList<String>Lists the CSS file paths that apply when rendering this resource, resolved from the current theme and template.
dirbooleanWhether this resource is a directory. Always false for a FileResource.
fileNodeFileNodeThe underlying data node this resource is backed by, which provides access to the file's raw content and hash.
glyphiconStringA Bootstrap glyphicon CSS class name suited to this file's content type - an expand icon for video, a picture icon for images, and a generic file icon otherwise.
htmlRenderFileResourceReturns a HTML renderable view of this file if it is a suitable type - a HTML file without a doctype declaration, since a doctype indicates plain, unrendered HTML. The result is computed once and cached.
paramNamesList<String>Lists the names of all the script parameters defined in this page's head section, if it is a HTML page.
sourceTenantIdlongThe id of the tenant organisation that owns this file's content.
textContentStringReturns all of the raw text content of this resource, decoded as UTF-8. For a HTML page this is the raw HTML markup, not the rendered output.
themeResourcebooleanChecks whether this file lives under a website's theme directory, by walking up its parent directories looking for a folder named "theme" directly inside a website branch resource.
titleStringThe title from the HTML page, if there is one. Otherwise the resource's file name.
underlyingContentTypeStringThe content type of this resource's underlying stored data, inferred from its file name and invariant with respect to the current request. This differs from getContentType, which may transform the response for a particular request, for example to JSON.
websiteBranchWebsiteBranchResourceWalks up this resource's ancestors to find the nearest one that can report a domain name - a ManageWebsiteBranchFolder when viewed in the admin console, or a WebsiteRootFolder when viewed on a website.

Methods

getSourceTenantId() · getCssPaths() · getUnderlyingContentType() · isDir() · getHtml() · parseHtml() · hasDocType() · getABit() · getTitle() · getBody() · getParam(String name) · setParam(String name, String value) · getParamNames() · doSaveHtml() · doSaveHtml(boolean runTidy) · getFileNode() · is(String type) · getTextContent() · getWebsiteBranch() · getGlyphicon() · isContentManagedPermissions() · isThemeResource()

getSourceTenantId()

Returns: long

The id of the tenant organisation that owns this file's content.

getCssPaths()

Returns: List<String>

Lists the CSS file paths that apply when rendering this resource, resolved from the current theme and template.

getUnderlyingContentType()

Returns: String

The content type of this resource's underlying stored data, inferred from its file name and invariant with respect to the current request. This differs from getContentType, which may transform the response for a particular request, for example to JSON.

isDir()

Returns: boolean

Whether this resource is a directory. Always false for a FileResource.

getHtml()

Returns: RenderFileResource

Returns a HTML renderable view of this file if it is a suitable type - a HTML file without a doctype declaration, since a doctype indicates plain, unrendered HTML. The result is computed once and cached.

parseHtml()

Returns: RenderFileResource

Returns a HTML renderable view of this file, parsing it as HTML regardless of whether it has a doctype declaration. Unlike getHtml, this does not skip files that would otherwise be treated as plain HTML.

hasDocType()

Returns: boolean

Checks whether this file's content begins with a DOCTYPE declaration, which indicates it should be treated as plain, unrendered HTML rather than a templated page.

getABit()

Returns: String

Reads a small leading fragment of this file's content (the first 30 bytes), used to sniff whether the file starts with a DOCTYPE declaration. Returns null if the content could not be read.

getTitle()

Returns: String

The title from the HTML page, if there is one. Otherwise the resource's file name.

getBody()

Returns: String

The body content of the HTML page, if this resource is a HTML page.

getParam(String name)

Returns: String

If this resource is a HTML page, this returns the script parameter with the given name A script parameter is defined in the head section of a HTML page in a script element, where the title attribute is the name of the parameter, and the element's type parameter is 'data/parameter'

ParameterDescription
namethe parameter name to look up

setParam(String name, String value)

Returns: void

Sets a script parameter on this file's HTML page. This resource must be a HTML page, since it calls getHtml without a null check.

ParameterDescription
namethe parameter name
valuethe parameter value

getParamNames()

Returns: List<String>

Lists the names of all the script parameters defined in this page's head section, if it is a HTML page.

doSaveHtml()

Returns: void

Writes any parsed data held in the HTML page representation back to this file's content, running the HTML tidy step first to ensure the result is well-formed. Equivalent to doSaveHtml(true).

doSaveHtml(boolean runTidy)

Returns: void

Writes any parsed data held in the HTML page representation back to this file's content. If no HTML page representation has been created (no HTML content fields have been set) this is a no-op.

ParameterDescription
runTidywhether to run the HTML tidy step on the generated markup before saving it

getFileNode()

Returns: FileNode

The underlying data node this resource is backed by, which provides access to the file's raw content and hash.

is(String type)

Returns: boolean

Checks whether this resource matches the given type name. A plain FileResource always matches "file". It also matches any value that is contained in the file's content type, so a css file with mimetype "text/css" matches both is("text") and is("css"), and for a HTML page it also matches the page's template name.

ParameterDescription
typethe type name to test against

getTextContent()

Returns: String

Returns all of the raw text content of this resource, decoded as UTF-8. For a HTML page this is the raw HTML markup, not the rendered output.

getWebsiteBranch()

Returns: WebsiteBranchResource

Walks up this resource's ancestors to find the nearest one that can report a domain name - a ManageWebsiteBranchFolder when viewed in the admin console, or a WebsiteRootFolder when viewed on a website.

getGlyphicon()

Returns: String

A Bootstrap glyphicon CSS class name suited to this file's content type - an expand icon for video, a picture icon for images, and a generic file icon otherwise.

isContentManagedPermissions()

Returns: boolean

Whether this resource's permissions are managed as content permissions. Always true for a FileResource.

isThemeResource()

Returns: boolean

Checks whether this file lives under a website's theme directory, by walking up its parent directories looking for a folder named "theme" directly inside a website branch resource.

To get full access to the Kademi Hub existing customers can login here, or new customers can register here.