| java.lang.Object au.id.jericho.lib.html.Segment au.id.jericho.lib.html.nodoc.SequentialListSegment au.id.jericho.lib.html.Attributes
Attributes | final public class Attributes extends SequentialListSegment (Code) | | Represents the list of
Attribute objects present within a particular
StartTag .
This segment starts at the end of the start tag's
and ends at the end of the last attribute.
The attributes in this list are a representation of those found in the source document and are not modifiable.
The
OutputDocument.replace(AttributesMap) and
OutputDocument#replace(Attributes, boolean convertNamesToLowerCase) methods
provide the means to add, delete or modify attributes and their values in an
OutputDocument .
As of version 2.4, any
encountered inside the attributes area of a non-server tag
no longer interfere with the parsing of the attributes.
If too many syntax errors are encountered while parsing a start tag's attributes, the parser rejects the entire start tag
and generates a
entry.
The threshold for the number of errors allowed can be set using the
Attributes.setDefaultMaxErrorCount(int) static method.
Obtained using the
StartTag.getAttributes method, or explicitly using the
Source.parseAttributes(int posint maxEnd) method.
It is common for instances of this class to contain no attributes.
See also the XML 1.0 specification for attributes.
Note that before version 2.0 the segment ended just before the tag's
instead of at the end of the last attribute.
See Also: StartTag See Also: Attribute |
Method Summary | |
static void | appendHTML(Writer writer, Map attributesMap) Outputs the contents of the specified
as HTML attribute name/value pairs to the specified Writer . | StringBuffer | appendTidy(StringBuffer sb, Tag nextTag) | static Attributes | construct(Source source, int startTagBegin, StartTagType startTagType, String tagName) | static Attributes | construct(Source source, int startTagBegin, int attributesBegin, int maxEnd, StartTagType startTagType, String tagName, int maxErrorCount) | static Attributes | construct(Source source, int begin, int maxEnd, int maxErrorCount) | public static String | generateHTML(Map attributesMap) Returns the contents of the specified
as HTML attribute name/value pairs.
Each attribute (including the first) is preceded by a single space, and all values are
and enclosed in double quotes.
The map keys must be of type String and values must be objects that implement the CharSequence interface.
A null value represents an attribute with no value.
Parameters: attributesMap - a map containing attribute name/value pairs. | public Attribute | get(String name) Returns the
Attribute with the specified name (case insensitive).
If more than one attribute exists with the specified name (which is illegal HTML),
the first is returned.
Parameters: name - the name of the attribute to get. | public int | getCount() Returns the number of attributes. | public String | getDebugInfo() Returns a string representation of this object useful for debugging purposes. | public static int | getDefaultMaxErrorCount() Returns the default maximum error count allowed when parsing attributes. | Map | getMap(boolean convertNamesToLowerCase) | String | getRawValue(String name) Returns the raw (not
) value of the attribute, or null if the attribute
. | public String | getValue(String name) Returns the
value of the attribute with the specified name (case insensitive).
Returns null if no attribute with the specified name exists or
the attribute
.
This is equivalent to
Attributes.get(String) get(name) .
Attribute.getValue getValue() ,
except that it returns null if no attribute with the specified name exists instead of throwing a
NullPointerException .
Parameters: name - the name of the attribute to get. | public Iterator | iterator() Returns an iterator over the
Attribute objects in this list in order of appearance. | public ListIterator | listIterator(int index) Returns a list iterator of the
Attribute objects in this list in order of appearance,
starting at the specified position in the list.
The specified index indicates the first item that would be returned by an initial call to the next() method.
An initial call to the previous() method would return the item with the specified index minus one.
IMPLEMENTATION NOTE: For efficiency reasons this method does not return an immutable list iterator.
Calling any of the add(Object) , remove() or set(Object) methods on the returned
ListIterator does not throw an exception but could result in unexpected behaviour.
Parameters: index - the index of the first item to be returned from the list iterator (by a call to the next() method). | public Map | populateMap(Map attributesMap, boolean convertNamesToLowerCase) Populates the specified Map with the name/value pairs from these attributes.
Both names and values are stored as String objects.
The entries are added in order of apprearance in the source document.
An attribute with
is represented by a map entry with a null value.
Attribute values are automatically
before storage in the map.
Parameters: attributesMap - the map to populate, must not be null . Parameters: convertNamesToLowerCase - specifies whether all attribute names are converted to lower case in the map. | public static void | setDefaultMaxErrorCount(int value) Sets the default maximum error count allowed when parsing attributes. |
appendHTML | static void appendHTML(Writer writer, Map attributesMap) throws IOException(Code) | | Outputs the contents of the specified
as HTML attribute name/value pairs to the specified Writer .
Each attribute is preceded by a single space, and all values are
and enclosed in double quotes.
Parameters: out - the Writer to which the output is to be sent. Parameters: attributesMap - a map containing attribute name/value pairs. throws: IOException - if an I/O exception occurs. See Also: Attributes.populateMap(Map attributesMap,boolean convertNamesToLowerCase) |
construct | static Attributes construct(Source source, int startTagBegin, StartTagType startTagType, String tagName)(Code) | | called from StartTagType.parseAttributes(Source, int startTagBegin, String tagName)
|
construct | static Attributes construct(Source source, int startTagBegin, int attributesBegin, int maxEnd, StartTagType startTagType, String tagName, int maxErrorCount)(Code) | | called from StartTag.parseAttributes(int maxErrorCount)
|
construct | static Attributes construct(Source source, int begin, int maxEnd, int maxErrorCount)(Code) | | called from Source.parseAttributes(int pos, int maxEnd, int maxErrorCount)
|
generateHTML | public static String generateHTML(Map attributesMap)(Code) | | Returns the contents of the specified
as HTML attribute name/value pairs.
Each attribute (including the first) is preceded by a single space, and all values are
and enclosed in double quotes.
The map keys must be of type String and values must be objects that implement the CharSequence interface.
A null value represents an attribute with no value.
Parameters: attributesMap - a map containing attribute name/value pairs. the contents of the specified as HTML attribute name/value pairs. See Also: StartTag.generateHTML(String tagNameMap attributesMapboolean emptyElementTag) |
get | public Attribute get(String name)(Code) | | Returns the
Attribute with the specified name (case insensitive).
If more than one attribute exists with the specified name (which is illegal HTML),
the first is returned.
Parameters: name - the name of the attribute to get. the attribute with the specified name, or null if no attribute with the specified name exists. See Also: Attributes.getValue(String name) |
getCount | public int getCount()(Code) | | Returns the number of attributes.
This is equivalent to calling the size() method specified in the List interface.
the number of attributes. |
getDebugInfo | public String getDebugInfo()(Code) | | Returns a string representation of this object useful for debugging purposes.
a string representation of this object useful for debugging purposes. |
getDefaultMaxErrorCount | public static int getDefaultMaxErrorCount()(Code) | | Returns the default maximum error count allowed when parsing attributes.
The system default value is 2.
When searching for start tags, the parser can find the end of the start tag only by
the attributes, as it is valid HTML for attribute values to contain '>' characters
(see the HTML 4.01 specification section 5.3.2).
If the source text being parsed does not follow the syntax of an attribute list at all, the parser assumes
that the text which was originally identified as the beginning of of a start tag is in fact some other text,
such as an invalid '<' character in the middle of some text, or part of a script element.
In this case the entire start tag is rejected.
On the other hand, it is quite common for attributes to contain minor syntactical errors,
such as an invalid character in an attribute name, or a couple of special characters in
that otherwise contain only attributes.
For this reason the parser allows a certain number of minor errors to occur while parsing an
attribute list before the entire start tag or attribute list is rejected.
This property indicates the number of minor errors allowed.
Major syntactical errors cause the start tag or attribute list to be rejected immediately, regardless
of the maximum error count setting.
Some errors are considered too minor to count at all (ignorable), such as missing whitespace between the end
of a quoted attribute value and the start of the next attribute name.
The classification of particular syntax errors in attribute lists into major, minor, and ignorable is
not part of the specification and may change in future versions.
Errors are
as they occur.
The value of this property is set using the
Attributes.setDefaultMaxErrorCount(int) method.
the default maximum error count allowed when parsing attributes. See Also: Source.parseAttributes(int posint maxEndint maxErrorCount) |
getMap | Map getMap(boolean convertNamesToLowerCase)(Code) | | |
getRawValue | String getRawValue(String name)(Code) | | Returns the raw (not
) value of the attribute, or null if the attribute
.
This is an internal convenience method.
the raw (not ) value of the attribute, or null if the attribute . |
getValue | public String getValue(String name)(Code) | | Returns the
value of the attribute with the specified name (case insensitive).
Returns null if no attribute with the specified name exists or
the attribute
.
This is equivalent to
Attributes.get(String) get(name) .
Attribute.getValue getValue() ,
except that it returns null if no attribute with the specified name exists instead of throwing a
NullPointerException .
Parameters: name - the name of the attribute to get. the value of the attribute with the specified name, or null if the attribute does not exist or . See Also: Attribute.getValue |
iterator | public Iterator iterator()(Code) | | Returns an iterator over the
Attribute objects in this list in order of appearance.
an iterator over the Attribute objects in this list in order of appearance. |
listIterator | public ListIterator listIterator(int index)(Code) | | Returns a list iterator of the
Attribute objects in this list in order of appearance,
starting at the specified position in the list.
The specified index indicates the first item that would be returned by an initial call to the next() method.
An initial call to the previous() method would return the item with the specified index minus one.
IMPLEMENTATION NOTE: For efficiency reasons this method does not return an immutable list iterator.
Calling any of the add(Object) , remove() or set(Object) methods on the returned
ListIterator does not throw an exception but could result in unexpected behaviour.
Parameters: index - the index of the first item to be returned from the list iterator (by a call to the next() method). a list iterator of the items in this list (in proper sequence), starting at the specified position in the list. throws: IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index > size() ). |
populateMap | public Map populateMap(Map attributesMap, boolean convertNamesToLowerCase)(Code) | | Populates the specified Map with the name/value pairs from these attributes.
Both names and values are stored as String objects.
The entries are added in order of apprearance in the source document.
An attribute with
is represented by a map entry with a null value.
Attribute values are automatically
before storage in the map.
Parameters: attributesMap - the map to populate, must not be null . Parameters: convertNamesToLowerCase - specifies whether all attribute names are converted to lower case in the map. the same map specified as the argument to the attributesMap parameter, populated with the name/value pairs from these attributes. See Also: Attributes.generateHTML(Map attributesMap) |
setDefaultMaxErrorCount | public static void setDefaultMaxErrorCount(int value)(Code) | | Sets the default maximum error count allowed when parsing attributes.
See the
Attributes.getDefaultMaxErrorCount() method for a full description of this property.
Parameters: value - the default maximum error count allowed when parsing attributes. |
|
|