Package org.apache.wicket.markup
Class MarkupStream
- java.lang.Object
-
- org.apache.wicket.markup.MarkupStream
-
public class MarkupStream extends Object
A stream ofMarkupElement
s, subclasses of which areComponentTag
andRawMarkup
. 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
-
-
Constructor Summary
Constructors Constructor Description MarkupStream(IMarkupFragment markup)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
atCloseTag()
boolean
atOpenCloseTag()
boolean
atOpenCloseTag(String componentId)
boolean
atOpenTag()
boolean
atOpenTag(String id)
boolean
atTag()
boolean
equalMarkup(MarkupStream markupStream)
True, if associate markup is the same.boolean
equalTo(MarkupStream that)
Compare this markup stream with another oneMarkupElement
get()
MarkupElement
get(int index)
Class<? extends Component>
getContainerClass()
Get the component/container's Class which is directly associated with the stream.int
getCurrentIndex()
String
getEncoding()
Gets the markup encoding.IMarkupFragment
getMarkupFragment()
ComponentTag
getPreviousTag()
Sometime its necessary to get the previous markup element versus the current one.IResourceStream
getResource()
ComponentTag
getTag()
String
getTagAttribute(String name, boolean withWicketNamespace)
Gets the attribute with 'name' for the tag at the current positionString
getWicketNamespace()
Get the wicket namespace valid for this specific markupboolean
hasMore()
boolean
isCurrentIndexInsideTheStream()
boolean
isMergedMarkup()
MarkupElement
next()
Note:MarkupElement
nextOpenTag()
Note:MarkupStream
setCurrentIndex(int currentIndex)
void
skipComponent()
Skips this component and all nested componentsvoid
skipRawMarkup()
Skips any raw markup at the current positionvoid
skipToMatchingCloseTag(ComponentTag openTag)
Renders markup until a closing tag for openTag is reached.boolean
skipUntil(Class<? extends MarkupElement> clazz)
Skip until an element of type 'clazz' is foundvoid
skipUntil(String wicketTagName)
Skips any markup at the current position until the wicket tag name is found.void
throwMarkupException(String message)
Throws a new markup exceptionString
toHtmlDebugString()
String
toString()
-
-
-
Constructor Detail
-
MarkupStream
public MarkupStream(IMarkupFragment markup)
Constructor- Parameters:
markup
- List of markup elements
-
-
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()
- Returns:
- The current markup element
-
get
public MarkupElement get(int index)
- Parameters:
index
- The index of a markup element- Returns:
- The MarkupElement element
-
getContainerClass
public final Class<? extends Component> getContainerClass()
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
-
getResource
public IResourceStream getResource()
- Returns:
- The resource where this markup stream came from
-
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
-
nextOpenTag
public MarkupElement nextOpenTag()
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
-
getMarkupFragment
public final IMarkupFragment getMarkupFragment()
- Returns:
- A markup fragment starting at the current position
-
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)
-
throwMarkupException
public void throwMarkupException(String message)
Throws a new markup exception- Parameters:
message
- The exception message- Throws:
MarkupException
-
toHtmlDebugString
public String toHtmlDebugString()
- Returns:
- An HTML string highlighting the current position in the markup stream
-
-