Search in sources :

Example 36 with HstRequestContext

use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.

the class IconLibraryItemComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
    super.doBeforeRender(request, response);
    HstRequestContext requestContext = request.getRequestContext();
    try {
        QueryManager jcrQueryManager = requestContext.getSession().getWorkspace().getQueryManager();
        Query jcrQuery = jcrQueryManager.createQuery(format(query, getTarget(requestContext)), "xpath");
        QueryResult queryResult = jcrQuery.execute();
        request.setAttribute("icon", getIcon(queryResult.getRows(), requestContext, response));
    } catch (RepositoryException e) {
        e.printStackTrace();
    }
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) QueryManager(javax.jcr.query.QueryManager) RepositoryException(javax.jcr.RepositoryException) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 37 with HstRequestContext

use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.

the class LatestNewsAndEventsComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
    final HstRequestContext ctx = request.getRequestContext();
    final HubNewsAndEvents document = (HubNewsAndEvents) ctx.getContentBean();
    if (document != null) {
        request.setAttribute("document", document);
    }
}
Also used : HubNewsAndEvents(uk.nhs.digital.website.beans.HubNewsAndEvents) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 38 with HstRequestContext

use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.

the class PolicyPageLinkedBeansComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) {
    super.doBeforeRender(request, response);
    // linkPath property contains the relative path of the links property in the published workflow document
    String linkPath = getComponentParameter("linkPath");
    final HstRequestContext context = request.getRequestContext();
    // we assume a PublishedWorkChapter as content bean, thus expect a PublishedWork as "parent" document
    PolicyPage policyPage = context.getContentBean(PolicyPage.class);
    try {
        HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(policyPage, context.getSiteContentBaseBean(), linkPath, Policy.class, false);
        // chapter cannot be re-used across different publishedworkflow
        linkedBeanQuery.setLimit(1);
        // linked documents will contain the publishedworkflow document containing all the chapters
        HstQueryResult linkedDocuments = linkedBeanQuery.execute();
        request.setAttribute("linkeddocuments", linkedDocuments);
    } catch (QueryException queryException) {
        log.warn("QueryException ", queryException);
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) PolicyPage(uk.nhs.digital.website.beans.PolicyPage) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Example 39 with HstRequestContext

use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.

the class IconLibraryComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
    super.doBeforeRender(request, response);
    HstRequestContext requestContext = request.getRequestContext();
    try {
        QueryManager jcrQueryManager = requestContext.getSession().getWorkspace().getQueryManager();
        Query jcrQuery = jcrQueryManager.createQuery("/jcr:root/content/gallery/website/icons//element(*, hippogallery:imageset)[jcr:contains(., '.svg/')]", "xpath");
        QueryResult queryResult = jcrQuery.execute();
        request.setAttribute("icons", buildListOfIcons(queryResult.getRows(), requestContext, request.getRequestContext().getServletRequest().getParameter("icon-search")));
        request.setAttribute("requestContext", requestContext);
    } catch (RepositoryException e) {
        e.printStackTrace();
    }
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) QueryManager(javax.jcr.query.QueryManager) RepositoryException(javax.jcr.RepositoryException) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext)

Example 40 with HstRequestContext

use of org.hippoecm.hst.core.request.HstRequestContext in project hippo by NHS-digital-website.

the class FinancialLinkedBeansComponent method doBeforeRender.

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) {
    super.doBeforeRender(request, response);
    // linkPath property contains the relative path of the links property in the published workflow document
    String linkPath = getComponentParameter("linkPath");
    final HstRequestContext context = request.getRequestContext();
    // we assume a Financial as content bean, thus expect a PublishedWork as "parent" document
    Financial financial = context.getContentBean(Financial.class);
    try {
        HstQuery linkedBeanQuery = ContentBeanUtils.createIncomingBeansQuery(financial, context.getSiteContentBaseBean(), linkPath, Publishedwork.class, false);
        // chapter cannot be re-used across different publishedworkflow
        linkedBeanQuery.setLimit(1);
        // linked documents will contain the publishedworkflow document containing all the chapters
        HstQueryResult linkedDocuments = linkedBeanQuery.execute();
        request.setAttribute("linkeddocuments", linkedDocuments);
    } catch (QueryException queryException) {
        log.warn("QueryException ", queryException);
    }
}
Also used : HstQuery(org.hippoecm.hst.content.beans.query.HstQuery) QueryException(org.hippoecm.hst.content.beans.query.exceptions.QueryException) Financial(uk.nhs.digital.website.beans.Financial) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) HstQueryResult(org.hippoecm.hst.content.beans.query.HstQueryResult)

Aggregations

HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)42 HstQuery (org.hippoecm.hst.content.beans.query.HstQuery)17 QueryException (org.hippoecm.hst.content.beans.query.exceptions.QueryException)11 HstQueryResult (org.hippoecm.hst.content.beans.query.HstQueryResult)8 HippoBean (org.hippoecm.hst.content.beans.standard.HippoBean)8 RepositoryException (javax.jcr.RepositoryException)6 Query (javax.jcr.query.Query)5 QueryManager (javax.jcr.query.QueryManager)5 QueryResult (javax.jcr.query.QueryResult)5 HippoBeanIterator (org.hippoecm.hst.content.beans.standard.HippoBeanIterator)5 Node (javax.jcr.Node)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 NodeIterator (javax.jcr.NodeIterator)3 HstComponentException (org.hippoecm.hst.core.component.HstComponentException)3 ValueList (org.onehippo.forge.selection.hst.contentbean.ValueList)3 Collectors (java.util.stream.Collectors)2 IteratorUtils.toList (org.apache.commons.collections.IteratorUtils.toList)2 ObjectBeanManagerException (org.hippoecm.hst.content.beans.ObjectBeanManagerException)2 ObjectConverter (org.hippoecm.hst.content.beans.manager.ObjectConverter)2 Constraint (org.hippoecm.hst.content.beans.query.builder.Constraint)2