public static String relativePathFrom(final String absolutePath, final HstRequestContext context) { final String basePath = context.getSiteContentBasePath(); if (!absolutePath.substring(1).startsWith(basePath)) { log.warn("Absolute path '{}' is outside the scope of the requested site.", absolutePath); return absolutePath; } return absolutePath.substring(1 + basePath.length() + 1); // exclude '/' before and after basePath. }
/** * @param request * @return the jcr path relative to the root (not starting with / thus) * @deprecated since 7.9.0 : use {@link org.hippoecm.hst.core.request.HstRequestContext#getSiteContentBasePath()} instead */ @Deprecated public String getSiteContentBasePath(HstRequest request){ return request.getRequestContext().getSiteContentBasePath(); }
private String getAbsoluteRootPath(final HstRequestContext requestContext) { if (StringUtils.startsWith(rootPath, "/")) { return rootPath; } else { return "/" + requestContext.getSiteContentBasePath() + "/" + rootPath; } }
protected String getSiteContentBasePath(HstRequest request){ return request.getRequestContext().getSiteContentBasePath(); }
/** * Try to determine the site-relative repository path of a bean, given a request context. * * If the bean doesn't fall under the requested site root, just return the bean's full path. * * @param bean representing the desired repository node * @param context current HST context * @return relative repository path of the bean under the current site root, * or absolute path if the bean is not under the current site root. */ public static String relativePathFrom(final HippoBean bean, final HstRequestContext context) { final String basePath = context.getSiteContentBasePath(); final String beanPath = bean.getCanonicalPath(); if (!Strings.isNullOrEmpty(beanPath) && beanPath.substring(1).startsWith(basePath)) { return beanPath.substring(1 + basePath.length() + 1); // skip slashes } return beanPath; }
/** * Tries to return a bean that is located in a faceted navigation tree below a result set. When it cannot be found, * or the bean is not of type <code>beanMappingClass</code>, <code>null</code> will be returned. * * @param <T> * @param query the free text search as String that is used for this faceted navigation. The query should already * have been processed by {@link org.hippoecm.hst.util.SearchInputParsingUtils#parse(String, boolean)} * if necessary. * @param relPath the relative path from site base content to the faceted navigation node, which must not start with a / and is relative to the site content base path * @param beanMappingClass the class T must be of * @return The faceted navigation result document of type T and <code>null</code> if it cannot be found or is not of type <code>T</code> */ public static <T extends HippoBean> T getFacetedNavigationResultDocument(final String query, final String relPath, final Class<T> beanMappingClass) { final HstRequestContext requestContext = RequestContextProvider.get(); if (requestContext == null) { throw new HstComponentException("Cannot call #getFacetNavigationBean without HstRequestContext"); } return getFacetedNavigationResultDocument(query, "/"+requestContext.getSiteContentBasePath(), relPath, beanMappingClass); }
/** * @see {@link #getFacetNavigationBean(String, String, String)} with <code>absBasePath</code> as "/"+ requestContext.getSiteContentBasePath(); */ public static HippoFacetNavigationBean getFacetNavigationBean(String relPath, String query) throws HstComponentException { final HstRequestContext requestContext = RequestContextProvider.get(); if (requestContext == null) { throw new HstComponentException("Cannot call #getFacetNavigationBean without HstRequestContext"); } if(relPath == null) { log.warn("Cannot return a content bean for relative path null for resolvedSitemapItem belonging to '{}'. Return null", requestContext.getResolvedSiteMapItem().getHstSiteMapItem().getId()); return null; } String absBasePath = "/"+ requestContext.getSiteContentBasePath(); return getFacetNavigationBean(absBasePath, relPath, query); }
/** * Return a <code>HippoBean</code> when it can be found for the relativeContentPath for the <code>{@link ResolvedSiteMapItem}</code>. If there is no * relativeContentPath available in the <code>{@link ResolvedSiteMapItem}</code>, or when the relativeContentPath does not point to an existing jcr node, * <code>null</code> will be returned * @param request * @param resolvedSiteMapItem * @return A <code>HippoBean</code> or <code>null</code> when there cannot be created a content bean for this resolvedSiteMapItem */ public HippoBean getBeanForResolvedSiteMapItem(HstRequest request, ResolvedSiteMapItem resolvedSiteMapItem) { final HstRequestContext requestContext = request.getRequestContext(); String base = requestContext.getSiteContentBasePath(); String relPath = PathUtils.normalizePath(resolvedSiteMapItem.getRelativeContentPath()); if(relPath == null) { log.debug("Cannot return a content bean for relative path null for resolvedSitemapItem belonging to '{}'. Return null", resolvedSiteMapItem.getHstSiteMapItem().getId()); return null; } try { if("".equals(relPath)) { return (HippoBean) requestContext.getObjectBeanManager().getObject("/"+base); } else { return (HippoBean) requestContext.getObjectBeanManager().getObject("/"+base+ "/" + relPath); } } catch (ObjectBeanManagerException e) { log.error("ObjectBeanManagerException. Return null : {}", e); } return null; }