Class CMSComponent

java.lang.Object
io.goobi.viewer.model.cms.pages.content.CMSComponent
All Implemented Interfaces:
Serializable, Comparable<CMSComponent>

public class CMSComponent extends Object implements Comparable<CMSComponent>, Serializable
Represents a reusable UI component on a CMS page, combining a JSF component reference with ordered content items, display metadata, and optional access restrictions.
See Also:
  • Constructor Details

    • CMSComponent

      public CMSComponent(CMSComponent template, List<CMSContentItem> items)
      Parameters:
      template - the component to copy structure from
      items - content items to populate the new component with
    • CMSComponent

      public CMSComponent(CMSComponent template, Optional<PersistentCMSComponent> jpa)
      Parameters:
      template - the component to copy structure and configuration from
      jpa - optional persistentComponent to load persisted data from
    • CMSComponent

      public CMSComponent(JsfComponent jsfComponent, String label, String description, List<String> types, String templateFilename, CMSComponentScope scope, Map<String,CMSComponentAttribute> attributes, List<CMSComponent.Property> properties, Integer order)
      Constructor to create Component from template file.
      Parameters:
      jsfComponent - the JSF component used to render this CMS component
      label - human-readable display label of the component
      description - short description of the component's purpose
      types - list of category type strings for the component selection menu
      templateFilename - filename of the component template
      scope - visibility scope of the component
      attributes - map of configurable component attributes
      properties - list of additional behaviour properties
      order - display order position of the component
  • Method Details

    • getPersistentComponent

      public PersistentCMSComponent getPersistentComponent()
    • setPublicationState

      public void setPublicationState(ContentItemPublicationState publicationState)
      Parameters:
      publicationState - the publication state to set on the persistentComponent
    • getPublicationState

      public ContentItemPublicationState getPublicationState()
    • setOrder

      public void setOrder(int order)
      Parameters:
      order - display order position of this component on the page
    • getOrder

      public Integer getOrder()
    • addContentItem

      public boolean addContentItem(CMSContentItem item)
      Parameters:
      item - the content item to add to this component
      Returns:
      true if item added successfully; false otherwise
    • removeContentItem

      public boolean removeContentItem(CMSContentItem item)
      Parameters:
      item - the content item to remove from this component
      Returns:
      true if item removed successfully; false otherwise
    • getContentItems

      public List<CMSContentItem> getContentItems()
    • getFirstContentItem

      public CMSContentItem getFirstContentItem()
    • getFirstContentOfType

      public <T extends CMSContent> T getFirstContentOfType(Class<? extends CMSContent> clazz)
    • getAllContentOfType

      public <T extends CMSContent> List<T> getAllContentOfType(Class<? extends CMSContent> clazz)
    • getFirstContentItem

      public CMSContentItem getFirstContentItem(String className)
    • getContentItem

      public CMSContentItem getContentItem(String componentId)
    • getTranslatableContentItems

      public List<CMSContentItem> getTranslatableContentItems()
    • getJsfComponent

      public JsfComponent getJsfComponent()
    • getLabel

      public String getLabel()
    • getDescription

      public String getDescription()
    • getTemplateFilename

      public String getTemplateFilename()
    • isPageScope

      public boolean isPageScope()
    • compareTo

      public int compareTo(CMSComponent o)
      Specified by:
      compareTo in interface Comparable<CMSComponent>
    • getUiComponent

      public UIComponent getUiComponent() throws PresentationException
      Returns this component's frontend JSF component tree, building it on first access.

      The subtree is built into a local panel group and only published to uiComponent once it is complete, so that every caller sees exactly one fully built instance. Concurrent requests of the same HTTP session share this object (the session-scoped CmsBean holds the current CMSPage, and Tomcat's CrawlerSessionManagerValve funnels all crawler requests into a single session). The previous implementation assigned the field before building and then re-read it as the build target: if another thread overwrote the field in between, both threads appended their composite child to the same panel group, which produced two children with an identical id and an IllegalStateException in JSF's checkIdUniqueness while saving the view. Publication happens inside a short lock that performs no I/O, so the first complete build wins and a losing thread discards its own subtree.

      Returns:
      the frontend UI component, or null if this component has no usable JSF component
      Throws:
      PresentationException - if the JSF component cannot be built
    • setUiComponent

      public void setUiComponent(UIComponent uiComponent)
      Parameters:
      uiComponent - the frontend JSF UI component to set
    • getBackendUiComponent

      public UIComponent getBackendUiComponent() throws PresentationException
      Throws:
      PresentationException
    • setBackendUiComponent

      public void setBackendUiComponent(UIComponent backendUiComponent)
      Parameters:
      backendUiComponent - the backend JSF UI component to set
    • getAttribute

      public CMSComponentAttribute getAttribute(String key)
      Parameters:
      key - attribute name to look up
      Returns:
      CMSComponentAttribute
    • getBooleanAttributeValue

      public boolean getBooleanAttributeValue(String key, boolean defaultValue)
      Parameters:
      key - attribute name to look up
      defaultValue - value returned when attribute is absent
      Returns:
      the boolean attribute value for the given key, or defaultValue if no such attribute is set
    • getAttributeValue

      public String getAttributeValue(String key)
      Parameters:
      key - attribute name to look up
      Returns:
      String
    • setAttribute

      public void setAttribute(String key, String value)
      Parameters:
      key - name of the attribute to set
      value - new string value to assign to the attribute
    • toggleAttribute

      public void toggleAttribute(String key, String value)
      Parameters:
      key - name of the attribute to toggle
      value - value to set, or clear if already set
    • getAttributes

      public Map<String,CMSComponentAttribute> getAttributes()
    • isPublished

      public boolean isPublished()
    • setPublished

      public void setPublished(boolean published)
      Parameters:
      published - true to publish the component; false to restrict to admins
    • isPrivate

      public boolean isPrivate()
    • setPrivate

      public void setPrivate(boolean privat)
      Parameters:
      privat - true to restrict component visibility to admins
    • togglePrivate

      public void togglePrivate()
    • togglePublished

      public void togglePublished()
    • hasAccess

      public boolean hasAccess(User user)
      Parameters:
      user - the user whose access rights to check; may be null
      Returns:
      true if the component is published, or if the given user is a CMS admin, false otherwise
    • getContentData

      public String getContentData(String itemId)
      Parameters:
      itemId - ID of the content item to retrieve data for
      Returns:
      String
    • getContentData

      public String getContentData(String itemId, Integer width, Integer height)
      Parameters:
      itemId - ID of the content item to retrieve data for
      width - optional width constraint passed to the content's getData method
      height - optional height constraint passed to the content's getData method
      Returns:
      String
    • hasContent

      public boolean hasContent(String itemId)
      Checks whether a contentItem with the given itemId exists and is not empty.
      Parameters:
      itemId - ID of the content item to check
      Returns:
      true if the contentItem with the given itemId exists and its CMSContent.isEmpty() method returns false
    • getContent

      public CMSContent getContent(String itemId)
    • setPreview

      public void setPreview(boolean preview)
      Sets whether this component should be displayed when the owning page is embedded in another page, rather than on the owning page itself.
      Parameters:
      preview - true to set scope to preview; false for normal page view
    • isPreview

      public boolean isPreview()
      Returns whether this component should be displayed when the owning page is embedded in another page, rather than on the owning page itself.
      Returns:
      true if scope is CMSComponentScope.PREVIEW; false otherwise
    • getScope

      public CMSComponentScope getScope()
    • setScope

      public void setScope(CMSComponentScope scope)
    • getPersistenceId

      public long getPersistenceId()
    • getOwningPage

      public CMSPage getOwningPage()
    • isPaged

      public boolean isPaged()
    • getTypes

      public List<String> getTypes()
    • getProperties

      public List<CMSComponent.Property> getProperties()
    • hasProperty

      public boolean hasProperty(CMSComponent.Property property)
    • toString

      public String toString()
      Overrides:
      toString in class Object