Package net.shibboleth.metadata.dom
Class Container
java.lang.Object
net.shibboleth.metadata.dom.Container
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceWhen a container needs to add a new childElement, use a functor with this interface to create the appropriate context for the new child and to add it in place. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringDefault indentation of four spaces.private final ElementThe wrappedElement.static final Container.ChildAddingStrategyChild adding strategy which adds the new child as the first child of the container.private final StringThe indentation applied to child containers.private final StringThe indentation applied to the opening and closing tags.private final StringThe difference between outer and inner indentation.static final Container.ChildAddingStrategyChild adding strategy which adds the new child as the last child of the container.private final ContainerThe parentContainer, ornull. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddChild(ElementMaker maker, Container.ChildAddingStrategy adder) Add a child to the container.addChild(Element child, Container.ChildAddingStrategy adder) Add a child to the container.findChild(ElementMatcher matcher) Find an existing child matching theElementMatcher, if there is one.findChildren(ElementMatcher matcher) Find all existing children matching theElementMatcher.Get the container's parent, if any.locateChild(ElementMatcher matcher, ElementMaker maker, Container.ChildAddingStrategy adder) Locate a child container matching theElementMatcher, creating one if necessary.voidprime()Make sure that the container is able to receive additional child containers.voidSet the text content of the wrappedElement.unwrap()Return the wrappedElement.
-
Field Details
-
FIRST_CHILD
Child adding strategy which adds the new child as the first child of the container. -
LAST_CHILD
Child adding strategy which adds the new child as the last child of the container. -
DEFAULT_INDENT
Default indentation of four spaces.- See Also:
-
element
The wrappedElement. -
parentContainer
The parentContainer, ornull. -
indentOuter
The indentation applied to the opening and closing tags. -
indentInner
The indentation applied to child containers. -
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. -
Container
Constructor. This variant is used internally to constructContainers corresponding to child elements. -
Container
Constructor. This variant is used to start aContainertree from an existing rootElement. It is the only public constructor.- Parameters:
root- the existingElementto wrap.
-
-
Method Details
-
getParent
Get the container's parent, if any.- Returns:
- the container's parent container, or
null
-
unwrap
Return the wrappedElement.- Returns:
- the wrapped
Element
-
setText
Set the text content of the wrappedElement.- 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
Find an existing child matching theElementMatcher, if there is one.- Parameters:
matcher-ElementMatcherto match against existing children- Returns:
- a child
ContainerwhoseElementmatches the suppliedElementMatcher.
-
findChildren
Find all existing children matching theElementMatcher.- Parameters:
matcher-ElementMatcherto match against existing children- Returns:
- a
Listof 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 addadder- 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-ElementMakerto create the new child elementadder- 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 theElementMatcher, creating one if necessary.- Parameters:
matcher-ElementMatcherto match against existing childrenmaker- aElementMakerto create a new childElementadder- aContainer.ChildAddingStrategydetermining where to place the new child- Returns:
- a child
Container, possibly just created
-