/** * Adds three request attributes to the request: * <ul> * <li>"currentYear" with the current year in yyyy format.</li> * <li>"currentMonth" with the current month in MM format, so with leading zeros.</li> * <li>"currentDay" with the current day of the month in dd format, so with leading zeros.</li> * </ul> */ public static void addCurrentDateStrings(final HstRequest request) { final LocalDate now = LocalDate.now(); request.setAttribute("currentYear", now.format(YEAR_FORMAT)); request.setAttribute("currentMonth", now.format(MONTH_FORMAT)); request.setAttribute("currentDay", now.format(DAY_FORMAT)); }
protected void setComponentId(final HstRequest request, final HstResponse response) { if (RequestContextProvider.get().isCmsRequest()) { request.setAttribute(REQUEST_ATTR_COMPONENT_ID, UUID.randomUUID().toString()); } else { request.setAttribute(REQUEST_ATTR_COMPONENT_ID, response.getNamespace()); } }
protected void setEditMode(final HstRequest request) { request.setAttribute(REQUEST_ATTR_CMS_EDIT, RequestContextProvider.get().isCmsRequest()); }
@Override public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException { super.doBeforeRender(request, response); setComponentId(request, response); final EssentialsGoogleMapsComponentInfo paramInfo = getComponentParametersInfo(request); request.setAttribute(REQUEST_ATTR_PARAM_INFO, paramInfo); request.setAttribute("cmsrequest", RequestContextProvider.get().isCmsRequest()); } }
/** * Populates request with search results * * @param request HstRequest * @param paramInfo EssentialsPageable instance * @param pageable search results (Pageable<HippoBean>) * @see CommonComponent#REQUEST_ATTR_QUERY * @see CommonComponent#REQUEST_ATTR_PAGEABLE * @see CommonComponent#REQUEST_ATTR_PAGE */ protected void populateRequest(final HstRequest request, final EssentialsPageable paramInfo, final Pageable<? extends HippoBean> pageable) { request.setAttribute(REQUEST_ATTR_QUERY, getSearchQuery(request)); request.setModel(REQUEST_ATTR_PAGEABLE, pageable); request.setAttribute(REQUEST_ATTR_PARAM_INFO, paramInfo); if (pageable != null) { pageable.setShowPagination(isShowPagination(request, paramInfo)); } }
@Override public void doBeforeRender(final HstRequest request, final HstResponse response) { super.doBeforeRender(request, response); final EssentialsDocumentComponentInfo paramInfo = getComponentParametersInfo(request); final String documentPath = paramInfo.getDocument(); log.debug("Calling EssentialsDocumentComponent for document path: [{}]", documentPath); setContentBeanForPath(documentPath, request, response); request.setAttribute(REQUEST_ATTR_PARAM_INFO, paramInfo); }
/** * Returns a proxy ParametersInfo object for the component class 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 * <p/> * <EM>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.</EM> </P> * <p/> * The parameter map used has inherited parameters from ancestor components, which have precedence over child * components) * * @param component the HST component with a ParameterInfo annotation * @param componentConfig the HST component configuration * @param request the HST request * @return the resolved parameter value for this name, or <code>null</null> if not present */ @SuppressWarnings("unchecked") public static <T> T getParametersInfo(HstComponent component, final ComponentConfiguration componentConfig, final HstRequest request) { T parametersInfo = (T) request.getAttribute(PARAMETERS_INFO_ATTRIBUTE); if (parametersInfo != null) { return parametersInfo; } parametersInfo = ParametersInfoUtils.createParametersInfo(component, componentConfig, request); if (parametersInfo != null) { request.setAttribute(PARAMETERS_INFO_ATTRIBUTE, parametersInfo); } return parametersInfo; }
@Override public void doBeforeRender(final HstRequest request, final HstResponse response) { super.doBeforeRender(request, response); final EssentialsImageComponentInfo paramInfo = getComponentParametersInfo(request); final String documentPath = paramInfo.getDocument(); log.debug("Calling EssentialsImageComponent for document path: [{}]", documentPath); if (!Strings.isNullOrEmpty(documentPath)) { try { final Object image = RequestContextProvider.get().getObjectBeanManager().getObject(documentPath); request.setModel(REQUEST_ATTR_DOCUMENT, image); } catch (ObjectBeanManagerException e) { if (log.isDebugEnabled()) { log.error("Error getting image", e); } } } request.setAttribute(REQUEST_ATTR_PARAM_INFO, paramInfo); } }
@Override public void doBeforeRender(final HstRequest request, final HstResponse response) { super.doBeforeRender(request, response); final EssentialsMenuComponentInfo paramInfo = getComponentParametersInfo(request); String siteMenu = paramInfo.getSiteMenu(); if (Strings.isNullOrEmpty(siteMenu)) { log.warn("No site menu is selected within EssentialsMenuComponent nor set as a component parameter (menuName)"); return; } siteMenu = CharMatcher.WHITESPACE.trimFrom(siteMenu); final HstSiteMenu menu = request.getRequestContext().getHstSiteMenus().getSiteMenu(siteMenu); if (menu == null) { log.warn("Invalid site menu is selected within EssentialsMenuComponent: {}", siteMenu); return; } log.debug("Using site menu:[{}]", siteMenu); request.setModel("menu", menu); request.setAttribute(REQUEST_ATTR_PARAM_INFO, paramInfo); } }
@Override public void doBeforeRender(HstRequest request, HstResponse response) throws HstComponentException { request.setAttribute(LIFECYCLE_PHASE_ATTRIBUTE, BEFORE_RENDER_PHASE); request.setAttribute(attrName, entry.getValue());
@Override public void doBeforeRender(HstRequest request, HstResponse response) throws HstComponentException { request.setAttribute(LIFECYCLE_PHASE_ATTRIBUTE, BEFORE_RENDER_PHASE); request.setAttribute(attrName, entry.getValue());
@Override public void doBeforeRender(final HstRequest request, final HstResponse response) { super.doBeforeRender(request, response); final EssentialsFacetsComponentInfo paramInfo = getComponentParametersInfo(request); final HstRequestContext context = request.getRequestContext(); String facetPath = paramInfo.getFacetPath(); // check if component is used through sitemap mapping: if (Strings.isNullOrEmpty(facetPath)) { final HippoBean bean = context.getContentBean(); if (bean != null) { facetPath = bean.getPath(); } } final String queryParam = cleanupSearchQuery(getAnyParameter(request, REQUEST_PARAM_QUERY)); final HippoFacetNavigationBean hippoFacetNavigationBean = getFacetNavigationBean(context, facetPath, queryParam); request.setAttribute(REQUEST_ATTR_QUERY, queryParam); request.setModel(REQUEST_ATTR_FACETS, hippoFacetNavigationBean); request.setAttribute(REQUEST_ATTR_PARAM_INFO, paramInfo); }
@Override public void doBeforeRender(final HstRequest request, final HstResponse response) { super.doBeforeRender(request, response); setComponentId(request, response); final EssentialsCarouselComponentInfo paramInfo = getComponentParametersInfo(request); request.setAttribute(REQUEST_ATTR_PARAM_INFO, paramInfo); final List<HippoDocument> items = getCarouselItems(paramInfo); request.setModel(REQUEST_ATTR_PAGEABLE, new DefaultPagination<>(items)); }
@Override public void doBeforeRender(final HstRequest request, final HstResponse response) { final EssentialsListPickerComponentInfo paramInfo = getComponentParametersInfo(request); final List<HippoDocument> documentItems = getDocumentItems(paramInfo); final int pageSize = getPageSize(request, paramInfo); final int page = getAnyIntParameter(request, REQUEST_PARAM_PAGE, 1); final Pageable<HippoDocument> pageable = getPageableFactory().createPageable(documentItems, page, pageSize); request.setModel(REQUEST_ATTR_PAGEABLE, pageable); request.setAttribute(REQUEST_ATTR_PARAM_INFO, paramInfo); }
request.setAttribute(PREF_VALUES_ATTR_NAME, prc.getPortletRequest().getPreferences().getMap()); } catch (Exception e) { if (logger.isDebugEnabled()) { request.setAttribute(HST_SITE_MENU_ATTR_NAME, editableMenu);
@Override public void doBeforeServeResource(HstRequest request, HstResponse response) throws HstComponentException { super.doBeforeServeResource(request, response); request.setAttribute(LIFECYCLE_PHASE_ATTRIBUTE, BEFORE_RESOURCE_PHASE); String dispatchPath = getDispatchPathParameter(request, request.getLifecyclePhase()); if (dispatchPath != null) { response.setServeResourcePath(dispatchPath); } try { doDispatch(getDispatchPathParameter(request, BEFORE_RESOURCE_PHASE), request, response); } finally { request.removeAttribute(LIFECYCLE_PHASE_ATTRIBUTE); } }
@Override public void doBeforeServeResource(HstRequest request, HstResponse response) throws HstComponentException { super.doBeforeServeResource(request, response); request.setAttribute(LIFECYCLE_PHASE_ATTRIBUTE, BEFORE_RESOURCE_PHASE); String dispatchPath = getDispatchPathParameter(request, request.getLifecyclePhase()); if (dispatchPath != null) { response.setServeResourcePath(dispatchPath); } try { doDispatch(getDispatchPathParameter(request, BEFORE_RESOURCE_PHASE), request, response); } finally { request.removeAttribute(LIFECYCLE_PHASE_ATTRIBUTE); } }
request.setAttribute("author", authors.get(0)); request.setModel("authors", authors); final Class<? extends HippoBean> clazz = getPrimaryType(context, document); log.error("Error fetching posts by authors", e); request.setAttribute(REQUEST_ATTR_PARAM_INFO, paramInfo);
/** * returns <code>true</code> when the component window is marked as async. When the component is async due to a * ancestor is async, we also set <code>{@link #ASYNC_RENDERED_BY_ANCESTOR_FLAG_ATTR_NAME}</code> is * <code>true</code> on the HstRequest to indicate async due to ancestor * * @param window * @param request * @return */ private boolean isAsync(final HstComponentWindow window, final HstRequest request) { // in cms request context, we never load asynchronous if (request.getRequestContext().isCmsRequest()) { return false; } if (request.getRequestContext().getBaseURL().getComponentRenderingWindowReferenceNamespace() != null) { return false; } // check if there is already an async parent. HstComponentWindow parent = window.getParentWindow(); while (parent != null) { if (parent.getComponentInfo().isAsync()) { request.setAttribute(ASYNC_RENDERED_BY_ANCESTOR_FLAG_ATTR_NAME, Boolean.TRUE); return true; } parent = parent.getParentWindow(); } // check whether the component itself is asyn return window.getComponentInfo().isAsync(); }