Class BeanUtils

java.lang.Object
io.goobi.viewer.managedbeans.utils.BeanUtils

public final class BeanUtils extends Object
Utility class for methods that use the FacesContext.
  • Method Details

    • getRequest

      public static HttpServletRequest getRequest()
      Gets the current Request from the faces context.
      Returns:
      the current HTTP servlet request, or null if unavailable
    • getRequest

      public static HttpServletRequest getRequest(FacesContext context)
      getRequest.
      Parameters:
      context - faces context to extract the request from
      Returns:
      the HTTP servlet request from the given FacesContext, or null if unavailable
    • getSession

      public static HttpSession getSession()
      getSession.
      Returns:
      HttpSession from current request
    • getServletPathWithHostAsUrlFromJsfContext

      public static String getServletPathWithHostAsUrlFromJsfContext()
      retrieve complete Servlet url from servlet context, including Url, Port, Servletname etc. call this method only from jsf context
      Returns:
      complete url as string
    • hasJsfContext

      public static boolean hasJsfContext()
      hasJsfContext.
      Returns:
      true if a JSF FacesContext is available in the current thread, false otherwise
    • getServletImagesPathFromRequest

      public static String getServletImagesPathFromRequest(HttpServletRequest request, String theme)
      getServletImagesPathFromRequest.
      Parameters:
      request - incoming HTTP request for base URL resolution
      theme - theme folder name appended to the path
      Returns:
      the absolute URL path to the servlet images directory for the given theme
    • getServletContext

      public static ServletContext getServletContext()
      getServletContext.
      Returns:
      the current ServletContext, or null if no FacesContext is available
    • getInitialLocale

      public static Locale getInitialLocale()
      getInitialLocale.
      Returns:
      Currently selected or default Locale
    • getLocale

      public static Locale getLocale()
      getLocale.
      Returns:
      Current Locale in NavigationHelper; default locale if none found
    • getDefaultLocale

      public static Locale getDefaultLocale()
      getDefaultLocale.
      Returns:
      the default application locale
    • getBeanByName

      public static Object getBeanByName(String name, Class clazz) throws ContextNotActiveException
      getBeanByName.
      Parameters:
      name - CDI bean name to look up
      clazz - expected type used to create the CDI reference
      Returns:
      the CDI-managed bean reference for the given name and type, or null if not found
      Throws:
      ContextNotActiveException - if no jsf context is available to retrieve the bean from
    • getNavigationHelper

      public static NavigationHelper getNavigationHelper()
      getNavigationHelper.
      Returns:
      the NavigationHelper managed bean, or null if outside a JSF context
    • getAdminBean

      public static AdminBean getAdminBean()
      getAdminBean.
      Returns:
      the AdminBean managed bean
    • getCollectionViewBean

      public static CollectionViewBean getCollectionViewBean()
      getCollectionViewBean.
      Returns:
      the CollectionViewBean managed bean
    • getActiveDocumentBean

      public static ActiveDocumentBean getActiveDocumentBean()
      getActiveDocumentBean.
      Returns:
      the ActiveDocumentBean managed bean
    • getPersistentStorageBean

      public static ApplicationBean getPersistentStorageBean()
      getPersistentStorageBean.

      Returns the @ApplicationScoped ApplicationBean. The result is cached in a static volatile field after the first successful lookup to avoid repeated Weld CDI bean resolution (which involves a Thread.getStackTrace() call on every invocation).

      Returns:
      the ApplicationBean managed bean
    • getSearchBean

      public static SearchBean getSearchBean()
      getSearchBean.
      Returns:
      the SearchBean managed bean
    • getBookmarkBean

      public static BookmarkBean getBookmarkBean()
      getBookmarkBean.
      Returns:
      the BookmarkBean managed bean
    • getCreateRecordBean

      public static CreateRecordBean getCreateRecordBean()
      getCreateRecordBean.
      Returns:
      the CreateRecordBean managed bean
    • getCMSCollectionsBean

      public static CmsCollectionsBean getCMSCollectionsBean()
      getCMSCollectionsBean.
      Returns:
      the CmsCollectionsBean managed bean
    • getMetadataBean

      public static MetadataBean getMetadataBean()
      getMetadataBean.
      Returns:
      the MetadataBean managed bean
    • getCmsBean

      public static CmsBean getCmsBean()
      getCmsBean.
      Returns:
      the CmsBean managed bean
    • getCmsMediaBean

      public static CmsMediaBean getCmsMediaBean()
      getCmsMediaBean.
      Returns:
      the CmsMediaBean managed bean
    • getCalendarBean

      public static CalendarBean getCalendarBean()
      getCalendarBean.
      Returns:
      the CalendarBean managed bean
    • getCaptchaBean

      public static CaptchaBean getCaptchaBean()
      getCaptchaBean.
      Returns:
      the CaptchaBean managed bean
    • getUserBean

      public static UserBean getUserBean() throws ContextNotActiveException
      getUserBean.
      Returns:
      the UserBean managed bean
      Throws:
      ContextNotActiveException - if no jsf context is available to retrieve the bean from
    • getSessionBean

      public static SessionBean getSessionBean()
      getSessionBean.
      Returns:
      the SessionBean managed bean, or a new instance if the CDI bean is unavailable
    • getImageDeliveryBean

      public static ImageDeliveryBean getImageDeliveryBean()
      getImageDeliveryBean.
      Returns:
      the ImageDeliveryBean managed bean, or a newly initialized one if unavailable
    • getBrowseBean

      public static BrowseBean getBrowseBean()
      getBrowseBean.
      Returns:
      the BrowseBean managed bean
    • getContentBean

      public static ContentBean getContentBean()
      getUserBean.
      Returns:
      the ContentBean managed bean
    • getUserBeanFromSession

      public static UserBean getUserBeanFromSession(HttpSession session)
      getUserBeanFromSession.
      Parameters:
      session - HTTP session to retrieve the UserBean from
      Returns:
      the UserBean stored in the given session, or null if not found
    • getBeanFromSession

      public static <T> Optional<T> getBeanFromSession(HttpSession session, String beanName, Class<T> clazz)
      getBeanFromSession.
      Type Parameters:
      T - a T class
      Parameters:
      session - HTTP session to retrieve the bean from
      beanName - session attribute name of the bean
      clazz - expected type of the bean
      Returns:
      an Optional containing the typed bean from the session, or empty if not found
    • getUserFromSession

      public static User getUserFromSession(HttpSession session)
      getUserFromSession. This performs a scan of the whole session and may be expensive. Prefer using getUserBean() and #UserBean.getUser()
      Parameters:
      session - HTTP session containing the UserBean
      Returns:
      the User stored in the UserBean of the given session, or null if not found
    • escapeCriticalUrlChracters

      public static String escapeCriticalUrlChracters(String value)
      escapeCriticalUrlChracters.
      Parameters:
      value - URL string to escape
      Returns:
      the input string with critical URL characters escaped
    • findInstanceInSessionAttributes

      public static <T> Optional<T> findInstanceInSessionAttributes(HttpSession session, Class<T> clazz)
      findInstanceInSessionAttributes.
      Type Parameters:
      T - a T class
      Parameters:
      session - HTTP session whose attributes are scanned
      clazz - type to search for among session attributes
      Returns:
      an Optional containing the first session attribute of the given type, or empty if none found
    • getResponse

      public static HttpServletResponse getResponse()
      getResponse.
      Returns:
      the current HTTP servlet response, or null if no FacesContext is available
    • getManagedBeanValue

      public static Object getManagedBeanValue(String expr)
      getManagedBeanValue.
      Parameters:
      expr - EL expression string to evaluate
      Returns:
      the value resolved by the EL expression, or null if the context or expression is unavailable
    • wipeSessionAttributes

      public static void wipeSessionAttributes(HttpSession session)
      Removes the user and permission attributes from the session.
      Parameters:
      session - HttpSession