Class Container

java.lang.Object
net.shibboleth.metadata.dom.Container

public class Container extends Object
A wrapper for a DOM Element allowing its use as a container for either a simple text value or for other Elements. In the latter case, white-space formatting is handled automatically for nested containers.
Since:
0.10.0
  • Field Details

    • FIRST_CHILD

      @Nonnull public static final Container.ChildAddingStrategy FIRST_CHILD
      Child adding strategy which adds the new child as the first child of the container.
    • LAST_CHILD

      @Nonnull public static final Container.ChildAddingStrategy LAST_CHILD
      Child adding strategy which adds the new child as the last child of the container.
    • DEFAULT_INDENT

      @Nonnull private static final String DEFAULT_INDENT
      Default indentation of four spaces.
      See Also:
    • element

      @Nonnull private final Element element
      The wrapped Element.
    • parentContainer

      @Nullable private final Container parentContainer
      The parent Container, or null.
    • indentOuter

      @Nonnull private final String indentOuter
      The indentation applied to the opening and closing tags.
    • indentInner

      @Nonnull private final String indentInner
      The indentation applied to child containers.
    • indentStep

      @Nonnull private final String indentStep
      The difference between outer and inner indentation.
  • Constructor Details

    • Container

      private Container(@Nonnull Element elem, @Nullable Container parent, @Nonnull String outer, @Nonnull String inner, @Nonnull String step)
      Constructor.
      Parameters:
      elem - Element on which to base the Container
      parent - Container to link as the parent, or null
      outer - indentation to be used for this container's start and end tags
      inner - indentation to be used for child containers
      step - difference between inner and outer indentation
    • Container

      private Container(@Nonnull Element child, @Nonnull Container parent)
      Constructor. This variant is used internally to construct Containers corresponding to child elements.
      Parameters:
      child - child Element for which to construct a Container
      parent - parentContainer Container to link this child to
    • Container

      public Container(@Nonnull Element root)
      Constructor. This variant is used to start a Container tree from an existing root Element. It is the only public constructor.
      Parameters:
      root - the existing Element to wrap.
  • Method Details

    • getParent

      @Nullable public Container getParent()
      Get the container's parent, if any.
      Returns:
      the container's parent container, or null
    • unwrap

      @Nonnull public Element unwrap()
      Return the wrapped Element.
      Returns:
      the wrapped Element
    • setText

      public void setText(@Nonnull String text)
      Set the text content of the wrapped Element.
      Parameters:
      text - the text content to set within the element
    • prime

      public void prime()
      Make sure that the container is able to receive additional child containers. If the container is empty, add in text content so that its opening and closing tags are on different lines but are indented in the same way. The resulting container will have at least one child node, almost always a text node starting with "\n".
    • findChild

      @Nullable public Container findChild(@Nonnull ElementMatcher matcher)
      Find an existing child matching the ElementMatcher, if there is one.
      Parameters:
      matcher - ElementMatcher to match against existing children
      Returns:
      a child Container whose Element matches the supplied ElementMatcher.
    • findChildren

      @Nonnull @NonnullElements public List<Container> findChildren(@Nonnull ElementMatcher matcher)
      Find all existing children matching the ElementMatcher.
      Parameters:
      matcher - ElementMatcher to match against existing children
      Returns:
      a List of all matching children
    • addChild

      @Nonnull public Container addChild(@Nonnull Element child, @Nonnull Container.ChildAddingStrategy adder)
      Add a child to the container.
      Parameters:
      child - the new child element to add
      adder - strategy class to place the new child inside the container
      Returns:
      a container wrapping the new child element
    • addChild

      @Nonnull public Container addChild(@Nonnull ElementMaker maker, @Nonnull Container.ChildAddingStrategy adder)
      Add a child to the container.
      Parameters:
      maker - ElementMaker to create the new child element
      adder - strategy class to place the new child inside the container
      Returns:
      a container wrapping the new child element
    • locateChild

      @Nonnull public Container locateChild(@Nonnull ElementMatcher matcher, @Nonnull ElementMaker maker, @Nonnull Container.ChildAddingStrategy adder)
      Locate a child container matching the ElementMatcher, creating one if necessary.
      Parameters:
      matcher - ElementMatcher to match against existing children
      maker - a ElementMaker to create a new child Element
      adder - a Container.ChildAddingStrategy determining where to place the new child
      Returns:
      a child Container, possibly just created