@SuppressWarnings("unchecked") public <T> T getObjectInstance(HstContainerConfig requestContainerConfig, String className) throws HstComponentException { try { Class<T> clazz = (Class<T>) Class.forName(className); return (T) clazz.newInstance(); } catch (ClassNotFoundException e) { throw new HstComponentException("Cannot find the class of " + className); } catch (InstantiationException e) { throw new HstComponentException("Cannot instantiate the class of " + className); } catch (IllegalAccessException e) { throw new HstComponentException("Illegal access to the class of " + className); } }
protected void handleInvalidScope(final HstRequest request, final HstResponse response) { // TODO determine what to do with invalid scope response.setStatus(HttpServletResponse.SC_NOT_FOUND); if (log.isDebugEnabled()) { throw new HstComponentException("EssentialsListComponent needs a valid scope to display documents"); } }
@SuppressWarnings("unchecked") public <T> T getObjectInstance(HstContainerConfig requestContainerConfig, String className) throws HstComponentException { T object = null; ClassLoader containerClassloader = requestContainerConfig.getContextClassLoader(); ClassLoader currentClassloader = Thread.currentThread().getContextClassLoader(); try { if (containerClassloader != currentClassloader) { Thread.currentThread().setContextClassLoader(containerClassloader); } Class<T> clazz = (Class<T>) containerClassloader.loadClass(className); object = (T) clazz.newInstance(); } catch (ClassNotFoundException e) { throw new HstComponentException("Cannot find the class of " + className); } catch (InstantiationException e) { throw new HstComponentException("Cannot instantiate the class of " + className); } catch (IllegalAccessException e) { throw new HstComponentException("Illegal access to the class of " + className); } finally { if (containerClassloader != currentClassloader) { Thread.currentThread().setContextClassLoader(currentClassloader); } } return object; }
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)); } } }
public ObjectBeanManager getObjectBeanManager(HstRequest request) { try { HstRequestContext requestContext = request.getRequestContext(); return new ObjectBeanManagerImpl(requestContext.getSession(), this.objectConverter); } catch (UnsupportedRepositoryOperationException e) { throw new HstComponentException(e); } catch (RepositoryException e) { throw new HstComponentException(e); } }
protected void doDispatch(String dispatchPath, HstRequest request, HstResponse response) throws HstComponentException { if (dispatchPath != null) { try { getServletContext().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)); } } }
public String toString() { HstContainerURL containerURL = this.urlProvider.createURL(this.baseContainerURL, this); containerURL.setResourceId(getResourceID()); try { return this.urlProvider.toURLString(containerURL, requestContext); } catch (UnsupportedEncodingException e) { throw new HstComponentException(e); } catch (ContainerException e) { throw new HstComponentException(e); } }
public String toString() { HstContainerURL containerURL = this.urlProvider.createURL(this.baseContainerURL, this); containerURL.setResourceId(getResourceID()); try { return this.urlProvider.toURLString(containerURL, requestContext, explicitContextPath); } catch (UnsupportedEncodingException e) { throw new HstComponentException(e); } catch (ContainerException e) { throw new HstComponentException(e); } }
public Session getSession() throws LoginException, RepositoryException { if (this.session == null) { this.session = this.repository.login(contextCredentialsProvider.getDefaultCredentials(this)); } else if (!this.session.isLive()) { throw new HstComponentException("Invalid session."); } return this.session; }
public static Session getPreviewCmsQuerySession(HstRequestContext requestContext, String sessionIdentifier) throws HstComponentException { try { SessionSecurityDelegation sessionSecurityDelegation = HstServices.getComponentManager().getComponent(SessionSecurityDelegation.class.getName()); if (!sessionSecurityDelegation.sessionSecurityDelegationEnabled()) { log.debug("Security Delegation was expected to be enabled for cms request with non proxied session but it was not enabled. " + "Return session from request context instead of new security delegated one"); return requestContext.getSession(true); } Credentials cmsUserCred = (Credentials) requestContext.getServletRequest().getAttribute(ContainerConstants.CMS_REQUEST_REPO_CREDS_ATTR); if (cmsUserCred == null) { throw new IllegalStateException("HttpServletRequest should contain cms user credentials attribute for cms requests"); } // create a security delegated session that is automatically cleaned up at the end of the request return sessionSecurityDelegation.getOrCreatePreviewSecurityDelegate(cmsUserCred, sessionIdentifier); } catch (RepositoryException e) { throw new HstComponentException(e); } }
/** * Same as {@link #getFacetNavigationBean(String)} only now instead of a {@link String} query we * pass in a {@link HstQuery} * @see {@link #getFacetNavigationBean(String)} * */ public static HippoFacetNavigationBean getFacetNavigationBean(HstQuery query) throws HstComponentException { if(query == null) { return getFacetNavigationBean((String)null); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetNavigationBean(queryAsString); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
/** * 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); }
/** * Same as {@link #getFacetNavigationBean(HstQuery)} only now instead of having the faceted navigation * node from the {@link ResolvedSiteMapItem} we add a <code>relPath</code> where it should be found * @see {@link #getFacetNavigationBean(String)} * @param query a {@link HstQuery} object * @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 * @return the <code>HippoFacetNavigationBean</code> accounted for this <code>query</code> and <code>relPath</code> and <code>null</code> if we could not find the HippoFacetNavigationBean when the <code>query</code> is applied * @throws HstComponentException */ public static HippoFacetNavigationBean getFacetNavigationBean(HstQuery query, String relPath) throws HstComponentException { if(query == null) { return getFacetNavigationBean((String)null); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetNavigationBean(relPath, queryAsString); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
/** * 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 {@link HstQuery} that is used for this faceted navigation * @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(HstQuery query, Class<T> beanMappingClass) { if(query == null) { return getFacetedNavigationResultDocument((String)null, beanMappingClass); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetedNavigationResultDocument(queryAsString, beanMappingClass); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
/** * 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 {@link HstQuery} that is used for this faceted navigation * @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(HstQuery query, String relPath, Class<T> beanMappingClass) { if(query == null) { return getFacetedNavigationResultDocument((String)null, relPath, beanMappingClass); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetedNavigationResultDocument(queryAsString, relPath, beanMappingClass); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
/** * Same as {@link #getFacetNavigationBean(HstQuery)} only now instead of having the faceted navigation * node from the {@link ResolvedSiteMapItem} we add <code>absBasePath</code> and <code>relPath</code> where it should be found * @see {@link #getFacetNavigationBean(String)} * @param query a {@link HstQuery} object * @param absBasePath the absolute path (starting with /) from where to get the faceted navigation bean for <code>relPath</code> and * <code>query</code>. The <code>absBasePath</code> is NOT allowed to point to or to a descendant of a faceted navigation * node * @param relPath the relative path from absBasePath to the faceted navigation node, which must not start with a / and is relative to the site content base path * @return the <code>HippoFacetNavigationBean</code> accounted for this <code>query</code> and <code>relPath</code> and <code>null</code> if we could not find the HippoFacetNavigationBean when the <code>query</code> is applied * @throws HstComponentException */ public static HippoFacetNavigationBean getFacetNavigationBean(HstQuery query, String absBasePath, String relPath) throws HstComponentException { if(query == null) { return getFacetNavigationBean((String)null); } try { String queryAsString = "xpath("+query.getQueryAsString(true)+")"; return getFacetNavigationBean(absBasePath, relPath, queryAsString); } catch (QueryException e) { throw new HstComponentException("Unable to create a string representation of query", e); } }
public static Session getWritableSession() throws RepositoryException { if (HstServices.isAvailable()) { Credentials defaultCredentials = HstServices.getComponentManager().getComponent(Credentials.class.getName() + ".writable"); Repository repository = HstServices.getComponentManager().getComponent(Repository.class.getName()); Session session = null; if (repository != null) { if (defaultCredentials != null) { session = repository.login(defaultCredentials); } else { session = repository.login(); } } return session; } else { throw new HstComponentException("Can not get a writable sessions because HstServices are not available"); } }
/** * @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); }
/** * @see {@link #getFacetNavigationBean(String, String, String)} with <code>absBasePath</code> as "/"+ requestContext.getSiteContentBasePath() and * <code>relPath </code> as requestContext.getResolvedSiteMapItem().getRelativeContentPath() */ public static HippoFacetNavigationBean getFacetNavigationBean(String query) throws HstComponentException { final HstRequestContext requestContext = RequestContextProvider.get(); if (requestContext == null) { throw new HstComponentException("Cannot call #getFacetNavigationBean without HstRequestContext"); } ResolvedSiteMapItem resolvedSiteMapItem = requestContext.getResolvedSiteMapItem(); String relPath = PathUtils.normalizePath(resolvedSiteMapItem.getRelativeContentPath()); return getFacetNavigationBean(relPath, query); }
/** * 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 * @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(String query, Class<T> beanMappingClass) { final HstRequestContext requestContext = RequestContextProvider.get(); if (requestContext == null) { throw new HstComponentException("Cannot call #getFacetNavigationBean without HstRequestContext"); } ResolvedSiteMapItem resolvedSiteMapItem = requestContext.getResolvedSiteMapItem(); String relPath = PathUtils.normalizePath(resolvedSiteMapItem.getRelativeContentPath()); return getFacetedNavigationResultDocument(query, relPath, beanMappingClass); }