jodd.servlet
Class HtmlUtil

java.lang.Object
  extended byjodd.servlet.HtmlUtil

public class HtmlUtil
extends java.lang.Object

Html utils for working with tag's names and attributes.


Constructor Summary
HtmlUtil()
           
 
Method Summary
static java.lang.String addAttribute(java.lang.String tagBody, java.lang.String name)
          Adds single attribute without value to a tag.
static java.lang.String addAttribute(java.lang.String body, java.lang.String name, int i)
          Adds single attribute without value to a tag.
static java.lang.String addAttribute(java.lang.String tagBody, java.lang.String name, java.lang.String value)
          Adds attribute and its value to a tag.
static java.lang.String addAttribute(java.lang.String body, java.lang.String name, java.lang.String value, int i)
          Adds attribute and its value to a tag.
static java.lang.String getAttribute(java.lang.String tagBody, java.lang.String attrName)
          Returns value of the first founded attribute that matches given name.
static java.lang.String getAttribute(java.lang.String body, java.lang.String attrName, int start)
          Returns value of the first founded attribute that matches given name.
static java.lang.String getTagName(java.lang.String tagBody)
          Returns tag's name.
static java.lang.String getTagName(java.lang.String body, int i)
          Returns tag's name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HtmlUtil

public HtmlUtil()
Method Detail

getTagName

public static java.lang.String getTagName(java.lang.String tagBody)
Returns tag's name. Given string represents a HTML body of a tag, therefore it must start with '<'.

Parameters:
tagBody - tag's body
Returns:
tag's name, or null if tag not found

getTagName

public static java.lang.String getTagName(java.lang.String body,
                                          int i)
Returns tag's name. Given string represents a HTML body and given starting index must be the index of tag's start (i.e. '<').

Names of ending tags will always start with '/' character.

Parameters:
body - hmtl body
i - index of tag's start
Returns:
tag's name, or null if tag not found

getAttribute

public static java.lang.String getAttribute(java.lang.String tagBody,
                                            java.lang.String attrName)
Returns value of the first founded attribute that matches given name. It is assumed that given string represents tag's body. Note: attribute must end with the =" or ='. Attribute name is not case sensitive.

Parameters:
tagBody - tag body
attrName - attribute name
Returns:
attribute value or null if attribute not found

getAttribute

public static java.lang.String getAttribute(java.lang.String body,
                                            java.lang.String attrName,
                                            int start)
Returns value of the first founded attribute that matches given name. Given string may not be just a tag's body, however, start and end parameters must define tags body. Note: attribute must end with the =" or ='. Attribute name is not case sensitive.

Parameters:
body - html body
attrName - attribute name
start - index of tag's start
Returns:
attribute value or null if attribute not found

addAttribute

public static java.lang.String addAttribute(java.lang.String tagBody,
                                            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.

Parameters:
tagBody - tag body
name - attribute name
value - attribute value
Returns:
tag string with added attribute and value

addAttribute

public static java.lang.String addAttribute(java.lang.String body,
                                            java.lang.String name,
                                            java.lang.String value,
                                            int i)
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.

Parameters:
body - html body
name - attribute name
value - attribute value
i - tag's offset in html body
Returns:
tag string with added attribute and value

addAttribute

public static java.lang.String addAttribute(java.lang.String tagBody,
                                            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.

Parameters:
tagBody - tag body
name - attribute name
Returns:
tag string with added attribute

addAttribute

public static java.lang.String addAttribute(java.lang.String body,
                                            java.lang.String name,
                                            int i)
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.

Parameters:
body - html body
name - attribute name
i - tag's offset in html body
Returns:
tag string with added attribute


Jodd v0.24.5 Javadoc