@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); } }
/** * Returns all exceptions which have the <CODE>causeType</CODE> and generated by a component of <CODE>componentInfo</CODE>. * * @param pageErrors * @param causeType * @return */ public static Collection<HstComponentException> getExceptionsByCauseType(PageErrors pageErrors, HstComponentInfo componentInfo, Class<? extends Throwable> causeType) { List<HstComponentException> exceptions = null; for (HstComponentException exception : pageErrors.getComponentExceptions(componentInfo)) { Throwable cause = exception.getCause(); if (cause != null && causeType.isAssignableFrom(cause.getClass())) { if (exceptions == null) { exceptions = new ArrayList<HstComponentException>(); } exceptions.add(exception); } } if (exceptions == null) { exceptions = Collections.emptyList(); } return exceptions; }
log.warn("Component exception caught: " + e.toString(), e); } else if (log.isWarnEnabled()) { log.warn("Component exception caught: {}", e.toString()); throw new HstComponentException(e); window.addComponentExcpetion(new HstComponentException(e)); window.addComponentExcpetion(new HstComponentException("The component is not available."));
protected void logWarningsForEachComponentExceptions(PageErrors pageErrors) { for (HstComponentInfo componentInfo : pageErrors.getComponentInfos()) { for (HstComponentException componentException : pageErrors.getComponentExceptions(componentInfo)) { if (log.isDebugEnabled()) { log.warn("Component exception found on " + componentInfo.getComponentClassName(), componentException); } else if (log.isWarnEnabled()) { log.warn("Component exception found on {}. ", componentInfo.getComponentClassName(), componentException.toString()); } } } }
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"); } }
log.warn("Component exception caught on window " + window.getName() + " with component " + component.getClass().getName() + ": " + e.toString(), e); } else if (log.isWarnEnabled()) { log.warn("Component exception caught on window " + window.getName() + " with component " + component.getClass().getName() + ": {}", e.toString()); throw new HstComponentException(e); window.addComponentExcpetion(new HstComponentException(e)); window.addComponentExcpetion(new HstComponentException("The component is not available."));
/** * Returns all exceptions which have the <CODE>causeType</CODE>. * * @param pageErrors * @param causeType * @return */ public static Collection<HstComponentException> getExceptionsByCauseType(PageErrors pageErrors, Class<? extends Throwable> causeType) { List<HstComponentException> exceptions = null; for (HstComponentException exception : pageErrors.getAllComponentExceptions()) { Throwable cause = exception.getCause(); if (cause != null && causeType.isAssignableFrom(cause.getClass())) { if (exceptions == null) { exceptions = new ArrayList<HstComponentException>(); } exceptions.add(exception); } } if (exceptions == null) { exceptions = Collections.emptyList(); } return exceptions; }
protected BeanFactory getContextBeanFactory(final ServletContext servletContext, final String [] contextNames) { BeanFactory beanFactory = null; String contextName = null; try { int beginIndex; if (contextNames.length > 0 && StringUtils.startsWith(contextNames[0], FrameworkServlet.SERVLET_CONTEXT_PREFIX)) { beanFactory = WebApplicationContextUtils.getWebApplicationContext(servletContext, contextNames[0]); beginIndex = 1; } else { beanFactory = WebApplicationContextUtils.getWebApplicationContext(servletContext); beginIndex = 0; } if (contextNames != null) { for (int i = beginIndex; i < contextNames.length; i++) { contextName = contextNames[i]; beanFactory = (BeanFactory) beanFactory.getBean(contextName); } } } catch (NoSuchBeanDefinitionException e) { throw new HstComponentException("There's no beanFactory definition with the specified name: " + contextName, e); } catch (BeansException e) { throw new HstComponentException("The beanFactory cannot be obtained: " + contextName, e); } catch (ClassCastException e) { throw new HstComponentException("The bean is not an instance of beanFactory: " + contextName, e); } catch (Exception e) { throw new HstComponentException("The beanFactory cannot be obtained: " + contextName, e); } return beanFactory; }
log.warn("Component exception caught on window " + window.getName() + " with component " + component.getClass().getName() + ": " + e.toString(), e); } else if (log.isWarnEnabled()) { log.warn("Component exception caught on window " + window.getName() + " with component " + component.getClass().getName() + ": {}", e.toString()); throw new HstComponentException(e); window.addComponentExcpetion(new HstComponentException(e)); window.addComponentExcpetion(new HstComponentException("The component is not available."));
Throwable cause = exception.getCause();
@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; }
log.warn("Component exception caught on window " + window.getName() + " with component " + component.getClass().getName() + ": " + e.toString(), e); } else if (log.isWarnEnabled()) { log.warn("Component exception caught on window " + window.getName() + " with component " + component.getClass().getName() + ": {}", e.toString()); throw new HstComponentException(e); window.addComponentExcpetion(new HstComponentException(e));
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)); } } }
log.warn("Component exception caught on window " + window.getName() + " with component " + component.getClass().getName() + ": " + e.toString(), e); } else if (log.isWarnEnabled()) { log.warn("Component exception caught on window " + window.getName() + " with component " + component.getClass().getName() + ": {}", e.toString()); throw new HstComponentException(e); window.addComponentExcpetion(new HstComponentException(e));
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); } }
throw new HstComponentException("The name of delegated spring bean is null."); throw new HstComponentException("There's no beanFactory definition with the specified name: " + contextName, e); } catch (BeansException e) { throw new HstComponentException("The beanFactory cannot be obtained: " + contextName, e); } catch (ClassCastException e) { throw new HstComponentException("The bean is not an instance of beanFactory: " + contextName, e); throw new HstComponentException("Cannot find the root web application context or client component manager."); } else if (beanFactory != null && componentManager == null) { throw new HstComponentException("Cannot find delegated spring HstComponent bean from the web application context: " + beanName); } else if (beanFactory == null && componentManager != null) { throw new HstComponentException("Cannot find delegated spring HstComponent bean from the client component manager: " + beanName); } else { throw new HstComponentException("Cannot find delegated spring HstComponent bean from either the web application context or the client component manager: " + beanName);
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; }