@Override public HstRequestContext getRequestContext() { return request.getRequestContext(); }
@Override public void doAction(HstRequest request, HstResponse response) throws HstComponentException { doDispatch(getDispatchPathParameter(request, request.getLifecyclePhase()), request, response); if (Boolean.parseBoolean(getParameter(SHARED_REQUEST_ATTRIBUTES_PARAM_NAME, request, null))) { String sharedAttributeNamePrefix = getParameter(SHARED_REQUEST_ATTRIBUTES_SESSION_ATTRIBUTE_NAME_PREFIX_PARAM_NAME, request, DEFAULT_SHARED_REQUEST_ATTRIBUTES_SESSION_ATTRIBUTE_NAME_PREFIX); String sharedAttributeName = sharedAttributeNamePrefix + response.getNamespace(); Map<String, Object> sharedAttrMap = new HashMap<String, Object>(); String attrName = null; Object attrValue = null; for (Enumeration attrNames = request.getAttributeNames(); attrNames.hasMoreElements(); ) { attrName = (String) attrNames.nextElement(); if (!attrName.startsWith("javax.")) { attrValue = request.getAttribute(attrName); if (attrValue != null) { sharedAttrMap.put(attrName, attrValue); } } } request.getSession(true).setAttribute(sharedAttributeName, sharedAttrMap); } }
/** * Also see {@link #getPublicRequestParameter(HstRequest, String)}. * * @param request * @param parameterName * @return The public request parameters String array for parameterName. If no values for parameterName found, <code>new String[0]</code> is returned */ public String[] getPublicRequestParameters(HstRequest request, String parameterName) { String contextNamespaceReference = request.getRequestContext().getContextNamespace(); if (contextNamespaceReference == null) { contextNamespaceReference = ""; } Map<String, String []> namespaceLessParameters = request.getParameterMap(contextNamespaceReference); String [] paramValues = namespaceLessParameters.get(parameterName); if (paramValues != null && paramValues.length > 0) { return paramValues; } return new String[0]; }
/** * 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; }
/** * Sets content bean onto request. If no bean is found, 404 response will be set. * * @param request HstRequest * @param response HstResponse */ public void setContentBeanWith404(final HstRequest request, final HstResponse response) { final HstRequestContext context = request.getRequestContext(); final HippoBean bean = context.getContentBean(); if (bean == null) { pageNotFound(response); return; } request.setModel(REQUEST_ATTR_DOCUMENT, bean); }
@Override public void doBeforeRender(HstRequest request, HstResponse response) throws HstComponentException { request.setAttribute(LIFECYCLE_PHASE_ATTRIBUTE, BEFORE_RENDER_PHASE); String dispatchPath = getDispatchPathParameter(request, request.getLifecyclePhase()); HttpSession session = request.getSession(false); attrValue = request.getAttribute(attrName); request.setAttribute(attrName, entry.getValue()); doDispatch(getDispatchPathParameter(request, BEFORE_RENDER_PHASE), request, response); } finally { request.removeAttribute(LIFECYCLE_PHASE_ATTRIBUTE);
@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); } }
Session impersonated = null; try { Session session = request.getRequestContext().getSession(); String writableUserProperty = getWritableUserName(); String writablePasswordProperty = getWritablePassword(); ContainerConfiguration config = request.getRequestContext().getContainerConfiguration(); if(request.getParameter(request.getReferenceNamespace()+":"+DEFAULT_UUID_NAME) != null) { postedFormDataNode.setProperty(HST_PREDECESSOR, request.getParameter(request.getReferenceNamespace()+":"+DEFAULT_UUID_NAME));
public void doBeforeRender(HstRequest request, HstResponse response) throws HstComponentException { HstPortletRequestContext prc = (HstPortletRequestContext)request.getRequestContext(); PortletPreferences prefs = prc.getPortletRequest().getPreferences(); request.setAttribute(PREF_VALUES_ATTR_NAME, prc.getPortletRequest().getPreferences().getMap()); } catch (Exception e) { if (logger.isDebugEnabled()) { hstSiteMenuName = getComponentConfiguration().getParameter("hstsitemenuname", request.getRequestContext().getResolvedSiteMapItem()); HstSiteMenu menu = request.getRequestContext().getHstSiteMenus().getSiteMenu(hstSiteMenuName); request.setAttribute(HST_SITE_MENU_ATTR_NAME, editableMenu);
protected PageErrorHandler.Status handleComponentExceptions(PageErrors pageErrors, HstContainerConfig requestContainerConfig, HstComponentWindow window, HstRequest hstRequest, HstResponse hstResponse) { if (!pageErrors.isEmpty()) { final HttpServletRequest request = hstRequest.getRequestContext().getServletRequest(); log.warn("Component exception(s) found in page request, '{}'.", request); PageErrorHandler pageErrorHandler = (PageErrorHandler) hstRequest.getAttribute(ContainerConstants.CUSTOM_ERROR_HANDLER_PARAM_NAME);
HstComponentWindow window = ((HstRequestImpl) hstRequest).getComponentWindow(); windowName = window.getName(); HstRequestContext hstRequestContext = hstRequest.getRequestContext(); HstContainerURL url = hstRequestContext.getBaseURL(); pathInfo = url.getPathInfo(); refNamespace = hstRequest.getReferenceNamespace(); if ("".equals(refNamespace)) { refNamespace = "root";
if (HstRequest.ACTION_PHASE.equals(request.getLifecyclePhase()) || !request.getRequestContext().isPortletContext()) { sendRedirect(request, response, path, queryParams, characterEncoding); } else {
return; if(request.getParameter(DEFAULT_UUID_NAME) != null) { String uuid = request.getParameter(DEFAULT_UUID_NAME); try { Session session = request.getRequestContext().getSession(); Node persistedFormData = session.getNodeByUUID(uuid);
@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); } }
if (request.getParameter(request.getReferenceNamespace() + ":" + DEFAULT_UUID_NAME) != null) { postedFormDataNode.setProperty(HST_PREDECESSOR, request.getParameter(request.getReferenceNamespace() + ":" + DEFAULT_UUID_NAME)); if (RESOURCE_PHASE.equals(request.getLifecyclePhase())) { log.debug("During {} a request does not (yet) support set render parameter. Skipping setting render parameter", RESOURCE_PHASE); } else {
/** * 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)); } }
protected void doDispatch(String dispatchPath, HstRequest request, HstResponse response) throws HstComponentException { if (dispatchPath != null) { try { servletContext.getRequestDispatcher(dispatchPath).include(request, response); } catch (ServletException e) { throw new HstComponentException(e); } catch (IOException e) { throw new HstComponentException(e); } } else { if (log.isDebugEnabled()) { log.debug("The dispatch path is null. The lifecycle phase is {} and the dispatch lifecycle phase is {}", request.getLifecyclePhase(), request.getAttribute(LIFECYCLE_PHASE_ATTRIBUTE)); } } }
/** * 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)); }
HstRequest hstRequest = HstRequestUtils.getHstRequest(request); boolean isActionPhase = (hstRequest != null && HstRequest.ACTION_PHASE.equals(hstRequest.getLifecyclePhase())); boolean renderable = true; String modelAndViewOfActionSessionAttributeName = getModelAndViewOfActionSessionAttributeName(hstRequest); hstRequest.getSession(true).setAttribute(modelAndViewOfActionSessionAttributeName, mv);
/** * Also see {@link #getPublicRequestParameter(HstRequest, String)}. * * @param request * @param parameterName * @return The public request parameters String array for parameterName. If no values for parameterName found, <code>new String[0]</code> is returned */ public String[] getPublicRequestParameters(HstRequest request, String parameterName) { Map<String, String []> namespaceLessParameters = request.getParameterMap(""); String [] paramValues = namespaceLessParameters.get(parameterName); if (paramValues != null && paramValues.length > 0) { return paramValues; } return ArrayUtils.EMPTY_STRING_ARRAY; }