Package com.facilita.fc.web
Class HtmlElement
- java.lang.Object
-
- com.facilita.fc.web.HtmlElement
-
- Direct Known Subclasses:
Form,InputElement,OptionElement,SelectElement,TextAreaElement
public class HtmlElement extends java.lang.ObjectRepresents an HTML element within an HTML form. An HTML element is everything from the start tag to the end tag.e.g.
<input type="text" name="firstname">would be represented by a singleInputElementobject, whereInputElementis a subclass ofHtmlElement.
-
-
Constructor Summary
Constructors Constructor Description HtmlElement(long cPtr, boolean cMemoryOwn)For internal use only.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description HtmlElementclone()Creates a copy of this HTML element.voiddelete()intgetAfterEndTagPosition()Gets the character offset into the HTML document at which the 1st character (not including < > tag characters) in this HTML element appears.intgetAfterStartTagPosition()Gets the character offset into the HTML document at which the 1st character (not including < > tag characters) in this HTML element appears.java.lang.StringgetAttribute(java.lang.String name)Gets the value of the specified attribute, or an emptyStringif the attribute is not contained within this HTML element.java.util.Map<java.lang.String,java.lang.String>getAttributes()Gets all the attributes contained in thisHtmlElementas aMapof attribute names to values.java.lang.StringgetCharEncoding()Gets the character encoding that is used to decode the data contained in thisHtmlElement, for example"UTF-8".java.lang.StringgetContent()Gets the content of this HTML element.intgetContentPosition()Gets the character offset into the HTML document at which this HTML element's content starts.static longgetCPtr(HtmlElement obj)For internal use only.java.lang.StringgetId()Gets the value of the"id"attribute for this HTML element.java.lang.StringgetName()Gets the value of the"name"attribute for this HTML element.java.lang.StringgetTag()Gets the tag name of this HTML element.java.lang.StringgetValue()Gets the value of the"value"attribute for this HTML element.booleanhasAttribute(java.lang.String name)Returnstrueif this HTML element contains the specified attribute.booleanisDisabled()Returnstrueif this HTML element has been disabled.booleanisSuccessfulControl()Returnstrueif this HTML element currently represents a successful control.voidremoveAttribute(java.lang.String name)Removes an attribute from this HTML element.voidsetAttribute(java.lang.String name)Sets the value of the specified attribute to an emptyString.voidsetAttribute(java.lang.String name, java.lang.String value)Sets the value of the specified attribute.voidsetCharEncoding(java.lang.String charEncoding)Sets the character encoding that is used to decode the data contained in thisHtmlElement, for example"UTF-8".voidsetContent(java.lang.String content)Sets the content of this HTML element.voidsetDisabled(boolean disable)Sets or removes the"disabled"attribute for this HTML element.voidsetId(java.lang.String id)Sets the value of the"id"attribute for this HTML element.voidsetName(java.lang.String name)Sets the value of the"name"attribute for this HTML element.voidsetValue(java.lang.String value)Sets the value of the"value"attribute for this HTML element.
-
-
-
Method Detail
-
getCPtr
public static long getCPtr(HtmlElement obj)
For internal use only. Of no interest to the user.- Parameters:
obj- a reference to an object of this class- Returns:
- a long containing the address of the CPP wrapped object
-
delete
public void delete()
-
getAttributes
public java.util.Map<java.lang.String,java.lang.String> getAttributes() throws java.io.UnsupportedEncodingException, com.facilita.exception.InternalErrorGets all the attributes contained in thisHtmlElementas aMapof attribute names to values.- Returns:
- all the attributes contained in this
HtmlElementas aMapof attribute names to values - Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.com.facilita.exception.InternalError- An internal error occurred.
-
hasAttribute
public boolean hasAttribute(java.lang.String name) throws java.io.UnsupportedEncodingExceptionReturnstrueif this HTML element contains the specified attribute.e.g.
if (element.hasAttribute("checked")) { // The element has the "checked" attribute }- Parameters:
name- the name of the attribute to look for- Returns:
trueif thisHtmlElementcontains this attribute- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.
-
getAttribute
public java.lang.String getAttribute(java.lang.String name) throws java.io.UnsupportedEncodingExceptionGets the value of the specified attribute, or an emptyStringif the attribute is not contained within this HTML element.e.g.
// Get the value of the "name" attribute for the HTML element String name = element.getAttribute("name");- Parameters:
name- the name of the attribute from which the value should be returned- Returns:
- the value of the attribute, or an empty
Stringif no attribute with the specifiednamecould be found - Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.- See Also:
setAttribute(String, String)
-
setAttribute
public void setAttribute(java.lang.String name) throws java.io.UnsupportedEncodingExceptionSets the value of the specified attribute to an emptyString.- Parameters:
name- the name of the attribute on which to set the value- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.- See Also:
setAttribute(String, String)
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.String value) throws java.io.UnsupportedEncodingExceptionSets the value of the specified attribute. The attribute will be added if it does not already exist.- Parameters:
name- the name of the attribute on which to set the valuevalue- the new value of the attribute- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.- See Also:
getAttribute(String)
-
removeAttribute
public void removeAttribute(java.lang.String name) throws java.io.UnsupportedEncodingExceptionRemoves an attribute from this HTML element. This method has no effect if the attribute does not exist.- Parameters:
name- the name of the attribute to remove- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.- See Also:
setAttribute(String, String),getAttribute(String)
-
getContent
public java.lang.String getContent() throws java.io.UnsupportedEncodingExceptionGets the content of this HTML element. This includes everything between the HTML tags, but excludes the tags themselves and any attributes.- Returns:
- the content of the HTML element
- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.- See Also:
setContent(String)
-
setContent
public void setContent(java.lang.String content) throws java.io.UnsupportedEncodingExceptionSets the content of this HTML element. This includes everything between the HTML tags, but excludes the tags themselves and any attributes.- Parameters:
content- the content to set- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.- See Also:
getContent()
-
getName
public java.lang.String getName() throws java.io.UnsupportedEncodingExceptionGets the value of the"name"attribute for this HTML element. Calling this method is equivalent to callinggetAttribute("name").- Returns:
- the value of the
"name"attribute - Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.- See Also:
getAttribute(String),setName(String)
-
setName
public void setName(java.lang.String name) throws java.io.UnsupportedEncodingExceptionSets the value of the"name"attribute for this HTML element. Calling this method is equivalent to callingsetAttribute("name", name).- Parameters:
name- the new value of the"name"attribute- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.- See Also:
getName(),setAttribute(String, String)
-
getValue
public java.lang.String getValue() throws java.io.UnsupportedEncodingExceptionGets the value of the"value"attribute for this HTML element. Calling this method is equivalent to callinggetAttribute("value").- Returns:
- the value of the
"value"attribute - Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.- See Also:
getAttribute(String),setValue(String)
-
setValue
public void setValue(java.lang.String value) throws java.io.UnsupportedEncodingExceptionSets the value of the"value"attribute for this HTML element. Calling this method is equivalent to callingsetAttribute("value", value).- Parameters:
value- the new value of the"value"attribute- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.- See Also:
getValue(),setAttribute(String, String)
-
getId
public java.lang.String getId() throws java.io.UnsupportedEncodingExceptionGets the value of the"id"attribute for this HTML element. Calling this method is equivalent to callinggetAttribute("id").- Returns:
- the value of the
"id"attribute - Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.- See Also:
getAttribute(String),setId(String)
-
setId
public void setId(java.lang.String id) throws java.io.UnsupportedEncodingExceptionSets the value of the"id"attribute for this HTML element. Calling this method is equivalent to callingsetAttribute("id", id).- Parameters:
id- the new value of the"id"attribute- Throws:
java.io.UnsupportedEncodingException- The specified encoding is not supported.- See Also:
getId(),setAttribute(String, String)
-
getTag
public java.lang.String getTag()
Gets the tag name of this HTML element.e.g. the HTML element
<input type="text" name="firstname">has a tag name of"input".- Returns:
- the tag name of this HTML element
-
isDisabled
public boolean isDisabled()
Returnstrueif this HTML element has been disabled. An element is disabled if it has a"disabled"attribute, i.e. ifhasAttribute("disabled")returnstrue.- Returns:
trueif this element has the"disabled"attribute
-
setDisabled
public void setDisabled(boolean disable)
Sets or removes the"disabled"attribute for this HTML element.setDisabled(true)is equivalent tosetAttribute("disabled").setDisabled(false)is equivalent toremoveAttribute("disabled").- Parameters:
disable-trueto disable the HTML element,falseto enable it
-
getAfterStartTagPosition
public int getAfterStartTagPosition()
Gets the character offset into the HTML document at which the 1st character (not including < > tag characters) in this HTML element appears.e.g. if the content of the HTTP
Responseobject is:
Then this code would output 47, i.e. the offset of the space after the opening<html><body><form name="myForm">Select: <select name="mySelect"><option value="1">1</option><option value="2">2</option></select></form></body></html>'<select':Form form = response.extractForm("myForm"); SelectElement select = form.getSelectElement("mySelect"); writeMessage("AfterStartTagPosition : " + select.getAfterStartTagPosition());- Returns:
- the character offset into the HTML document at which the 1st character in this HTML element appears
- See Also:
getAfterEndTagPosition()
-
getAfterEndTagPosition
public int getAfterEndTagPosition()
Gets the character offset into the HTML document at which the 1st character (not including < > tag characters) in this HTML element appears.e.g. if the content of the HTTP
Responseobject is:
Then this code would output 129, i.e. the offset of the<html><body><form name="myForm">Select: <select name="mySelect"><option value="1">1</option><option value="2">2</option></select></form></body></html>'<'after the closing'</select>':Form form = response.extractForm("myForm"); SelectElement select = form.getSelectElement("mySelect"); writeMessage("AfterEndTagPosition : " + select.getAfterEndTagPosition());- Returns:
- the character offset into the HTML document at which the last character in this HTML element appears
- See Also:
getAfterStartTagPosition()
-
getContentPosition
public int getContentPosition()
Gets the character offset into the HTML document at which this HTML element's content starts.- Returns:
- the character offset into the HTML document at which this HTML element's content starts
-
isSuccessfulControl
public boolean isSuccessfulControl()
Returnstrueif this HTML element currently represents a successful control. A successful control is one that is valid for submission, i.e. one that will be sent to the web server when the form is submitted.- Returns:
trueif this HTML element is a successful control
-
clone
public HtmlElement clone()
Creates a copy of this HTML element.- Overrides:
clonein classjava.lang.Object- Returns:
- a new
HtmlElementobject which is an exact copy of this HTML element
-
setCharEncoding
public void setCharEncoding(java.lang.String charEncoding)
Sets the character encoding that is used to decode the data contained in thisHtmlElement, for example"UTF-8".- Parameters:
charEncoding- the character encoding to set- See Also:
getCharEncoding()
-
getCharEncoding
public java.lang.String getCharEncoding()
Gets the character encoding that is used to decode the data contained in thisHtmlElement, for example"UTF-8".- Returns:
- the character encoding
- See Also:
setCharEncoding(String)
-
-