public class ComponentHelper
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ComponentHelper.Options
An options to be passed to the included resource's renderer.
|
| Constructor and Description |
|---|
ComponentHelper(javax.servlet.jsp.PageContext pageContext) |
| Modifier and Type | Method and Description |
|---|---|
DataSource |
asDataSource(Resource datasource)
Returns the datasource given its datasource resource.
|
DataSource |
asDataSource(Resource datasource,
Resource context)
Returns the datasource given its datasource resource.
|
void |
call(java.lang.String script,
ComponentHelper.Options options)
Calls the given script and passes the given options to its renderer.
|
Resource |
consumeLayoutResource()
Consumes the current available layout resource for current page.
|
Tag |
consumeTag()
Consumes the current available tag for current page.
|
Config |
getConfig()
Returns the config of current resource of the page.
|
ExpressionHelper |
getExpressionHelper()
Returns the ExpressionHelper appropriate for the current page.
|
I18n |
getI18n()
Returns I18n appropriate for the current page.
|
java.lang.String |
getIconClass(java.lang.String icon)
Returns the icon class(es) for the given icon string from the content
property.
|
DataSource |
getItemDataSource()
Returns the datasource for items of the current resource.
|
DataSource |
getItemDataSource(Resource resource)
Returns the datasource for items of the given resource.
|
LayoutBuilder |
getLayout()
Returns the layout config of current resource of the page.
|
ComponentHelper.Options |
getOptions()
Returns the options passed from another page.
|
java.lang.String |
getReadOnlyResourceType()
Returns the associated resource type of current resource for the purpose
rendering read only version.
|
java.lang.String |
getReadOnlyResourceType(Resource resource)
Returns the associated resource type of the given content resource for the
purpose rendering read only version.
|
RenderCondition |
getRenderCondition()
Returns the render condition of the current resource.
|
RenderCondition |
getRenderCondition(Resource resource)
Returns the render condition of the given resource.
|
RenderCondition |
getRenderCondition(Resource resource,
boolean cache)
Returns the render condition of the given resource.
|
State |
getState()
Returns the client state.
|
Value |
getValue()
Returns the values that is applicable for the current page.
|
XSSAPI |
getXss()
Returns XSSAPI based on the current request.
|
void |
include(Resource resource,
ComponentHelper.Options options)
Includes the given resource and passes the given options to its renderer.
|
void |
include(Resource resource,
java.lang.String resourceType,
ComponentHelper.Options options)
Includes the given resource with the given resourceType and passes the given
options to its renderer.
|
void |
include(Resource resource,
java.lang.String resourceType,
java.lang.String selectors,
ComponentHelper.Options options)
Includes the given resource with the given resourceType and passes the given
options to its renderer.
|
void |
include(Resource resource,
java.lang.String resourceType,
Tag tag)
Includes the given resource with the given resourceType and passes the given
tag to its renderer.
|
void |
include(Resource resource,
Tag tag)
Includes the given resource and passes the given tag to its renderer.
|
void |
includeForLayout(Resource resource,
ComponentHelper.Options options)
A convenient overload to
includeForLayout(Resource, Resource, Options), with layoutResource
as null. |
void |
includeForLayout(Resource resource,
Resource layoutResource,
ComponentHelper.Options options)
Includes the given resource to be rendered by the given layoutResource.
|
void |
populateCommonAttrs(AttrBuilder attrs)
The overload of
populateCommonAttrs(AttrBuilder, Resource) using the
current request's resource as the source. |
void |
populateCommonAttrs(AttrBuilder attrs,
Resource src)
Populates the common attributes to the given
AttrBuilder. |
public ComponentHelper(@Nonnull
javax.servlet.jsp.PageContext pageContext)
@Nonnull public I18n getI18n()
@Nonnull public XSSAPI getXss()
@Nonnull public Config getConfig()
@Nonnull public Value getValue()
@Nonnull public ExpressionHelper getExpressionHelper()
@Nonnull public State getState()
@Nonnull public Tag consumeTag()
There is a mechanism such that a tag can be passed to another page when including that page. This method is intended as a way to consume the tag passed by other page. Component developer can make use this method to get the main tag of the component regardless if there is a tag passed by other page or not.
include(Resource, Tag),
include(Resource, String, Tag)@CheckForNull public Resource consumeLayoutResource()
Config.LAYOUT child node, otherwise null is
returned.
This method is usually called by layout implementation to get the layout resource that can be passed by the caller.
includeForLayout(Resource, Options),
includeForLayout(Resource, Resource, Options)public void populateCommonAttrs(@Nonnull
AttrBuilder attrs)
populateCommonAttrs(AttrBuilder, Resource) using the
current request's resource as the source.attrs - the attribute builderpublic void populateCommonAttrs(@Nonnull
AttrBuilder attrs,
@Nonnull
Resource src)
AttrBuilder.
Currently the following common properties and nodes are read and processed from the given resource:
| Name | Type | Description |
|---|---|---|
| granite:id | Property: StringEL | The id attribute. |
| granite:rel | Property: StringEL | The class attribute. This is used to indicate the semantic relationship
of the component similar to rel attribute. |
| granite:class | Property: StringEL | The class attribute. |
| granite:title | Property: String | The title attribute. This property is i18nable. |
| granite:hidden | Property: Boolean | The hidden attribute. |
| granite:itemscope | Property: Boolean | The itemscope attribute. |
| granite:itemtype | Property: String | The itemtype attribute. |
| granite:itemprop | Property: String | The itemprop attribute. |
| granite:data | Node | Each property of this node is converted into a data-* attribute. If the property value is an instance of a String, it will be interpreted as StringEL. The property having a prefixed name is ignored. |
attrs - The attribute builder to populate tosrc - The resource of the source of the config@Nonnull public ComponentHelper.Options getOptions()
There is a mechanism such that options can be passed to another page when including that page.
include(Resource, Options),
include(Resource, String, Options)@Nonnull public LayoutBuilder getLayout()
LayoutBuilder.getResourceType()@CheckForNull public java.lang.String getReadOnlyResourceType()
readonly child resource of the RT.@CheckForNull
public java.lang.String getReadOnlyResourceType(@Nonnull
Resource resource)
readonly child resource of the RT.resource - the resource@Nonnull public DataSource getItemDataSource() throws javax.servlet.ServletException, java.io.IOException
getItemDataSource(Resource) with resource is the current request
resource.javax.servlet.ServletException - in case there's a servlet error while fetching datajava.io.IOException - in case there's an i/o error while fetching data@Nonnull public DataSource getItemDataSource(@Nonnull Resource resource) throws javax.servlet.ServletException, java.io.IOException
Config.ITEMS subresource; or specified as datasource using
Config.DATASOURCE subresource.
If there is no Config.ITEMS or Config.DATASOURCE subresource,
then EmptyDataSource is returned.
In contrast with asDataSource(Resource, Resource), this method looks
for the datasource resource of the given resource. i.e. The given resource is
the parent of the items, not the datasource resource itself. The given
resource is also used as the context resource when calling
asDataSource(Resource, Resource) internally.resource - the resourcejavax.servlet.ServletException - in case there's a servlet error while fetching datajava.io.IOException - in case there's an i/o error while fetching datapublic DataSource asDataSource(@CheckForNull Resource datasource) throws javax.servlet.ServletException, java.io.IOException
asDataSource(Resource, Resource) with context is
null.datasource - the resource representing the datasourcejavax.servlet.ServletException - in case there's a servlet error while fetching datajava.io.IOException - in case there's an i/o error while fetching datapublic DataSource asDataSource(@CheckForNull Resource datasource, @CheckForNull Resource context) throws javax.servlet.ServletException, java.io.IOException
datasource - The resource representing the datasourcecontext - The context resource that is returned when calling
SlingHttpServletRequest.getResource() at the datasource
implementation. If this is null, the given datasource is
used.null if the given datasource is null.javax.servlet.ServletException - in case there's a servlet error while fetching datajava.io.IOException - in case there's an i/o error while fetching data@Nonnull public RenderCondition getRenderCondition() throws javax.servlet.ServletException, java.io.IOException
getRenderCondition(Resource) using the current resource.
The render condition is specified by granite:rendercondition or
rendercondition subresource.
Contrast this with getRenderCondition(Resource, boolean), where only
granite:rendercondition is checked. This method is meant for backward
compatibility; otherwise it is better to use
getRenderCondition(Resource, boolean) for performance. Once the
transition is over, this method will have the same behaviour as
getRenderCondition(Resource, boolean) with cache =
false.javax.servlet.ServletException - in case there's a servlet errorjava.io.IOException - in case there's an i/o error@Nonnull public RenderCondition getRenderCondition(@Nonnull Resource resource) throws javax.servlet.ServletException, java.io.IOException
granite:rendercondition or
rendercondition subresource.
Contrast this with getRenderCondition(Resource, boolean), where only
granite:rendercondition is checked. This method is meant for backward
compatibility; otherwise it is better to use
getRenderCondition(Resource, boolean) for performance. Once the
transition is over, this method will have the same behaviour as
getRenderCondition(Resource, boolean) with cache =
false.resource - the resourcejavax.servlet.ServletException - in case there's a servlet errorjava.io.IOException - in case there's an i/o error@Nonnull public RenderCondition getRenderCondition(@Nonnull Resource resource, boolean cache) throws javax.servlet.ServletException, java.io.IOException
granite:rendercondition
subresource, unlike getRenderCondition(Resource).resource - The resourcecache - true to cache the result; Use it when checking render
condition of other resource (typically the item resource) so that
the render condition is only resolved once.null.javax.servlet.ServletException - in case there's a servlet errorjava.io.IOException - in case there's an i/o errorpublic java.lang.String getIconClass(@CheckForNull
java.lang.String icon)
icon - the icon stringnull if the given icon is nullpublic void include(@Nonnull
Resource resource,
@Nonnull
Tag tag)
throws javax.servlet.ServletException,
java.io.IOException
resource - the resource to includetag - the tagjavax.servlet.ServletException - in case there's a servlet errorjava.io.IOException - in case there's an i/o errorpublic void include(@Nonnull
Resource resource,
@Nonnull
ComponentHelper.Options options)
throws javax.servlet.ServletException,
java.io.IOException
resource - the resource to includeoptions - the optionsjavax.servlet.ServletException - in case there's a servlet errorjava.io.IOException - in case there's an i/o errorpublic void include(@Nonnull
Resource resource,
@CheckForNull
java.lang.String resourceType,
@Nonnull
Tag tag)
throws javax.servlet.ServletException,
java.io.IOException
resource - the resource to includeresourceType - the resource typetag - the tagjavax.servlet.ServletException - in case there's a servlet errorjava.io.IOException - in case there's an i/o errorpublic void include(@Nonnull
Resource resource,
@CheckForNull
java.lang.String resourceType,
@Nonnull
ComponentHelper.Options options)
throws javax.servlet.ServletException,
java.io.IOException
resource - the resource to includeresourceType - the resource typeoptions - the optionsjavax.servlet.ServletException - in case there's a servlet errorjava.io.IOException - in case there's an i/o errorpublic void include(@Nonnull
Resource resource,
@CheckForNull
java.lang.String resourceType,
@CheckForNull
java.lang.String selectors,
@Nonnull
ComponentHelper.Options options)
throws javax.servlet.ServletException,
java.io.IOException
resource - the resource to includeresourceType - the resource typeselectors - the selectors to be included as part of the request.options - the optionsjavax.servlet.ServletException - in case there's a servlet errorjava.io.IOException - in case there's an i/o errorpublic void includeForLayout(@Nonnull
Resource resource,
@Nonnull
ComponentHelper.Options options)
throws javax.servlet.ServletException,
java.io.IOException
includeForLayout(Resource, Resource, Options), with layoutResource
as null.resource - the resource to includeoptions - the optionsjavax.servlet.ServletException - in case there's a servlet errorjava.io.IOException - in case there's an i/o errorpublic void includeForLayout(@Nonnull
Resource resource,
@CheckForNull
Resource layoutResource,
@Nonnull
ComponentHelper.Options options)
throws javax.servlet.ServletException,
java.io.IOException
If layoutResource is not null, the
ComponentHelper.Options.layoutResource(Resource) is set.
This method will attempt to derive the resourceType to be passed to
include(Resource, String, Options) based the following priorities:
Config.LAYOUT child
node's RTresource - the resource to includelayoutResource - the layout resource to render the given resource withoptions - the optionsjavax.servlet.ServletException - in case there's a servlet errorjava.io.IOException - in case there's an i/o errorpublic void call(@Nonnull
java.lang.String script,
@Nonnull
ComponentHelper.Options options)
throws javax.servlet.ServletException,
java.io.IOException
script - the script to be calledoptions - the optionsjavax.servlet.ServletException - in case there's a servlet errorjava.io.IOException - in case there's an i/o errorCopyright © 2010 - 2023 Adobe. All Rights Reserved