au.id.jericho.lib.html

Class Attribute

Implemented Interfaces:
CharSequence, Comparable

public final class Attribute
extends Segment

Represents a single attribute name/value segment within a StartTag.

An instance of this class is a representation of a single attribute in the source document and is not modifiable. The AttributesOutputSegment class provides the means to add, delete or modify attributes and their values for inclusion in an OutputDocument.

Obtained using the Attributes.get(String key) method.

See also the XML 1.0 specification for attributes.

See Also:
Attributes

Method Summary

String
getDebugInfo()
Returns a string representation of this object useful for debugging purposes.
String
getKey()
Returns the name of this attribute in lower case.
String
getName()
Returns the name of this attribute in original case.
Segment
getNameSegment()
Returns the segment spanning the name of this attribute.
char
getQuoteChar()
Returns the character used to quote the value.
String
getValue()
Returns the decoded value of this attribute, or null if it has no value.
Segment
getValueSegment()
Returns the segment spanning the value of this attribute, or null if it has no value.
Segment
getValueSegmentIncludingQuotes()
Returns the segment spanning the value of this attribute, including quotation marks if any, or null if it has no value.
boolean
hasValue()
Indicates whether this attribute has a value.

Methods inherited from class au.id.jericho.lib.html.Segment

charAt, compareTo, encloses, encloses, equals, extractText, extractText, findAllCharacterReferences, findAllComments, findAllElements, findAllElements, findAllElements, findAllStartTags, findAllStartTags, findAllStartTags, findAllTags, findAllTags, findFormControls, findFormFields, findWords, getBegin, getChildElements, getDebugInfo, getEnd, getSourceText, getSourceTextNoWhitespace, hashCode, ignoreWhenParsing, isComment, isWhiteSpace, isWhiteSpace, length, parseAttributes, subSequence, toString

Method Details

getDebugInfo

public String getDebugInfo()
Returns a string representation of this object useful for debugging purposes.
Overrides:
getDebugInfo in interface Segment
Returns:
a string representation of this object useful for debugging purposes.

getKey

public String getKey()
Returns:
the name of this attribute in lower case.
See Also:
getName()

getName

public String getName()
Returns:
the name of this attribute in original case.
See Also:
getKey()

getNameSegment

public Segment getNameSegment()
Returns the segment spanning the name of this attribute.
Returns:
the segment spanning the name of this attribute.
See Also:
getName()

getQuoteChar

public char getQuoteChar()
Returns the character used to quote the value.

The return value is either a double-quote ("), a single-quote ('), or a space.

Returns:
the character used to quote the value, or a space if the value is not quoted or this attribute has no value.

getValue

public String getValue()
Returns the decoded value of this attribute, or null if it has no value.

This is equivalent to CharacterReference.decode(getValueSegment(),true).

Note that before version 1.4.1 this method returned the raw value of the attribute as it appears in the source document, without decoding.

To obtain the raw value without decoding, use getValueSegment().toString().

Special attention should be given to attributes that contain URLs, such as the href attribute. When such an attribute contains a URL with parameters (as described in the form-urlencoded media type), the ampersand (&) characters used to separate the parameters should be encoded to prevent the parameter names from being unintentionally interpreted as character entity references. This requirement is explicitly stated in the HTML 4.01 specification section 5.3.2.

For example, take the following element in the source document:

<a href="Report.jsp?chapt=2&sect=3">next</a>
By default, calling getAttributes().getValue("href") on this element returns the string "Report.jsp?chapt=2§=3", since the text "&sect" is interpreted as the rarely used character entity reference CharacterEntityReference._sect &sect; (U+00A7), despite the fact that it is missing the terminating semicolon (;).

Most browsers recognise unterminated character entity references in attribute values representing a codepoint of U+00FF or below, but ignore those representing codepoints above this value. One relatively popular browser only recognises those representing a codepoint of U+003E or below, meaning it would have interpreted the URL in the above example differently to most other browsers. Most browsers also use different rules depending on whether the unterminated character reference is inside or outside of an attribute value, with both of these possibilities further split into different rules for character entity references, decimal character references, and hexadecimal character references.

The behaviour of this library is determined by the current compatibility mode setting, which is determined by the Config.CurrentCompatibilityMode property.

Returns:
the decoded value of this attribute, or null if it has no value.

getValueSegment

public Segment getValueSegment()
Returns the segment spanning the value of this attribute, or null if it has no value.
Returns:
the segment spanning the value of this attribute, or null if it has no value.
See Also:
getValue()

getValueSegmentIncludingQuotes

public Segment getValueSegmentIncludingQuotes()
Returns the segment spanning the value of this attribute, including quotation marks if any, or null if it has no value.

If the value is not enclosed by quotation marks, this is the same as the value segment

Returns:
the segment spanning the value of this attribute, including quotation marks if any, or null if it has no value.

hasValue

public boolean hasValue()
Returns:
true if this attribute has a value, otherwise false.