Class CmsMediaBean

java.lang.Object
io.goobi.viewer.managedbeans.CmsMediaBean
All Implemented Interfaces:
Serializable

@Named @SessionScoped public class CmsMediaBean extends Object implements Serializable
JSF backing bean for CMS media file management including upload, editing, and deletion.
See Also:
  • Field Details

  • Constructor Details

    • CmsMediaBean

      public CmsMediaBean()
      Creates a new CmsMediaBean instance.
  • Method Details

    • resetData

      public void resetData()
      Reload all media items, along with the available categories.
    • createMediaItem

      public CMSMediaItem createMediaItem()
      createMediaItem.
      Returns:
      a new CMSMediaItem initialized with metadata entries for all configured locales
    • deleteMedia

      public void deleteMedia(CMSMediaItem item) throws DAOException
      deleteMedia.
      Parameters:
      item - media item to delete from the database and filesystem
      Throws:
      DAOException - if any.
    • getAllMedia

      public List<CMSMediaItem> getAllMedia() throws DAOException
      getAllMedia.
      Returns:
      a list of all CMS media items accessible to the current user
      Throws:
      DAOException - if any.
    • getDataProvider

      Getter for the field dataProvider.
      Returns:
      the TableDataProvider for the CMS media item list
    • getMediaItems

      getMediaItems.
      Returns:
      a list of categorizable translated selectable CMS media items for the current page in the paginated media list
      Throws:
      DAOException - if any.
    • reloadMediaList

      public void reloadMediaList()
      reloadMediaList.
    • reloadMediaList

      public void reloadMediaList(boolean resetCurrentPage)
      reloadMediaList.
      Parameters:
      resetCurrentPage - if true, navigate back to the first page after reload
    • deleteSelectedItems

      public void deleteSelectedItems() throws DAOException
      Deletes all mediaItems from getMediaItems() which are are marked as selected. Reloads the media list
      Throws:
      DAOException - if any.
    • saveSelectedItems

      public void saveSelectedItems() throws DAOException
      Saves all mediaItems from getMediaItems() which are are marked as selected. Reloads the media list
      Throws:
      DAOException - if any.
    • getMediaUrl

      public static String getMediaUrl(CMSMediaItem item) throws NumberFormatException
      getMediaUrl.
      Parameters:
      item - media item for which to build the URL
      Returns:
      the URL to the given CMS media item at its natural size
      Throws:
      NumberFormatException - if any.
      ViewerConfigurationException - if any.
    • getMediaUrl

      public static String getMediaUrl(CMSMediaItem item, String width, String height)
      getMediaUrl.
      Parameters:
      item - media item for which to build the URL
      width - requested image width in pixels, or null/blank for auto
      height - requested image height in pixels, or null/blank for auto
      Returns:
      the URL to the given CMS media item scaled to the specified dimensions
      Throws:
      ViewerConfigurationException - if any.
    • getMediaFileAsString

      public static String getMediaFileAsString(CMSMediaItem item)
      getMediaFileAsString.
      Parameters:
      item - media item whose file content is retrieved via REST
      Returns:
      the text content of the given CMS media item fetched via REST API, or empty string on failure
      Throws:
      ViewerConfigurationException - if any.
    • getMediaPreviewUrl

      public static String getMediaPreviewUrl(CMSMediaItem item) throws NumberFormatException
      getMediaPreviewUrl.
      Parameters:
      item - media item for which to build a preview thumbnail URL
      Returns:
      the URL to a 160px-high preview thumbnail of the given CMS media item
      Throws:
      NumberFormatException - if any.
      ViewerConfigurationException - if any.
    • isImage

      public boolean isImage(CMSMediaItem item)
      isImage.
      Parameters:
      item - media item whose filename is tested
      Returns:
      true if the given media item's filename matches the image file filter pattern, false otherwise
    • isVideo

      public boolean isVideo(CMSMediaItem item)
      isVideo.
      Parameters:
      item - media item whose filename is tested
      Returns:
      true if the given media item's filename matches the video file filter pattern, false otherwise
    • isAudio

      public boolean isAudio(CMSMediaItem item)
      isAudio.
      Parameters:
      item - media item whose filename is tested
      Returns:
      true if the given media item's filename matches the audio file filter pattern, false otherwise
    • isText

      public boolean isText(CMSMediaItem item)
      isText.
      Parameters:
      item - media item whose filename is tested
      Returns:
      true if the given media item's filename matches the document/text file filter pattern, false otherwise
    • saveSelectedMediaItem

      public void saveSelectedMediaItem() throws DAOException
      saveSelectedMediaItem.
      Throws:
      DAOException - if any.
    • saveMedia

      public void saveMedia(CMSMediaItem media, List<Selectable<CMSCategory>> categories) throws DAOException
      Save media item, adding or removing the given categories, depending whether they are selected or not. if User.hasPrivilegeForAllSubthemeDiscriminatorValues() is false for the current user and none of the given categories is selected, then don't change the media categories since doing so would break category restrictions
      Parameters:
      media - media item to persist to the database
      categories - selectable categories to apply or remove from the media item
      Throws:
      DAOException - if any.
    • saveMedia

      public void saveMedia(CMSMediaItem media) throws DAOException
      saveMedia.
      Parameters:
      media - media item to add or update in the database
      Throws:
      DAOException - if any.
    • getFileName

      public static String getFileName(Part filePart)
      getFileName.
      Parameters:
      filePart - multipart upload part from which the filename is extracted
      Returns:
      the filename extracted from the content-disposition header of the upload part, or null if not found
    • setSelectedTag

      public void setSelectedTag(String selectedTag)
      Setter for the field selectedTag.
      Parameters:
      selectedTag - the tag name to filter the media list by
    • getSelectedTag

      public String getSelectedTag()
      Getter for the field selectedTag.
      Returns:
      the tag currently selected to filter the media list
    • getAllMediaCategories

      public List<CMSCategory> getAllMediaCategories() throws DAOException
      getAllMediaCategories.
      Returns:
      a list of all CMS categories available for media items
      Throws:
      DAOException - if any.
    • getImageFilter

      public static String getImageFilter()
      getImageFilter.
      Returns:
      a regex matching only filenames ending with one of the supported image format suffixes
    • getVideoFilter

      public static String getVideoFilter()
    • getAudioFilter

      public static String getAudioFilter()
    • getDocumentFilter

      public static String getDocumentFilter()
    • getMediaFilter

      public static String getMediaFilter()
    • getImageTypes

      public static String getImageTypes()
    • getVideoTypes

      public static String getVideoTypes()
    • getAudioTypes

      public static String getAudioTypes()
    • getDocumentTypes

      public static String getDocumentTypes()
    • getAllTypes

      public static String getAllTypes()
    • getFilter

      public String getFilter()
      Getter for the field filter.
      Returns:
      the media type filter string currently applied to the media list
    • setFilter

      public void setFilter(String filter)
      Setter for the field filter.
      Parameters:
      filter - the media type filter string; triggers a reload of the media list if changed
    • getFilenameFilter

      public String getFilenameFilter()
      Getter for the field filenameFilter.
      Returns:
      the filename filter string currently applied to restrict the media list
    • setFilenameFilter

      public void setFilenameFilter(String filter)
      Setter for the field filenameFilter.
      Parameters:
      filter - the filename filter string; triggers a reload of the media list if changed
    • setSelectedMediaItem

      public void setSelectedMediaItem(CategorizableTranslatedSelectable<CMSMediaItem> selectedMediaItem)
      Setter for the field selectedMediaItem.
      Parameters:
      selectedMediaItem - the media item to mark as selected, or null to clear the selection
    • toggleSelectedMediaItem

      public void toggleSelectedMediaItem(CategorizableTranslatedSelectable<CMSMediaItem> selectedMediaItem)
      toggleSelectedMediaItem.
      Parameters:
      selectedMediaItem - media item to select, or deselect if already selected
    • getSelectedMediaItem

      public TranslatedSelectable<CMSMediaItem> getSelectedMediaItem()
      Getter for the field selectedMediaItem.
      Returns:
      the currently selected media item, or null if none is selected
    • setAllSelected

      public void setAllSelected(boolean allSelected)
      Setter for the field allSelected.
      Parameters:
      allSelected - true to mark all media items as selected, false to deselect all
    • isAllSelected

      public boolean isAllSelected()
      isAllSelected.
      Returns:
      true if all media items are currently marked as selected, false otherwise
    • needsPaginator

      public boolean needsPaginator()
      needsPaginator.
      Returns:
      true if there is more than one page in the data-provider. False otherwise