Agent System POND 1.2 (28.2.2002)

FIM.Util.WWW.Form
Class FormElement

java.lang.Object
  |
  +--FIM.Util.WWW.Form.FormElement
All Implemented Interfaces:
Element, Serializable
Direct Known Subclasses:
ActionElement, ElementGroup, SelectableElement, TextElement

public abstract class FormElement
extends Object
implements Element, Serializable

An element of a HTML-form. It is connected to a HTMLDocument, has a start and end offset, a parent element, a label and a name. It can contain a number of children and attributes.

Version:
1.0, 1.7.2000
Author:
Michael Sonntag
See Also:
Serialized Form

Field Summary
protected  MutableAttributeSet attributes
          The attributes of this element.
protected  Vector children
          The children of this element, if any.
 
Constructor Summary
FormElement(HTMLDocument doc, Element parent, int startOffs, int endOffs, String name)
          Creates a new form element.
 
Method Summary
 AttributeSet getAttributes()
          Fetches the collection of attributes this element contains.
 Document getDocument()
          Fetches the document associated with this element.
 Element getElement(int index)
          Fetches the child element at the given index.
 int getElementCount()
          Gets the number of child elements contained by this element.
 int getElementIndex(int offset)
          Gets the child element index closest to the given offset.
abstract  String getEncoded()
          Returns this element in encoded (application/x-www-form-urlencoded) form.
 int getEndOffset()
          Fetches the offset from the beginning of the document that this element ends at.
 String getLabel()
          Fetch the label of this element.
 String getName()
          Fetches the name of the element.
 Element getParentElement()
          Fetches the parent element.
 int getStartOffset()
          Fetches the offset from the beginning of the document that this element begins at.
 boolean isLeaf()
          Is this element a leaf element?
 int match(String[] matchStr)
          Matches this element against a number of strings and returns a measure for matching them. 0=no match, 100=perfect match.
May be expanded to similarity-matching in the future (similar sounding words, same word-stem, etc.).
abstract  void reset()
          Resets this element to its initial state.
protected  void setLabel(String label)
          Set the label for this element.
 String toString()
          Returns a string representation of the form element.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

children

protected Vector children
The children of this element, if any.

attributes

protected MutableAttributeSet attributes
The attributes of this element. Always exists, but may be empty.
Constructor Detail

FormElement

public FormElement(HTMLDocument doc,
                   Element parent,
                   int startOffs,
                   int endOffs,
                   String name)
Creates a new form element.
Parameters:
doc - the document this element belongs to
parent - the parent of this element
startOffs - start offset of the element in the document
endOffs - end offset of the element in the document
name - the name of the element
Method Detail

getDocument

public Document getDocument()
Fetches the document associated with this element.
Specified by:
getDocument in interface Element
Returns:
the document

getParentElement

public Element getParentElement()
Fetches the parent element. Will usually be the form.
Specified by:
getParentElement in interface Element
Returns:
the parent element

getName

public String getName()
Fetches the name of the element.
Specified by:
getName in interface Element
Returns:
the element name

getAttributes

public AttributeSet getAttributes()
Fetches the collection of attributes this element contains.
Specified by:
getAttributes in interface Element
Returns:
the attributes for the element

getStartOffset

public int getStartOffset()
Fetches the offset from the beginning of the document that this element begins at.
Specified by:
getStartOffset in interface Element
Returns:
the starting offset >= 0

getEndOffset

public int getEndOffset()
Fetches the offset from the beginning of the document that this element ends at.
Specified by:
getEndOffset in interface Element
Returns:
the ending offset >= 0

getElementIndex

public int getElementIndex(int offset)
Gets the child element index closest to the given offset. The offset is specified relative to the begining of the document.
Specified by:
getElementIndex in interface Element
Parameters:
offset - the specified offset >= 0
Returns:
the element index >= 0

getElementCount

public int getElementCount()
Gets the number of child elements contained by this element. If this element is a leaf, a count of zero is returned.
Specified by:
getElementCount in interface Element
Returns:
the number of child elements >= 0

getElement

public Element getElement(int index)
Fetches the child element at the given index.
Specified by:
getElement in interface Element
Parameters:
index - the specified index >= 0
Returns:
the child element

isLeaf

public boolean isLeaf()
Is this element a leaf element?
Specified by:
isLeaf in interface Element
Returns:
true if a leaf element else false

getLabel

public String getLabel()
Fetch the label of this element. If none set, null is returned.
Returns:
label of the element

setLabel

protected void setLabel(String label)
Set the label for this element. Removing by calling with null as parameter
Parameters:
label - the new label

reset

public abstract void reset()
Resets this element to its initial state.

getEncoded

public abstract String getEncoded()
Returns this element in encoded (application/x-www-form-urlencoded) form.
Returns:
the element in encoded form or an empty string ("") if it shall not be passed to the server
See Also:
URLEncoder

match

public int match(String[] matchStr)
Matches this element against a number of strings and returns a measure for matching them. 0=no match, 100=perfect match.
May be expanded to similarity-matching in the future (similar sounding words, same word-stem, etc.).

Strategy for matching:

  1. Label of the element: 100 for exact match, 90 for substring (case-insensitive)
  2. Name of the lement: 95 for exact match, 85 for substring (case-insensitive)
  3. Text in front of the element: 70- (case-insensitive)
  4. Text after the element: 50- (case-insensitive)
The maximum value of all string provided will be returned;

Parameters:
matchStr - an array of strings which are matched against this element
Returns:
measure how much this element matches the parameter

toString

public String toString()
Returns a string representation of the form element.
Overrides:
toString in class Object
Returns:
string representation of the form element

Agent System POND 1.2 (28.2.2002)

Submit a bug

Copyright 2001,2002 Michael Sonntag & Institute for Information Processing and Microprocessor Technology (FIM), Johannes-Kepler-University Linz, Altenbergerstr. 69, A-4040 Linz, Austria.