org.apache.wicket.markup
Class MarkupStream

java.lang.Object
  extended by org.apache.wicket.markup.MarkupStream

public final 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

Constructor Summary
MarkupStream(Markup markup)
          Constructor
 
Method Summary
 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 one
 int findComponentIndex(String path, String id)
          Find the markup element index of the component with 'path'
 MarkupElement 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.
 IResourceStream getResource()
           
 ComponentTag getTag()
           
 String getWicketNamespace()
          Get the wicket namespace valid for this specific markup
 String getXmlDeclaration()
          Return the XML declaration string, in case if found in the markup.
 boolean hasMore()
           
 boolean isMergedMarkup()
           
 MarkupElement next()
          The correct way of using MarkupStream is like:
 void setCurrentIndex(int currentIndex)
           
 void skipComponent()
          Skips this component and all nested components
 void skipRawMarkup()
          Skips any raw markup at the current position
 void skipToMatchingCloseTag(ComponentTag openTag)
          Renders markup until a closing tag for openTag is reached.
 void 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 exception
 String toHtmlDebugString()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MarkupStream

public MarkupStream(Markup 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

findComponentIndex

public final int findComponentIndex(String path,
                                    String id)
Find the markup element index of the component with 'path'

Parameters:
path - The component path expression
id - The component's id to search for
Returns:
-1, if not found

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

getXmlDeclaration

public String getXmlDeclaration()
Return the XML declaration string, in case if found in the markup.

Returns:
Null, if not found.

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()
The correct way of using MarkupStream is like:
 while (markupStream.hasMore())
 {
    final MarkupElement cursor = markupStream.get();
    ...
    markupStream.next();
 }
 

Returns:
The next markup element in the stream

setCurrentIndex

public void setCurrentIndex(int currentIndex)
Parameters:
currentIndex - New current index in the stream

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 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

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

toString

public String toString()
Overrides:
toString in class Object
Returns:
String representation of markup stream


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.