コード例 #1
0
  public <T extends HippoBean> T getHippoBeanForPath(
      final String documentPath, Class<T> beanMappingClass) {
    if (!Strings.isNullOrEmpty(documentPath)) {
      final HstRequestContext context = RequestContextProvider.get();
      final HippoBean root = context.getSiteContentBaseBean();
      return root.getBean(documentPath, beanMappingClass);
    }

    return null;
  }
コード例 #2
0
  /**
   * Find HippoBean for given path. If path is null or empty, site root bean will be returned
   *
   * @param path document (or folder) path relative to site-root
   * @return bean identified by path. Site root bean if path empty or no corresponding bean.
   */
  public static HippoBean getScopeBean(final String path) {
    final HstRequestContext context = RequestContextProvider.get();
    final HippoBean siteBean = context.getSiteContentBaseBean();

    if (!Strings.isNullOrEmpty(path)) {
      final String myPath = PathUtils.normalizePath(path);
      log.debug("Looking for bean {}", myPath);
      HippoBean scope = siteBean.getBean(myPath);
      if (scope != null) {
        return scope;
      }
      log.warn("Bean was null for selected path:  {}", myPath);
    }
    return siteBean;
  }
コード例 #3
0
 /**
  * Sets {@code HttpServletResponse.SC_NOT_FOUND} error code onto request.
  *
  * @param response
  * @see javax.servlet.http.HttpServletResponse#SC_NOT_FOUND
  */
 public void pageNotFound(HstResponse response) {
   final HstRequestContext context = RequestContextProvider.get();
   String pageNotFoundPath = getComponentParameter(PAGE_404);
   if (Strings.isNullOrEmpty(pageNotFoundPath)) {
     pageNotFoundPath = PAGE_404;
   }
   final HippoBean bean =
       context.getSiteContentBaseBean().getBean(pageNotFoundPath, HippoBean.class);
   response.setStatus(HttpServletResponse.SC_NOT_FOUND);
   if (bean != null) {
     final HstLinkCreator hstLinkCreator = context.getHstLinkCreator();
     final HstLink hstLink = hstLinkCreator.create(bean.getNode(), context);
     try {
       response.sendRedirect(hstLink.toUrlForm(context, false));
     } catch (IOException e) {
       log.warn("Error redirecting to 404 page: [{}]", PAGE_404);
     }
   } else {
     // check if we have pagenotfound config
     final ResolvedSiteMapItem resolvedSiteMapItem =
         RequestContextProvider.get().getResolvedSiteMapItem();
     if (resolvedSiteMapItem == null) {
       return;
     }
     final HstSiteMap siteMap = resolvedSiteMapItem.getHstSiteMapItem().getHstSiteMap();
     final HstSiteMapItem pagenotfound = siteMap.getSiteMapItemByRefId(PAGE_NOT_FOUND);
     if (pagenotfound != null) {
       String link = pagenotfound.getValue();
       try {
         response.forward('/' + link);
       } catch (IOException e) {
         log.error("Error forwarding to " + PAGE_NOT_FOUND + " page", e);
       }
     }
   }
 }
コード例 #4
0
 protected void setEditMode(final HstRequest request) {
   request.setAttribute(REQUEST_ATTR_CMS_EDIT, RequestContextProvider.get().isCmsRequest());
 }