Package org.apache.wicket.markup
Class MarkupStream
- java.lang.Object
-
- org.apache.wicket.markup.MarkupStream
-
public class MarkupStream extends java.lang.ObjectA stream ofMarkupElements, subclasses of which areComponentTagandRawMarkup. 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 booleanatCloseTag()booleanatOpenCloseTag()booleanatOpenCloseTag(java.lang.String componentId)booleanatOpenTag()booleanatOpenTag(java.lang.String id)booleanatTag()booleanequalMarkup(MarkupStream markupStream)True, if associate markup is the same.booleanequalTo(MarkupStream that)Compare this markup stream with another oneMarkupElementget()MarkupElementget(int index)java.lang.Class<? extends Component>getContainerClass()Get the component/container's Class which is directly associated with the stream.intgetCurrentIndex()java.lang.StringgetEncoding()Gets the markup encoding.IMarkupFragmentgetMarkupFragment()ComponentTaggetPreviousTag()Sometime its necessary to get the previous markup element versus the current one.org.apache.wicket.util.resource.IResourceStreamgetResource()ComponentTaggetTag()java.lang.StringgetTagAttribute(java.lang.String name, boolean withWicketNamespace)Gets the attribute with 'name' for the tag at the current positionjava.lang.StringgetWicketNamespace()Get the wicket namespace valid for this specific markupbooleanhasMore()booleanisCurrentIndexInsideTheStream()booleanisMergedMarkup()MarkupElementnext()Note:MarkupElementnextOpenTag()Note:MarkupStreamsetCurrentIndex(int currentIndex)voidskipComponent()Skips this component and all nested componentsvoidskipRawMarkup()Skips any raw markup at the current positionvoidskipToMatchingCloseTag(ComponentTag openTag)Renders markup until a closing tag for openTag is reached.booleanskipUntil(java.lang.Class<? extends MarkupElement> clazz)Skip until an element of type 'clazz' is foundvoidskipUntil(java.lang.String wicketTagName)Skips any markup at the current position until the wicket tag name is found.voidthrowMarkupException(java.lang.String message)Throws a new markup exceptionjava.lang.StringtoHtmlDebugString()java.lang.StringtoString()
-
-
-
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(java.lang.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(java.lang.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 java.lang.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 java.lang.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 org.apache.wicket.util.resource.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 java.lang.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(java.lang.Class<? extends MarkupElement> clazz)
Skip until an element of type 'clazz' is found- Parameters:
clazz-- Returns:
- true if found
-
skipUntil
public void skipUntil(java.lang.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 java.lang.String getTagAttribute(java.lang.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(java.lang.String message)
Throws a new markup exception- Parameters:
message- The exception message- Throws:
MarkupException
-
toHtmlDebugString
public java.lang.String toHtmlDebugString()
- Returns:
- An HTML string highlighting the current position in the markup stream
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Returns:
- String representation of markup stream
-
-