Package com.composum.sling.core
Class AbstractSlingBean
- java.lang.Object
-
- com.composum.sling.core.AbstractSlingBean
-
- All Implemented Interfaces:
RestrictedBean,SlingBean
- Direct Known Subclasses:
AbstractServletBean,ConsoleSlingBean,OsgiBundleModel,OsgiBundlesModel,ResourceModel,RestrictionsView,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 interfaceAbstractSlingBean.NodeClosure
-
Field Summary
Fields Modifier and Type Field Description protected BeanContextcontextthe instance of the scripting context for the bean (initialized)protected javax.jcr.query.QueryManagerqueryManagerprotected RequestHandlerequestprotected org.apache.sling.api.resource.ResourceResolverresolverprotected ResourceHandleresourcethe resource represented by this bean (initialized)protected org.apache.sling.api.SlingHttpServletResponseresponseprotected javax.jcr.Sessionsessionprotected org.apache.sling.api.scripting.SlingScriptHelpersling
-
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 voidexecuteQuery(String queryString, AbstractSlingBean.NodeClosure closure)<T extends AbstractSlingBean>
List<T>findBeans(String queryString, Class<T> type)javax.jcr.NodeIteratorfindNodes(String queryString)javax.jcr.NodeIteratorfindNodes(String queryString, String type)List<String>findPathList(String queryString)ResourceHandlegetContentResource()StringgetDomId()booleangetHasTitle()StringgetId()<T> TgetInherited(String key, Class<T> type)<T> TgetInherited(String key, T defaultValue)StringgetName()returns the name of the resource wrapped by this beanjavax.jcr.NodegetNode()ResourceHandlegetParent(String resourceType)Determine a typed parent resource.ResourceHandlegetParent(String resourceType, String path)Use path instead of resource (e.g.StringgetPath()returns the path of the resource wrapped by this beanMap<String,Map<String,Boolean>>getPermissible()<T> TgetProperty(String key, Class<T> type)<T> TgetProperty(String key, T defaultValue)javax.jcr.query.QueryManagergetQueryManager()RequestHandlegetRequest()@NotNull org.apache.sling.api.resource.ResourceResolvergetResolver()Returns the resolver using the resource of this bean (resource.getResolver()).@NotNull ResourceHandlegetResource()the getter for the resource which defines this bean instance.org.apache.sling.api.SlingHttpServletResponsegetResponse()ServiceRestrictions.KeygetServiceKey()javax.jcr.SessiongetSession()org.apache.sling.api.scripting.SlingScriptHelpergetSling()Returns the handle to the 'Sling world' and all available services.StringgetStringId()Returns the default 'toString' value with the JVM 'id' of the object.StringgetTitle()StringgetType()returns the type of the resource wrapped by this beanStringgetUrl()Returns the URL to the resource of this bean (mapped and with the appropriate extension).StringgetUsername()voidinitialize(BeanContext context)Uses the contexts 'resource' attribute for initialization (content.getResource()).voidinitialize(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 booleanisPermissible(ServiceRestrictions.Key key, ServiceRestrictions.Permission permission)booleanisReadAllowed()booleanisWriteAllowed()StringtoString()Default implementation: usestoString(StringBuilder).voidtoString(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:
initializein 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:
initializein 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:
isReadAllowedin interfaceRestrictedBean
-
isWriteAllowed
public boolean isWriteAllowed()
- Specified by:
isWriteAllowedin 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:SlingBeanreturns the path of the resource wrapped by this bean
-
getName
public String getName()
Description copied from interface:SlingBeanreturns the name of the resource wrapped by this bean
-
getType
public String getType()
Description copied from interface:SlingBeanreturns 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).
-
-