java.lang.Object
com.semanticcms.core.model.Node
All Implemented Interfaces:
Freezable<Node>
Direct Known Subclasses:
Element, Page

public abstract class Node extends Object implements Freezable<Node>
A node contains elements, but is not necessarily an element itself. A node can also have references to pages. A node can have a captured body.
  • Field Details

    • lock

      protected final Object lock
    • frozen

      protected volatile boolean frozen
  • Constructor Details

    • Node

      public Node()
  • Method Details

    • toString

      public String toString()
      The toString calls getLabel().
      Overrides:
      toString in class Object
    • freeze

      public Node freeze()
      Specified by:
      freeze in interface Freezable<Node>
    • checkNotFrozen

      protected void checkNotFrozen() throws FrozenException
      Throws:
      FrozenException
    • getProperty

      public Map<String,Object> getProperty()
      Gets an unmodifiable snapshot of all properties associated with a node. The returned map will not change, even if properties are added to the node.
    • setProperty

      public boolean setProperty(String name, Object value) throws FrozenException
      Sets a property on this node, if the property has not already been set. Setting a property to null still marks the property as used and associates it with null.
      Returns:
      true when the property was added or false when the property already existed (including possibly with a null value).
      Throws:
      FrozenException - properties may not be set once the node is frozen
    • getChildElements

      public List<Element> getChildElements()
      Every node may potentially have child elements.
    • addChildElement

      public Long addChildElement(Element childElement, ElementWriter elementWriter)
      Adds a child element to this node.
    • getPageLinks

      public Set<PageRef> getPageLinks()
      Gets the set of all pages this node directly links to; this does not include pages linked to by child elements.
    • addPageLink

      public void addPageLink(PageRef pageLink)
    • getBody

      public BufferResult getBody()
      Every node may potentially have HTML body.
    • setBody

      public void setBody(BufferResult body)
    • getLabel

      public abstract String getLabel()
      Gets a short description, useful for links and lists, for this node.
    • appendLabel

      @Deprecated(forRemoval=true) public final void appendLabel(Appendable out) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use getLabel()
      Appends a short description, useful for links and lists, for this node.
      Throws:
      IOException
    • findTopLevelElements

      public <E> List<E> findTopLevelElements(Class<E> elementType)

      Looks for the nearest nested elements of the given class. These elements may be direct descendants or descendants further down the tree, but only the top-most descendants are returned.

      If the node is a page, its elements are checked, but the elements of its child pages are not.

      Returns:
      The unmodifiable list of top-level matches, in the order they were declared in the page, or empty list if none found.
    • findChildElement

      public <E> Optional<E> findChildElement(Class<E> elementType, Predicate<? super E> filter)

      Finds the first descendant element of the given class or interface and matching the given Predicate, with a depth-first traversal.

      If the node is a page, its elements are checked, but the elements of its child pages are not.

      Returns:
      The element or Optional.empty() when not found.
    • findChildElement

      public <E> Optional<E> findChildElement(Class<E> elementType)

      Finds the first descendant element of the given class or interface, with a depth-first traversal.

      If the node is a page, its elements are checked, but the elements of its child pages are not.

      Returns:
      The element or Optional.empty() when not found.
    • requireChildElement

      public <E> E requireChildElement(Class<E> elementType, Predicate<? super E> filter) throws NoSuchElementException

      Finds the first descendant element of the given class or interface and matching the given Predicate, with a depth-first traversal.

      If the node is a page, its elements are checked, but the elements of its child pages are not.

      Returns:
      The element.
      Throws:
      NoSuchElementException - when not found.
    • requireChildElement

      public <E> E requireChildElement(Class<E> elementType) throws NoSuchElementException

      Finds the first descendant element of the given class or interface, with a depth-first traversal.

      If the node is a page, its elements are checked, but the elements of its child pages are not.

      Returns:
      The element.
      Throws:
      NoSuchElementException - when not found.