Class BeanUtils
java.lang.Object
io.goobi.viewer.managedbeans.utils.BeanUtils
Utility class for methods that use the FacesContext.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringescapeCriticalUrlChracters(String value) escapeCriticalUrlChracters.static <T> Optional<T> findInstanceInSessionAttributes(HttpSession session, Class<T> clazz) findInstanceInSessionAttributes.static ActiveDocumentBeangetActiveDocumentBean.static AdminBeangetAdminBean.static ObjectgetBeanByName(String name, Class clazz) getBeanByName.static <T> Optional<T> getBeanFromSession(HttpSession session, String beanName, Class<T> clazz) getBeanFromSession.static BookmarkBeangetBookmarkBean.static BrowseBeangetBrowseBean.static CalendarBeangetCalendarBean.static CaptchaBeangetCaptchaBean.static CmsBeangetCmsBean.static CmsCollectionsBeangetCMSCollectionsBean.static CmsMediaBeangetCmsMediaBean.static CollectionViewBeangetCollectionViewBean.static ContentBeangetUserBean.static CreateRecordBeangetCreateRecordBean.static LocalegetDefaultLocale.static ImageDeliveryBeangetImageDeliveryBean.static LocalegetInitialLocale.static LocalegetLocale.static ObjectgetManagedBeanValue(String expr) getManagedBeanValue.static MetadataBeangetMetadataBean.static NavigationHelpergetNavigationHelper.static ApplicationBeangetPersistentStorageBean.static HttpServletRequestGets the current Request from the faces context.static HttpServletRequestgetRequest(FacesContext context) getRequest.static HttpServletResponsegetResponse.static SearchBeangetSearchBean.static ServletContextgetServletContext.static StringgetServletImagesPathFromRequest(HttpServletRequest request, String theme) getServletImagesPathFromRequest.static Stringretrieve complete Servlet url from servlet context, including Url, Port, Servletname etc. call this method only from jsf contextstatic HttpSessiongetSession.static SessionBeangetSessionBean.static UserBeangetUserBean.static UserBeangetUserBeanFromSession(HttpSession session) getUserBeanFromSession.static UsergetUserFromSession(HttpSession session) getUserFromSession.static booleanhasJsfContext.static voidwipeSessionAttributes(HttpSession session) Removes the user and permission attributes from the session.
-
Method Details
-
getRequest
Gets the current Request from the faces context.- Returns:
- the current HTTP servlet request, or null if unavailable
-
getRequest
getRequest.- Parameters:
context- faces context to extract the request from- Returns:
- the HTTP servlet request from the given FacesContext, or null if unavailable
-
getSession
getSession.- Returns:
- HttpSession from current request
-
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
getServletImagesPathFromRequest.- Parameters:
request- incoming HTTP request for base URL resolutiontheme- theme folder name appended to the path- Returns:
- the absolute URL path to the servlet images directory for the given theme
-
getServletContext
getServletContext.- Returns:
- the current ServletContext, or null if no FacesContext is available
-
getInitialLocale
getInitialLocale.- Returns:
- Currently selected or default
Locale
-
getLocale
getLocale.- Returns:
- Current Locale in
NavigationHelper; default locale if none found
-
getDefaultLocale
getDefaultLocale.- Returns:
- the default application locale
-
getBeanByName
getBeanByName.- Parameters:
name- CDI bean name to look upclazz- 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
-
getAdminBean
getAdminBean.- Returns:
- the AdminBean managed bean
-
getCollectionViewBean
getCollectionViewBean.- Returns:
- the CollectionViewBean managed bean
-
getActiveDocumentBean
getActiveDocumentBean.- Returns:
- the ActiveDocumentBean managed bean
-
getPersistentStorageBean
getPersistentStorageBean.Returns the
@ApplicationScopedApplicationBean. 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
getSearchBean.- Returns:
- the SearchBean managed bean
-
getBookmarkBean
getBookmarkBean.- Returns:
- the BookmarkBean managed bean
-
getCreateRecordBean
getCreateRecordBean.- Returns:
- the CreateRecordBean managed bean
-
getCMSCollectionsBean
getCMSCollectionsBean.- Returns:
- the CmsCollectionsBean managed bean
-
getMetadataBean
getMetadataBean.- Returns:
- the MetadataBean managed bean
-
getCmsBean
getCmsBean.- Returns:
- the CmsBean managed bean
-
getCmsMediaBean
getCmsMediaBean.- Returns:
- the CmsMediaBean managed bean
-
getCalendarBean
getCalendarBean.- Returns:
- the CalendarBean managed bean
-
getCaptchaBean
getCaptchaBean.- Returns:
- the CaptchaBean managed bean
-
getUserBean
getUserBean.- Returns:
- the UserBean managed bean
- Throws:
ContextNotActiveException- if no jsf context is available to retrieve the bean from
-
getSessionBean
getSessionBean.- Returns:
- the SessionBean managed bean, or a new instance if the CDI bean is unavailable
-
getImageDeliveryBean
getImageDeliveryBean.- Returns:
- the ImageDeliveryBean managed bean, or a newly initialized one if unavailable
-
getBrowseBean
getBrowseBean.- Returns:
- the BrowseBean managed bean
-
getContentBean
getUserBean.- Returns:
- the ContentBean managed bean
-
getUserBeanFromSession
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 frombeanName- session attribute name of the beanclazz- expected type of the bean- Returns:
- an Optional containing the typed bean from the session, or empty if not found
-
getUserFromSession
getUserFromSession. This performs a scan of the whole session and may be expensive. Prefer usinggetUserBean()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
escapeCriticalUrlChracters.- Parameters:
value- URL string to escape- Returns:
- the input string with critical URL characters escaped
-
findInstanceInSessionAttributes
findInstanceInSessionAttributes.- Type Parameters:
T- a T class- Parameters:
session- HTTP session whose attributes are scannedclazz- 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
getResponse.- Returns:
- the current HTTP servlet response, or null if no FacesContext is available
-
getManagedBeanValue
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
Removes the user and permission attributes from the session.- Parameters:
session-HttpSession
-