org.hippoecm.hst.component.support.bean
Class BaseHstComponent

java.lang.Object
  extended by org.hippoecm.hst.core.component.GenericHstComponent
      extended by org.hippoecm.hst.component.support.bean.BaseHstComponent
All Implemented Interfaces:
HstComponent
Direct Known Subclasses:
BaseFormHstComponent

public class BaseHstComponent
extends GenericHstComponent

A base HstComponent implementation to provide some facility methods for accessing content node POJO objects, ObjectBeanManager, request parameters, query manager, etc.

This implementation enables developers to make use of HST Content Bean's ObjectBeanManager which provides a simple object-content mapping solution. To use ObjectBeanManager, you can invoke getObjectBeanManager(HstRequest), which retrieves a JCR session from HstRequestContext.getSession() internally.

When you need to persist beans through ecm workflow, you can use getWorkflowPersistenceManager(Session). Make sure that the jcr session you use as parameter is obtained through getPersistableSession(HstRequest) or getPersistableSession(HstRequest, Credentials).

Version:
$Id: BaseHstComponent.java 32953 2012-02-14 21:44:26Z wko $

Field Summary
static String BEANS_ANNOTATED_CLASSES_CONF_PARAM
           
protected  boolean beansInitialized
           
static String DEFAULT_BEANS_ANNOTATED_CLASSES_CONF
           
protected  HstQueryManagerFactory hstQueryManagerFactory
           
static String OBJECT_CONVERTER_CONTEXT_ATTRIBUTE
           
protected  ObjectConverter objectConverter
           
 
Fields inherited from class org.hippoecm.hst.core.component.GenericHstComponent
RESOURCE_PATH_BY_RESOURCE_ID
 
Constructor Summary
BaseHstComponent()
           
 
Method Summary
 HippoFolderBean getAssetBaseBean(HstRequest request)
           
 HippoBean getBeanForResolvedSiteMapItem(HstRequest request, ResolvedSiteMapItem resolvedSiteMapItem)
          Return a HippoBean when it can be found for the relativeContentPath for the ResolvedSiteMapItem.
 HippoBean getContentBean(HstRequest request)
          When the ResolvedSiteMapItem belonging to the current requestUri has a relativeContentPath that points to an existing jcr Node, a HippoBean wrapping this node is returned.
<T extends HippoBean>
T
getContentBean(HstRequest request, Class<T> beanMappingClass)
           
 ComponentManager getDefaultClientComponentManager()
          This returns the client ComponentManager if one is configured with its default name.
protected  String[] getFallBackJcrNodeTypes()
          Deprecated.  
 HippoFolderBean getGalleryBaseBean(HstRequest request)
           
 HstSite getHstSite(HstRequest request)
           
protected  List<Class<? extends HippoBean>> getLocalAnnotatedClasses()
          when you want to inject specific component only custom annotated classes override this method This method is only called during the init() phase of a component
 String getLocalParameter(String name, HstRequest request)
          See getParameter(String, HstRequest), but now, only resolved parameters directly on the HstComponent are taken into acoount: in other words, no inheritance of parameters is applied
 Map<String,String> getLocalParameters(HstRequest request)
          See getParameters(HstRequest), but now, only resolved parameter map of parameters is returned that is directly on the HstComponenConfiguration, thus, no inheritance is applied
 Mount getMount(HstRequest request)
           
 ObjectBeanManager getObjectBeanManager(HstRequest request)
           
 ObjectConverter getObjectConverter()
           
 String getParameter(String name, HstRequest request)
          Returns resolved parameter from HstComponentConfiguration : resolved means that possible property placeholders like ${1} or ${year}, where the first refers to the first wildcard matcher in a resolved sitemap item, and the latter to a resolved parameter in the resolved HstSiteMapItem The parameter map used has inherited parameters from ancestor components, which have precedence over child components)
 Map<String,String> getParameters(HstRequest request)
          See getParameter(String, HstRequest), where we now return all resolved parameters (thus with inheritance of ancestor components)
protected
<T> T
getParametersInfo(HstRequest request)
          Returns a proxy ParametersInfo object which resolves parameter from HstComponentConfiguration : resolved means that possible property placeholders like ${1} or ${year}, where the first refers to the first wildcard matcher in a resolved sitemap item, and the latter to a resolved parameter in the resolved HstSiteMapItem
protected  javax.jcr.Session getPersistableSession(HstRequest request)
          Creates a persistable JCR session with the default credentials
protected  javax.jcr.Session getPersistableSession(HstRequest request, javax.jcr.Credentials credentials)
          Creates a persistable JCR session with provided credentials.
 String getPublicRequestParameter(HstRequest request, String parameterName)
          A public request parameter is a request parameter that is not namespaced.
 String[] getPublicRequestParameters(HstRequest request, String parameterName)
          Also see getPublicRequestParameter(HstRequest, String).
 HstQueryManager getQueryManager()
          Deprecated. use getQueryManager(HstRequest), getQueryManager(HstRequestContext) or #getQue instead
 HstQueryManager getQueryManager(HstRequest request)
           
 HstQueryManager getQueryManager(HstRequestContext ctx)
           
 HstQueryManager getQueryManager(javax.jcr.Session session)
           
 ResolvedMount getResolvedMount(HstRequest request)
           
 HippoBean getSiteContentBaseBean(HstRequest request)
           
 String getSiteContentBasePath(HstRequest request)
           
protected  WorkflowPersistenceManager getWorkflowPersistenceManager(javax.jcr.Session session)
          Returns a WorkflowPersistenceManager instance.
protected  WorkflowPersistenceManager getWorkflowPersistenceManager(javax.jcr.Session session, Map<String,ContentNodeBinder> contentNodeBinders)
          Returns a WorkflowPersistenceManager instance with custom binders map.
 void init(javax.servlet.ServletContext servletContext, ComponentConfiguration componentConfig)
          Allows the component to initialize itself
 boolean isPreview(HstRequest request)
           
 void sendRedirect(String path, HstRequest request, HstResponse response)
           Facility method for sending a redirect to a sitemap path.
 void sendRedirect(String path, HstRequest request, HstResponse response, Map<String,String[]> queryParams)
           Facility method for sending a redirect to a sitemap path including query params.
 void sendRedirect(String path, HstRequest request, HstResponse response, Map<String,String[]> queryParams, String characterEncoding)
           Facility method for sending a redirect to a sitemap path including query params and characterEncoding.
 
Methods inherited from class org.hippoecm.hst.core.component.GenericHstComponent
destroy, doAction, doBeforeRender, doBeforeServeResource, getComponentConfiguration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEANS_ANNOTATED_CLASSES_CONF_PARAM

public static final String BEANS_ANNOTATED_CLASSES_CONF_PARAM
See Also:
Constant Field Values

DEFAULT_BEANS_ANNOTATED_CLASSES_CONF

public static final String DEFAULT_BEANS_ANNOTATED_CLASSES_CONF
See Also:
Constant Field Values

OBJECT_CONVERTER_CONTEXT_ATTRIBUTE

public static final String OBJECT_CONVERTER_CONTEXT_ATTRIBUTE

beansInitialized

protected boolean beansInitialized

objectConverter

protected ObjectConverter objectConverter

hstQueryManagerFactory

protected HstQueryManagerFactory hstQueryManagerFactory
Constructor Detail

BaseHstComponent

public BaseHstComponent()
Method Detail

init

public void init(javax.servlet.ServletContext servletContext,
                 ComponentConfiguration componentConfig)
          throws HstComponentException
Description copied from interface: HstComponent
Allows the component to initialize itself

Specified by:
init in interface HstComponent
Overrides:
init in class GenericHstComponent
Parameters:
servletContext - the servletConfig of the HST container servlet
componentConfig - the componentConfigBean configuration
Throws:
HstComponentException

getParameter

public String getParameter(String name,
                           HstRequest request)
Returns resolved parameter from HstComponentConfiguration : resolved means that possible property placeholders like ${1} or ${year}, where the first refers to the first wildcard matcher in a resolved sitemap item, and the latter to a resolved parameter in the resolved HstSiteMapItem The parameter map used has inherited parameters from ancestor components, which have precedence over child components)

Parameters:
name -
request -
Returns:
the resolved parameter value for this name, or null if not present

getParameters

public Map<String,String> getParameters(HstRequest request)
See getParameter(String, HstRequest), where we now return all resolved parameters (thus with inheritance of ancestor components)

Parameters:
request -
Returns:
Map of all parameters, and when no parameters present, return empty map.

getLocalParameter

public String getLocalParameter(String name,
                                HstRequest request)
See getParameter(String, HstRequest), but now, only resolved parameters directly on the HstComponent are taken into acoount: in other words, no inheritance of parameters is applied

Parameters:
name -
request -
Returns:
the resolved parameter value for this name, or null if not present

getLocalParameters

public Map<String,String> getLocalParameters(HstRequest request)
See getParameters(HstRequest), but now, only resolved parameter map of parameters is returned that is directly on the HstComponenConfiguration, thus, no inheritance is applied

Parameters:
request -
Returns:
Map of all parameters, and when no parameters present, return empty map.

getPublicRequestParameter

public String getPublicRequestParameter(HstRequest request,
                                        String parameterName)
A public request parameter is a request parameter that is not namespaced. Thus for example ?foo=bar. Typically, a namespaced request parameter for example looks like ?r1_r4:foo=bar. Public request parameters are used when some parameter from some hst component needs to be readable by another hst component. For example when you have a search box in the top of your webpage. The input value there should be readable by the center content block displaying the search results. In that case, this method can be used to fetch the public request parameter. Also see getPublicRequestParameters(HstRequest, String)

Parameters:
request -
parameterName -
Returns:
The public request parameter for parameterName. If there are multiple values, the first one is returned. If no value, null is returned

getPublicRequestParameters

public String[] getPublicRequestParameters(HstRequest request,
                                           String parameterName)
Also see getPublicRequestParameter(HstRequest, String).

Parameters:
request -
parameterName -
Returns:
The public request parameters String array for parameterName. If no values for parameterName found, new String[0] is returned

getHstSite

public HstSite getHstSite(HstRequest request)

getResolvedMount

public ResolvedMount getResolvedMount(HstRequest request)

getMount

public Mount getMount(HstRequest request)

getSiteContentBasePath

public String getSiteContentBasePath(HstRequest request)
Parameters:
request -
Returns:
the jcr path relative to the root (not starting with / thus)

isPreview

public boolean isPreview(HstRequest request)
Returns:
true when this request is matched to a preview site
See Also:
Mount.isPreview()

getContentBean

public HippoBean getContentBean(HstRequest request)
When the ResolvedSiteMapItem belonging to the current requestUri has a relativeContentPath that points to an existing jcr Node, a HippoBean wrapping this node is returned. When there is no relativeContentPath or the location does not exist, null is returned

Parameters:
request -
Returns:
A HippoBean or null when there cannot be created a content bean for the resolvedSiteMapItem belonging to the current request

getContentBean

public <T extends HippoBean> T getContentBean(HstRequest request,
                                              Class<T> beanMappingClass)
Parameters:
request -
beanMappingClass - the class of the bean that you expect
Returns:
A HippoBean of beanMappingClass or null if bean cannot be found or is of a different class
See Also:
#getContentBean(HstRequest)} but only returns the bean if the found content bean is of type {@code beanMappingClass}. When the bean cannot be found, or is not of type {@code beanMappingClass}, null is returned

getSiteContentBaseBean

public HippoBean getSiteContentBaseBean(HstRequest request)

getGalleryBaseBean

public HippoFolderBean getGalleryBaseBean(HstRequest request)
Parameters:
request -
Returns:
the root gallery HippoFolderBean at /content/gallery and null if it does not exist

getAssetBaseBean

public HippoFolderBean getAssetBaseBean(HstRequest request)
Parameters:
request -
Returns:
the root asset HippoFolderBean at /content/assets and null if it does not exist

getBeanForResolvedSiteMapItem

public HippoBean getBeanForResolvedSiteMapItem(HstRequest request,
                                               ResolvedSiteMapItem resolvedSiteMapItem)
Return a HippoBean when it can be found for the relativeContentPath for the ResolvedSiteMapItem. If there is no relativeContentPath available in the ResolvedSiteMapItem, or when the relativeContentPath does not point to an existing jcr node, null will be returned

Parameters:
request -
resolvedSiteMapItem -
Returns:
A HippoBean or null when there cannot be created a content bean for this resolvedSiteMapItem

getQueryManager

@Deprecated
public HstQueryManager getQueryManager()
Deprecated. use getQueryManager(HstRequest), getQueryManager(HstRequestContext) or #getQue instead


getQueryManager

public HstQueryManager getQueryManager(HstRequest request)
Parameters:
request - the HstRequest
Returns:
the HstQueryManager
See Also:
same as {@link #getQueryManager(HstRequestContext)} and {@link #getQueryManager(Session)} does

getQueryManager

public HstQueryManager getQueryManager(HstRequestContext ctx)
Parameters:
ctx - the HstRequestContext
Returns:
the HstQueryManager
See Also:
same as {@link #getQueryManager(HstRequest)} and {@link #getQueryManager(Session)} does

getQueryManager

public HstQueryManager getQueryManager(javax.jcr.Session session)
Parameters:
session - the Session
Returns:
the HstQueryManager
See Also:
same as {@link #getQueryManager(HstRequestContext)} and {@link #getQueryManager(HstRequest)} does

getObjectBeanManager

public ObjectBeanManager getObjectBeanManager(HstRequest request)

getDefaultClientComponentManager

public ComponentManager getDefaultClientComponentManager()
This returns the client ComponentManager if one is configured with its default name. If set on the context with a different attribute name, you need to fetch it yourself with a different attr name

Returns:
the client ComponentManager or null if none configured

sendRedirect

public void sendRedirect(String path,
                         HstRequest request,
                         HstResponse response)

Facility method for sending a redirect to a sitemap path. You do not have to take into account the context path or Mount path

Parameters:
path - the sitemap path you want to redirect to
request - the HstRequest
response - the HstResponse
See Also:
HstResponse.sendRedirect(String)

sendRedirect

public void sendRedirect(String path,
                         HstRequest request,
                         HstResponse response,
                         Map<String,String[]> queryParams)

Facility method for sending a redirect to a sitemap path including query params. You do not have to take into account the context path or Mount path

Parameters:
path - the sitemap path you want to redirect to
request - the HstRequest
queryParams - query parameters to append to the redirection url
response - the HstResponse
See Also:
HstResponse.sendRedirect(String)

sendRedirect

public void sendRedirect(String path,
                         HstRequest request,
                         HstResponse response,
                         Map<String,String[]> queryParams,
                         String characterEncoding)

Facility method for sending a redirect to a sitemap path including query params and characterEncoding. You do not have to take into account the context path or Mount path

Parameters:
path - the sitemap path you want to redirect to
request - the HstRequest
queryParams - query parameters to append to the redirection url
response - the HstResponse
characterEncoding - character encoding for query parameters
See Also:
HstResponse.sendRedirect(String)

getObjectConverter

public ObjectConverter getObjectConverter()
                                   throws HstComponentException
Throws:
HstComponentException

getFallBackJcrNodeTypes

@Deprecated
protected String[] getFallBackJcrNodeTypes()
Deprecated. 

If you want other fallbacktypes, override getObjectConverter() method instead. This method just returns the default fallback primary node types by using ObjectConverterUtils.getDefaultFallbackNodeTypes().

Returns:
String array containing the fallback types

getLocalAnnotatedClasses

protected List<Class<? extends HippoBean>> getLocalAnnotatedClasses()
when you want to inject specific component only custom annotated classes override this method This method is only called during the init() phase of a component

Returns:
List of annotated classes, and if there are none, return an empty list

getPersistableSession

protected javax.jcr.Session getPersistableSession(HstRequest request)
                                           throws javax.jcr.RepositoryException
Creates a persistable JCR session with the default credentials

Note: The client should invoke logout() method on the session after use.

Internally, Session.impersonate(Credentials) method will be used to create a persistable JCR session. The method is invoked on the session from the session pooling repository.

Parameters:
request -
Returns:
Throws:
javax.jcr.RepositoryException

getPersistableSession

protected javax.jcr.Session getPersistableSession(HstRequest request,
                                                  javax.jcr.Credentials credentials)
                                           throws javax.jcr.RepositoryException
Creates a persistable JCR session with provided credentials.

Note: The client should invoke logout() method on the session after use.

Internally, Session.impersonate(Credentials) method will be used to create a persistable JCR session. The method is invoked on the session from the session pooling repository.

Parameters:
request -
Returns:
Throws:
javax.jcr.RepositoryException

getWorkflowPersistenceManager

protected WorkflowPersistenceManager getWorkflowPersistenceManager(javax.jcr.Session session)
Returns a WorkflowPersistenceManager instance.

Parameters:
session - make sure this is a persistable session, obtained through or {@link #getPersistableSession(HstRequest, Credentials)}
Returns:

getWorkflowPersistenceManager

protected WorkflowPersistenceManager getWorkflowPersistenceManager(javax.jcr.Session session,
                                                                   Map<String,ContentNodeBinder> contentNodeBinders)
Returns a WorkflowPersistenceManager instance with custom binders map.

Parameters:
session - make sure this is a persistable session, obtained through or {@link #getPersistableSession(HstRequest, Credentials)}
contentNodeBinders -
Returns:

getParametersInfo

protected <T> T getParametersInfo(HstRequest request)
Returns a proxy ParametersInfo object which resolves parameter from HstComponentConfiguration : resolved means that possible property placeholders like ${1} or ${year}, where the first refers to the first wildcard matcher in a resolved sitemap item, and the latter to a resolved parameter in the resolved HstSiteMapItem

NOTE: Because the returned ParametersInfo proxy instance is bound to the current request, you MUST NOT store the returned object in a member variable or session. You should retrieve that per request.

The parameter map used has inherited parameters from ancestor components, which have precedence over child components)

Parameters:
request - the HST request
Returns:
the resolved parameter value for this name, or null if not present


Copyright © 2008-2012 Hippo. All Rights Reserved.