Class AbstractSlingBean

    • 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
      • 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 interface SlingBean
        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 interface SlingBean
        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)
      • 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.
      • getPath

        public String getPath()
        Description copied from interface: SlingBean
        returns the path of the resource wrapped by this bean
        Specified by:
        getPath in interface SlingBean
      • getName

        public String getName()
        Description copied from interface: SlingBean
        returns the name of the resource wrapped by this bean
        Specified by:
        getName in interface SlingBean
      • getType

        public String getType()
        Description copied from interface: SlingBean
        returns the type of the resource wrapped by this bean
        Specified by:
        getType in interface SlingBean
      • 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()
      • getProperty

        public <T> T getProperty​(String key,
                                 T defaultValue)
      • getProperty

        public <T> T getProperty​(String key,
                                 Class<T> type)
      • getInherited

        public <T> T getInherited​(String key,
                                  T defaultValue)
      • getInherited

        public <T> T getInherited​(String key,
                                  Class<T> type)
      • 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
      • 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'