Package org.htmlparser.lexer
Class PageAttribute
- java.lang.Object
-
- org.htmlparser.Attribute
-
- org.htmlparser.lexer.PageAttribute
-
- All Implemented Interfaces:
java.io.Serializable
public class PageAttribute extends Attribute
An attribute within a tag on a page. This attribute is similar to Attribute but 'lazy loaded' from thePageby providing the page and cursor offsets into the page for the name and value. This is done for speed, since if the name and value are not needed we can avoid the cost and memory overhead of creating the strings.Thus the property getters, defer to the base class unless the property is null, in which case an attempt is made to read it from the underlying page. Optimizations in the predicates and length calculation defer the actual instantiation of strings until absolutely needed.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected intmNameEndThe ending offset of the name within the page.protected intmNameStartThe starting offset of the name within the page.protected PagemPageThe page this attribute is extracted from.protected intmValueEndThe ending offset of the name within the page.protected intmValueStartThe starting offset of the value within the page.-
Fields inherited from class org.htmlparser.Attribute
mAssignment, mName, mQuote, mValue
-
-
Constructor Summary
Constructors Constructor Description PageAttribute()Create an empty attribute.PageAttribute(java.lang.String value)Create a whitespace attribute with the value given.PageAttribute(java.lang.String name, java.lang.String value)Create an attribute with the name and value given.PageAttribute(java.lang.String name, java.lang.String value, char quote)Create an attribute with the name, value and quote given.PageAttribute(java.lang.String name, java.lang.String assignment, java.lang.String value)Create an attribute with the name, assignment string and value given.PageAttribute(java.lang.String name, java.lang.String assignment, java.lang.String value, char quote)Create an attribute with the name, assignment string, value and quote given.PageAttribute(Page page, int name_start, int name_end, int value_start, int value_end, char quote)Create an attribute.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetAssignment()Get the assignment string of this attribute.voidgetAssignment(java.lang.StringBuffer buffer)Get the assignment string of this attribute.intgetLength()Get the length of the string value of this attribute.java.lang.StringgetName()Get the name of this attribute.voidgetName(java.lang.StringBuffer buffer)Get the name of this attribute.intgetNameEndPosition()Get the ending position of the attribute name.intgetNameStartPosition()Get the starting position of the attribute name.PagegetPage()Get the page this attribute is anchored to, if any.java.lang.StringgetRawValue()Get the raw value of the attribute.voidgetRawValue(java.lang.StringBuffer buffer)Get the raw value of the attribute.java.lang.StringgetValue()Get the value of the attribute.voidgetValue(java.lang.StringBuffer buffer)Get the value of the attribute.intgetValueEndPosition()Get the ending position of the attribute value.intgetValueStartPosition()Get the starting position of the attribute value.booleanisEmpty()Predicate to determine if this attribute has an equals sign but no value.booleanisStandAlone()Predicate to determine if this attribute has no equals sign (or value).booleanisValued()Predicate to determine if this attribute has a value.booleanisWhitespace()Predicate to determine if this attribute is whitespace.voidsetNameEndPosition(int end)Set the ending position of the attribute name.voidsetNameStartPosition(int start)Set the starting position of the attribute name.voidsetPage(Page page)Set the page this attribute is anchored to.voidsetValueEndPosition(int end)Set the ending position of the attribute value.voidsetValueStartPosition(int start)Set the starting position of the attribute value.-
Methods inherited from class org.htmlparser.Attribute
getQuote, getQuote, setAssignment, setName, setQuote, setRawValue, setValue, toString, toString
-
-
-
-
Field Detail
-
mPage
protected Page mPage
The page this attribute is extracted from.
-
mNameStart
protected int mNameStart
The starting offset of the name within the page. If negative, the name is considerednull.
-
mNameEnd
protected int mNameEnd
The ending offset of the name within the page.
-
mValueStart
protected int mValueStart
The starting offset of the value within the page. If negative, the value is considerednull.
-
mValueEnd
protected int mValueEnd
The ending offset of the name within the page.
-
-
Constructor Detail
-
PageAttribute
public PageAttribute(Page page, int name_start, int name_end, int value_start, int value_end, char quote)
Create an attribute.- Parameters:
page- The page containing the attribute.name_start- The starting offset of the name within the page. If this is negative, the name is considered null.name_end- The ending offset of the name within the page.value_start- he starting offset of the value within the page. If this is negative, the value is considered null.value_end- The ending offset of the value within the page.quote- The quote, if any, surrounding the value of the attribute, (i.e. ' or "), or zero if none.
-
PageAttribute
public PageAttribute(java.lang.String name, java.lang.String assignment, java.lang.String value, char quote)Create an attribute with the name, assignment string, value and quote given. If the quote value is zero, assigns the value usingAttribute.setRawValue(java.lang.String)which sets the quote character to a proper value if necessary.- Parameters:
name- The name of this attribute.assignment- The assignment string of this attribute.value- The value of this attribute.quote- The quote around the value of this attribute.
-
PageAttribute
public PageAttribute(java.lang.String name, java.lang.String value, char quote)Create an attribute with the name, value and quote given. Uses an equals sign as the assignment string if the value is notnull, and callsAttribute.setRawValue(java.lang.String)to get the correct quoting ifquoteis zero.- Parameters:
name- The name of this attribute.value- The value of this attribute.quote- The quote around the value of this attribute.
-
PageAttribute
public PageAttribute(java.lang.String value) throws java.lang.IllegalArgumentExceptionCreate a whitespace attribute with the value given.- Parameters:
value- The value of this attribute.- Throws:
java.lang.IllegalArgumentException- if the value contains other than whitespace. To set a real value usePageAttribute(String,String).
-
PageAttribute
public PageAttribute(java.lang.String name, java.lang.String value)Create an attribute with the name and value given. Uses an equals sign as the assignment string if the value is notnull, and callsAttribute.setRawValue(java.lang.String)to get the correct quoting.- Parameters:
name- The name of this attribute.value- The value of this attribute.
-
PageAttribute
public PageAttribute(java.lang.String name, java.lang.String assignment, java.lang.String value)Create an attribute with the name, assignment string and value given. CallsAttribute.setRawValue(java.lang.String)to get the correct quoting.- Parameters:
name- The name of this attribute.assignment- The assignment string of this attribute.value- The value of this attribute.
-
PageAttribute
public PageAttribute()
Create an empty attribute. This will provide "" from theAttribute.toString()andAttribute.toString(StringBuffer)methods.
-
-
Method Detail
-
getName
public java.lang.String getName()
Get the name of this attribute. The part before the equals sign, or the contents of the stand-alone attribute.- Overrides:
getNamein classAttribute- Returns:
- The name, or
nullif it's just a whitepace 'attribute'. - See Also:
Attribute.setName(java.lang.String)
-
getName
public void getName(java.lang.StringBuffer buffer)
Get the name of this attribute.
-
getAssignment
public java.lang.String getAssignment()
Get the assignment string of this attribute. This is usually just an equals sign, but in poorly formed attributes it can include whitespace on either or both sides of an equals sign.- Overrides:
getAssignmentin classAttribute- Returns:
- The assignment string.
- See Also:
Attribute.setAssignment(java.lang.String)
-
getAssignment
public void getAssignment(java.lang.StringBuffer buffer)
Get the assignment string of this attribute.- Overrides:
getAssignmentin classAttribute- Parameters:
buffer- The buffer to place the assignment string in.- See Also:
getAssignment()
-
getValue
public java.lang.String getValue()
Get the value of the attribute. The part after the equals sign, or the text if it's just a whitepace 'attribute'. NOTE: This does not include any quotes that may have enclosed the value when it was read. To get the un-stripped value usegetRawValue().- Overrides:
getValuein classAttribute- Returns:
- The value, or
nullif it's a stand-alone or empty attribute, or the text if it's just a whitepace 'attribute'. - See Also:
Attribute.setValue(java.lang.String)
-
getValue
public void getValue(java.lang.StringBuffer buffer)
Get the value of the attribute.- Overrides:
getValuein classAttribute- Parameters:
buffer- The buffer to place the value in.- See Also:
getValue()
-
getRawValue
public java.lang.String getRawValue()
Get the raw value of the attribute. The part after the equals sign, or the text if it's just a whitepace 'attribute'. This includes the quotes around the value if any.- Overrides:
getRawValuein classAttribute- Returns:
- The value, or
nullif it's a stand-alone attribute, or the text if it's just a whitepace 'attribute'. - See Also:
Attribute.setRawValue(java.lang.String)
-
getRawValue
public void getRawValue(java.lang.StringBuffer buffer)
Get the raw value of the attribute. The part after the equals sign, or the text if it's just a whitepace 'attribute'. This includes the quotes around the value if any.- Overrides:
getRawValuein classAttribute- Parameters:
buffer- The string buffer to append the attribute value to.- See Also:
getRawValue()
-
getPage
public Page getPage()
Get the page this attribute is anchored to, if any.- Returns:
- The page used to construct this attribute, or null if this is just a regular attribute.
-
setPage
public void setPage(Page page)
Set the page this attribute is anchored to.- Parameters:
page- The page to be used to construct this attribute. Note: If you set this you probably also want to uncache the property values by setting them to null.
-
getNameStartPosition
public int getNameStartPosition()
Get the starting position of the attribute name.- Returns:
- The offset into the page at which the name begins.
-
setNameStartPosition
public void setNameStartPosition(int start)
Set the starting position of the attribute name.- Parameters:
start- The new offset into the page at which the name begins.
-
getNameEndPosition
public int getNameEndPosition()
Get the ending position of the attribute name.- Returns:
- The offset into the page at which the name ends.
-
setNameEndPosition
public void setNameEndPosition(int end)
Set the ending position of the attribute name.- Parameters:
end- The new offset into the page at which the name ends.
-
getValueStartPosition
public int getValueStartPosition()
Get the starting position of the attribute value.- Returns:
- The offset into the page at which the value begins.
-
setValueStartPosition
public void setValueStartPosition(int start)
Set the starting position of the attribute value.- Parameters:
start- The new offset into the page at which the value begins.
-
getValueEndPosition
public int getValueEndPosition()
Get the ending position of the attribute value.- Returns:
- The offset into the page at which the value ends.
-
setValueEndPosition
public void setValueEndPosition(int end)
Set the ending position of the attribute value.- Parameters:
end- The new offset into the page at which the value ends.
-
isWhitespace
public boolean isWhitespace()
Predicate to determine if this attribute is whitespace.- Overrides:
isWhitespacein classAttribute- Returns:
trueif this attribute is whitespace,falseif it is a real attribute.
-
isStandAlone
public boolean isStandAlone()
Predicate to determine if this attribute has no equals sign (or value).- Overrides:
isStandAlonein classAttribute- Returns:
trueif this attribute is a standalone attribute.falseif has an equals sign.
-
isEmpty
public boolean isEmpty()
Predicate to determine if this attribute has an equals sign but no value.
-
isValued
public boolean isValued()
Predicate to determine if this attribute has a value.
-
-