Package com.composum.sling.core
Class AbstractSlingBean
- java.lang.Object
-
- com.composum.sling.core.AbstractSlingBean
-
- All Implemented Interfaces:
RestrictedBean
,SlingBean
- Direct Known Subclasses:
AbstractServletBean
,ResourceModel
,SetupConfiguration
,SetupConfiguration.ConfigBean
,SetupConfiguration.ScriptBean
,UserProfile
public abstract class AbstractSlingBean extends Object implements SlingBean, RestrictedBean
The abstract base class for 'Beans' to implement a Model based on e JCR resource without a mapping framework. Such a 'bean' can be declared as variable in aJSP context using the 'component' tag of the Composum 'nodes' tag library (cpnl).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AbstractSlingBean.NodeClosure
-
Field Summary
Fields Modifier and Type Field Description protected BeanContext
context
the instance of the scripting context for the bean (initialized)protected javax.jcr.query.QueryManager
queryManager
protected RequestHandle
request
protected org.apache.sling.api.resource.ResourceResolver
resolver
protected ResourceHandle
resource
the resource represented by this bean (initialized)protected org.apache.sling.api.SlingHttpServletResponse
response
protected javax.jcr.Session
session
protected org.apache.sling.api.scripting.SlingScriptHelper
sling
-
Constructor Summary
Constructors Constructor Description AbstractSlingBean()
if this constructor is used, the bean must be initialized using the 'initialize' method!AbstractSlingBean(BeanContext context)
initialize bean using the context with the 'resource' attribute withinAbstractSlingBean(BeanContext context, org.apache.sling.api.resource.Resource resource)
initialize bean using the context an the resource given explicitly
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
executeQuery(String queryString, AbstractSlingBean.NodeClosure closure)
<T extends AbstractSlingBean>
List<T>findBeans(String queryString, Class<T> type)
javax.jcr.NodeIterator
findNodes(String queryString)
javax.jcr.NodeIterator
findNodes(String queryString, String type)
List<String>
findPathList(String queryString)
ResourceHandle
getContentResource()
String
getDomId()
boolean
getHasTitle()
String
getId()
<T> T
getInherited(String key, Class<T> type)
<T> T
getInherited(String key, T defaultValue)
String
getName()
returns the name of the resource wrapped by this beanjavax.jcr.Node
getNode()
ResourceHandle
getParent(String resourceType)
Determine a typed parent resource.ResourceHandle
getParent(String resourceType, String path)
Use path instead of resource (e.g.String
getPath()
returns the path of the resource wrapped by this beanMap<String,Map<String,Boolean>>
getPermissible()
<T> T
getProperty(String key, Class<T> type)
<T> T
getProperty(String key, T defaultValue)
javax.jcr.query.QueryManager
getQueryManager()
RequestHandle
getRequest()
@NotNull org.apache.sling.api.resource.ResourceResolver
getResolver()
Returns the resolver using the resource of this bean (resource.getResolver()).@NotNull ResourceHandle
getResource()
the getter for the resource which defines this bean instance.org.apache.sling.api.SlingHttpServletResponse
getResponse()
ServiceRestrictions.Key
getServiceKey()
javax.jcr.Session
getSession()
org.apache.sling.api.scripting.SlingScriptHelper
getSling()
Returns the handle to the 'Sling world' and all available services.String
getStringId()
Returns the default 'toString' value with the JVM 'id' of the object.String
getTitle()
String
getType()
returns the type of the resource wrapped by this beanString
getUrl()
Returns the URL to the resource of this bean (mapped and with the appropriate extension).String
getUsername()
void
initialize(BeanContext context)
Uses the contexts 'resource' attribute for initialization (content.getResource()).void
initialize(BeanContext context, org.apache.sling.api.resource.Resource resource)
This basic initialization sets up the context and resource attributes only, all the other attributes are set 'lazy' during their getter calls.protected boolean
isPermissible(ServiceRestrictions.Key key, ServiceRestrictions.Permission permission)
boolean
isReadAllowed()
boolean
isWriteAllowed()
String
toString()
Default implementation: usestoString(StringBuilder)
.void
toString(StringBuilder builder)
A 'toString' implementation for logging and debugging.
-
-
-
Field Detail
-
context
protected BeanContext context
the instance of the scripting context for the bean (initialized)
-
resource
protected ResourceHandle resource
the resource represented by this bean (initialized)
-
sling
protected transient org.apache.sling.api.scripting.SlingScriptHelper sling
-
resolver
protected transient org.apache.sling.api.resource.ResourceResolver resolver
-
session
protected transient javax.jcr.Session session
-
queryManager
protected transient javax.jcr.query.QueryManager queryManager
-
request
protected transient RequestHandle request
-
response
protected transient org.apache.sling.api.SlingHttpServletResponse response
-
-
Constructor Detail
-
AbstractSlingBean
public AbstractSlingBean(BeanContext context, org.apache.sling.api.resource.Resource resource)
initialize bean using the context an the resource given explicitly
-
AbstractSlingBean
public AbstractSlingBean(BeanContext context)
initialize bean using the context with the 'resource' attribute within
-
AbstractSlingBean
public AbstractSlingBean()
if this constructor is used, the bean must be initialized using the 'initialize' method!
-
-
Method Detail
-
initialize
public void initialize(BeanContext context)
Uses the contexts 'resource' attribute for initialization (content.getResource()).- Specified by:
initialize
in interfaceSlingBean
- Parameters:
context
- the scripting context (e.g. a JSP PageContext or a Groovy scripting context)
-
initialize
public void initialize(BeanContext context, org.apache.sling.api.resource.Resource resource)
This basic initialization sets up the context and resource attributes only, all the other attributes are set 'lazy' during their getter calls.- Specified by:
initialize
in interfaceSlingBean
- Parameters:
context
- the scripting context (e.g. a JSP PageContext or a Groovy scripting context)resource
- the resource to use (normally the resource addressed by the request)- See Also:
BeanContext.withResource(Resource)
-
getServiceKey
@Nullable public ServiceRestrictions.Key getServiceKey()
-
isReadAllowed
public boolean isReadAllowed()
- Specified by:
isReadAllowed
in interfaceRestrictedBean
-
isWriteAllowed
public boolean isWriteAllowed()
- Specified by:
isWriteAllowed
in interfaceRestrictedBean
-
isPermissible
protected boolean isPermissible(ServiceRestrictions.Key key, ServiceRestrictions.Permission permission)
-
getSling
public org.apache.sling.api.scripting.SlingScriptHelper getSling()
Returns the handle to the 'Sling world' and all available services.
-
getResolver
@NotNull public @NotNull org.apache.sling.api.resource.ResourceResolver getResolver()
Returns the resolver using the resource of this bean (resource.getResolver()).
-
getResource
@NotNull public @NotNull ResourceHandle getResource()
the getter for the resource which defines this bean instance.
-
getUrl
public String getUrl()
Returns the URL to the resource of this bean (mapped and with the appropriate extension).
-
getPath
public String getPath()
Description copied from interface:SlingBean
returns the path of the resource wrapped by this bean
-
getName
public String getName()
Description copied from interface:SlingBean
returns the name of the resource wrapped by this bean
-
getType
public String getType()
Description copied from interface:SlingBean
returns the type of the resource wrapped by this bean
-
getDomId
public String getDomId()
-
getId
public String getId()
-
getNode
public javax.jcr.Node getNode()
-
getParent
public ResourceHandle getParent(String resourceType)
Determine a typed parent resource.
-
getParent
public ResourceHandle getParent(String resourceType, String path)
Use path instead of resource (e.g. if resource is synthetic or non existing) to determine a typed parent.
-
getHasTitle
public boolean getHasTitle()
-
getTitle
public String getTitle()
-
getContentResource
public ResourceHandle getContentResource()
-
getProperty
public <T> T getProperty(String key, T defaultValue)
-
getInherited
public <T> T getInherited(String key, T defaultValue)
-
getRequest
public RequestHandle getRequest()
-
getResponse
public org.apache.sling.api.SlingHttpServletResponse getResponse()
-
executeQuery
public void executeQuery(String queryString, AbstractSlingBean.NodeClosure closure) throws javax.jcr.RepositoryException
- Throws:
javax.jcr.RepositoryException
-
findBeans
public <T extends AbstractSlingBean> List<T> findBeans(String queryString, Class<T> type)
-
findPathList
public List<String> findPathList(String queryString) throws javax.jcr.RepositoryException
- Throws:
javax.jcr.RepositoryException
-
findNodes
public javax.jcr.NodeIterator findNodes(String queryString) throws javax.jcr.RepositoryException
- Throws:
javax.jcr.RepositoryException
-
findNodes
public javax.jcr.NodeIterator findNodes(String queryString, String type) throws javax.jcr.RepositoryException
- Throws:
javax.jcr.RepositoryException
-
getQueryManager
public javax.jcr.query.QueryManager getQueryManager() throws javax.jcr.RepositoryException
- Throws:
javax.jcr.RepositoryException
-
getSession
public javax.jcr.Session getSession()
-
getUsername
public String getUsername()
-
toString
public void toString(StringBuilder builder)
A 'toString' implementation for logging and debugging.- Parameters:
builder
- the buffer to write into
-
getStringId
public String getStringId()
Returns the default 'toString' value with the JVM 'id' of the object.- Returns:
- the general JVM 'id'
-
toString
public String toString()
Default implementation: usestoString(StringBuilder)
.
-
-