jodd.servlet
Class HtmlTag

java.lang.Object
  extended by jodd.servlet.HtmlTag

public class HtmlTag
extends java.lang.Object

Very simple utility for working with HTML tag's names and attributes.


Field Summary
protected  java.util.Map<java.lang.String,java.lang.String> attributes
           
protected  int attrStartIndex
           
protected  boolean changed
           
protected  int firstIndex
           
protected  boolean isClosedTag
           
protected  boolean isEndTag
           
protected  int lastIndex
           
protected  int nextIndex
           
protected  int startIndex
           
protected  java.lang.String suffix
           
protected  java.lang.String tag
           
static char TAG_END
           
static char TAG_START
           
protected  java.lang.String tagName
           
 
Constructor Summary
  HtmlTag(java.lang.String tag)
           
protected HtmlTag(java.lang.String tag, int startIndex, int nextIndex)
           
 
Method Summary
 java.lang.String getAttribute(java.lang.String attrName)
          Returns attribute value or null if attribute value doesn't exist.
 int getNextIndex()
          Returns next index for location start.
 int getStartIndex()
          Returns start index of the tag.
 java.lang.String getTag()
          Returns unchanged tag content.
 java.lang.String getTagName()
          Returns tag's name.
 boolean hasAttribute(java.lang.String attrName)
          Returns true if attribute is included in the tag.
 boolean isClosedTag()
          Returns true if tag is closed (ends with '/>').
 boolean isEndTag()
          Returns true if tag is closing tag.
static HtmlTag locateNextTag(java.lang.String html, int start)
          Locates HTML tag in specified source.
 void removeAttribute(java.lang.String attrName)
          Removes attribute from the tag.
protected  void resolveAttributes()
          Resolves attributes from tag's body.
 java.lang.String resolveTag()
          Resolves tag.
protected  java.lang.String resolveTagName()
          Resolves tag name from tag's body.
 void setAttribute(java.lang.String name)
          Adds single attribute without value to a tag.
 void setAttribute(java.lang.String name, java.lang.String value)
          Adds attribute and its value to a tag.
 void setSuffixText(java.lang.String suffix)
          Adds suffix text that will be appended after the tags end.
 java.lang.String toString()
           
 int totalAttributes()
          Returns total number of attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TAG_START

public static final char TAG_START
See Also:
Constant Field Values

TAG_END

public static final char TAG_END
See Also:
Constant Field Values

tag

protected final java.lang.String tag

nextIndex

protected final int nextIndex

firstIndex

protected final int firstIndex

lastIndex

protected final int lastIndex

isClosedTag

protected final boolean isClosedTag

isEndTag

protected final boolean isEndTag

startIndex

protected final int startIndex

tagName

protected java.lang.String tagName

attrStartIndex

protected int attrStartIndex

attributes

protected java.util.Map<java.lang.String,java.lang.String> attributes

changed

protected boolean changed

suffix

protected java.lang.String suffix
Constructor Detail

HtmlTag

public HtmlTag(java.lang.String tag)

HtmlTag

protected HtmlTag(java.lang.String tag,
                  int startIndex,
                  int nextIndex)
Method Detail

locateNextTag

public static HtmlTag locateNextTag(java.lang.String html,
                                    int start)
Locates HTML tag in specified source.


getTag

public java.lang.String getTag()
Returns unchanged tag content.


getNextIndex

public int getNextIndex()
Returns next index for location start.


getStartIndex

public int getStartIndex()
Returns start index of the tag.


isClosedTag

public boolean isClosedTag()
Returns true if tag is closed (ends with '/>').


isEndTag

public boolean isEndTag()
Returns true if tag is closing tag.


getTagName

public java.lang.String getTagName()
Returns tag's name.


resolveTagName

protected java.lang.String resolveTagName()
Resolves tag name from tag's body.


getAttribute

public java.lang.String getAttribute(java.lang.String attrName)
Returns attribute value or null if attribute value doesn't exist.


hasAttribute

public boolean hasAttribute(java.lang.String attrName)
Returns true if attribute is included in the tag.


removeAttribute

public void removeAttribute(java.lang.String attrName)
Removes attribute from the tag.


setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Adds attribute and its value to a tag. Attribute is added to the end of the tag, just before closing '>'. If name is not specified, nothing will be added. If value is not specified, it will be set to an empty string.


setAttribute

public void setAttribute(java.lang.String name)
Adds single attribute without value to a tag. Attribute is added to the end of the tag, just before closing '>'. If name is not specified, nothing will be added.


totalAttributes

public int totalAttributes()
Returns total number of attributes.


resolveAttributes

protected void resolveAttributes()
Resolves attributes from tag's body.


setSuffixText

public void setSuffixText(java.lang.String suffix)
Adds suffix text that will be appended after the tags end.


resolveTag

public java.lang.String resolveTag()
Resolves tag.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2003-2012 Jodd Team