Class MarkupStream


  • public class MarkupStream
    extends Object
    A stream of MarkupElements, subclasses of which are ComponentTag and RawMarkup. A markup stream has a current index in the list of markup elements. The next markup element can be retrieved and the index advanced by calling next(). If the index hits the end, hasMore() will return false.

    The current markup element can be accessed with get() and as a ComponentTag with getTag().

    The stream can be sought to a particular location with setCurrentIndex().

    Convenience methods also exist to skip component tags (and any potentially nested markup) or raw markup.

    Several boolean methods of the form at*() return true if the markup stream is positioned at a tag with a given set of characteristics.

    The resource from which the markup was loaded can be retrieved with getResource().

    Author:
    Jonathan Locke
    • Method Detail

      • atCloseTag

        public boolean atCloseTag()
        Returns:
        True if current markup element is a close tag
      • atOpenCloseTag

        public boolean atOpenCloseTag()
        Returns:
        True if current markup element is an openclose tag
      • atOpenCloseTag

        public boolean atOpenCloseTag​(String componentId)
        Parameters:
        componentId - Required component name attribute
        Returns:
        True if the current markup element is an openclose tag with the given component name
      • atOpenTag

        public boolean atOpenTag()
        Returns:
        True if current markup element is an open tag
      • atOpenTag

        public boolean atOpenTag​(String id)
        Parameters:
        id - Required component id attribute
        Returns:
        True if the current markup element is an open tag with the given component name
      • atTag

        public boolean atTag()
        Returns:
        True if current markup element is a tag
      • equalTo

        public boolean equalTo​(MarkupStream that)
        Compare this markup stream with another one
        Parameters:
        that - The other markup stream
        Returns:
        True if each MarkupElement in this matches each element in that
      • equalMarkup

        public final boolean equalMarkup​(MarkupStream markupStream)
        True, if associate markup is the same. It will change e.g. if the markup file has been re-loaded or the locale has been changed.
        Parameters:
        markupStream - The markup stream to compare with.
        Returns:
        true, if markup has not changed
      • get

        public MarkupElement get​(int index)
        Parameters:
        index - The index of a markup element
        Returns:
        The MarkupElement element
      • getContainerClass

        public final Class<? extends ComponentgetContainerClass()
        Get the component/container's Class which is directly associated with the stream.
        Returns:
        The component's class
      • getCurrentIndex

        public int getCurrentIndex()
        Returns:
        Current index in markup stream
      • getEncoding

        public final String getEncoding()
        Gets the markup encoding. A markup encoding may be specified in a markup file with an XML encoding specifier of the form <?xml ... encoding="..." ?>.
        Returns:
        The encoding, or null if not found
      • getTag

        public ComponentTag getTag()
        Returns:
        The current markup element as a markup tag
      • getWicketNamespace

        public final String getWicketNamespace()
        Get the wicket namespace valid for this specific markup
        Returns:
        wicket namespace
      • isCurrentIndexInsideTheStream

        public boolean isCurrentIndexInsideTheStream()
        Returns:
        True if this markup stream is moved to a MarkupElement element
      • hasMore

        public boolean hasMore()
        Returns:
        True if this markup stream has more MarkupElement elements
      • isMergedMarkup

        public final boolean isMergedMarkup()
        Returns:
        true, if underlying markup has been merged (inheritance)
      • next

        public MarkupElement next()
        Note:
        Returns:
        The next markup element in the stream
      • setCurrentIndex

        public MarkupStream setCurrentIndex​(int currentIndex)
        Parameters:
        currentIndex - New current index in the stream
        Returns:
        this
      • skipComponent

        public final void skipComponent()
        Skips this component and all nested components
      • skipRawMarkup

        public void skipRawMarkup()
        Skips any raw markup at the current position
      • skipUntil

        public boolean skipUntil​(Class<? extends MarkupElement> clazz)
        Skip until an element of type 'clazz' is found
        Parameters:
        clazz -
        Returns:
        true if found
      • skipUntil

        public void skipUntil​(String wicketTagName)
        Skips any markup at the current position until the wicket tag name is found.
        Parameters:
        wicketTagName - wicket tag name to seek
      • skipToMatchingCloseTag

        public void skipToMatchingCloseTag​(ComponentTag openTag)
        Renders markup until a closing tag for openTag is reached.
        Parameters:
        openTag - The open tag
      • getTagAttribute

        public final String getTagAttribute​(String name,
                                            boolean withWicketNamespace)
        Gets the attribute with 'name' for the tag at the current position
        Parameters:
        name -
        withWicketNamespace -
        Returns:
        null, if not found
      • getPreviousTag

        public final ComponentTag getPreviousTag()
        Sometime its necessary to get the previous markup element versus the current one.
        Returns:
        The previous element (currentIndex - 1)
      • toHtmlDebugString

        public String toHtmlDebugString()
        Returns:
        An HTML string highlighting the current position in the markup stream