Package org.jsoup.nodes
Class Attribute
- java.lang.Object
-
- org.jsoup.nodes.Attribute
-
- All Implemented Interfaces:
java.lang.Cloneable,java.util.Map.Entry<java.lang.String,java.lang.String>
public class Attribute extends java.lang.Object implements java.util.Map.Entry<java.lang.String,java.lang.String>, java.lang.CloneableA single key + value attribute. (Only used for presentation.)
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String[]booleanAttributesprivate static java.util.regex.PatternhtmlKeyReplaceprivate static java.util.regex.PatternhtmlKeyValidprivate java.lang.Stringkey(package private) Attributesparentprivate java.lang.Stringvalprivate static java.util.regex.PatternxmlKeyReplaceprivate static java.util.regex.PatternxmlKeyValid
-
Constructor Summary
Constructors Constructor Description Attribute(java.lang.String key, java.lang.String value)Create a new attribute from unencoded (raw) key and value.Attribute(java.lang.String key, java.lang.String val, Attributes parent)Create a new attribute from unencoded (raw) key and value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Attributeclone()static AttributecreateFromEncoded(java.lang.String unencodedKey, java.lang.String encodedValue)Create a new Attribute from an unencoded key and a HTML attribute encoded value.booleanequals(java.lang.Object o)java.lang.StringgetKey()Get the attribute key.static java.lang.StringgetValidKey(java.lang.String key, Document.OutputSettings.Syntax syntax)java.lang.StringgetValue()Get the attribute value.booleanhasDeclaredValue()Check if this Attribute has a value.inthashCode()java.lang.Stringhtml()Get the HTML representation of this attribute; e.g.protected voidhtml(java.lang.Appendable accum, Document.OutputSettings out)protected static voidhtml(java.lang.String key, java.lang.String val, java.lang.Appendable accum, Document.OutputSettings out)(package private) static voidhtmlNoValidate(java.lang.String key, java.lang.String val, java.lang.Appendable accum, Document.OutputSettings out)static booleanisBooleanAttribute(java.lang.String key)Checks if this attribute name is defined as a boolean attribute in HTML5protected booleanisDataAttribute()protected static booleanisDataAttribute(java.lang.String key)voidsetKey(java.lang.String key)Set the attribute key; case is preserved.java.lang.StringsetValue(java.lang.String val)Set the attribute value.protected static booleanshouldCollapseAttribute(java.lang.String key, java.lang.String val, Document.OutputSettings out)protected booleanshouldCollapseAttribute(Document.OutputSettings out)Collapsible if it's a boolean attribute and value is empty or same as namejava.lang.StringtoString()Get the string representation of this attribute, implemented ashtml().
-
-
-
Field Detail
-
booleanAttributes
private static final java.lang.String[] booleanAttributes
-
key
private java.lang.String key
-
val
@Nullable private java.lang.String val
-
parent
@Nullable Attributes parent
-
xmlKeyValid
private static final java.util.regex.Pattern xmlKeyValid
-
xmlKeyReplace
private static final java.util.regex.Pattern xmlKeyReplace
-
htmlKeyValid
private static final java.util.regex.Pattern htmlKeyValid
-
htmlKeyReplace
private static final java.util.regex.Pattern htmlKeyReplace
-
-
Constructor Detail
-
Attribute
public Attribute(java.lang.String key, @Nullable java.lang.String value)Create a new attribute from unencoded (raw) key and value.- Parameters:
key- attribute key; case is preserved.value- attribute value (may be null)- See Also:
createFromEncoded(java.lang.String, java.lang.String)
-
Attribute
public Attribute(java.lang.String key, @Nullable java.lang.String val, @Nullable Attributes parent)Create a new attribute from unencoded (raw) key and value.- Parameters:
key- attribute key; case is preserved.val- attribute value (may be null)parent- the containing Attributes (this Attribute is not automatically added to said Attributes)- See Also:
createFromEncoded(java.lang.String, java.lang.String)
-
-
Method Detail
-
getKey
public java.lang.String getKey()
Get the attribute key.- Specified by:
getKeyin interfacejava.util.Map.Entry<java.lang.String,java.lang.String>- Returns:
- the attribute key
-
setKey
public void setKey(java.lang.String key)
Set the attribute key; case is preserved.- Parameters:
key- the new key; must not be null
-
getValue
public java.lang.String getValue()
Get the attribute value. Will return an empty string if the value is not set.- Specified by:
getValuein interfacejava.util.Map.Entry<java.lang.String,java.lang.String>- Returns:
- the attribute value
-
hasDeclaredValue
public boolean hasDeclaredValue()
Check if this Attribute has a value. Set boolean attributes have no value.- Returns:
- if this is a boolean attribute / attribute without a value
-
setValue
public java.lang.String setValue(@Nullable java.lang.String val)Set the attribute value.- Specified by:
setValuein interfacejava.util.Map.Entry<java.lang.String,java.lang.String>- Parameters:
val- the new attribute value; may be null (to set an enabled boolean attribute)- Returns:
- the previous value (if was null; an empty string)
-
html
public java.lang.String html()
Get the HTML representation of this attribute; e.g.href="index.html".- Returns:
- HTML
-
html
protected void html(java.lang.Appendable accum, Document.OutputSettings out) throws java.io.IOException- Throws:
java.io.IOException
-
html
protected static void html(java.lang.String key, @Nullable java.lang.String val, java.lang.Appendable accum, Document.OutputSettings out) throws java.io.IOException- Throws:
java.io.IOException
-
htmlNoValidate
static void htmlNoValidate(java.lang.String key, @Nullable java.lang.String val, java.lang.Appendable accum, Document.OutputSettings out) throws java.io.IOException- Throws:
java.io.IOException
-
getValidKey
@Nullable public static java.lang.String getValidKey(java.lang.String key, Document.OutputSettings.Syntax syntax)
-
toString
public java.lang.String toString()
Get the string representation of this attribute, implemented ashtml().- Overrides:
toStringin classjava.lang.Object- Returns:
- string
-
createFromEncoded
public static Attribute createFromEncoded(java.lang.String unencodedKey, java.lang.String encodedValue)
Create a new Attribute from an unencoded key and a HTML attribute encoded value.- Parameters:
unencodedKey- assumes the key is not encoded, as can be only run of simple \w chars.encodedValue- HTML attribute encoded value- Returns:
- attribute
-
isDataAttribute
protected boolean isDataAttribute()
-
isDataAttribute
protected static boolean isDataAttribute(java.lang.String key)
-
shouldCollapseAttribute
protected final boolean shouldCollapseAttribute(Document.OutputSettings out)
Collapsible if it's a boolean attribute and value is empty or same as name- Parameters:
out- output settings- Returns:
- Returns whether collapsible or not
-
shouldCollapseAttribute
protected static boolean shouldCollapseAttribute(java.lang.String key, @Nullable java.lang.String val, Document.OutputSettings out)
-
isBooleanAttribute
public static boolean isBooleanAttribute(java.lang.String key)
Checks if this attribute name is defined as a boolean attribute in HTML5
-
equals
public boolean equals(@Nullable java.lang.Object o)- Specified by:
equalsin interfacejava.util.Map.Entry<java.lang.String,java.lang.String>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Map.Entry<java.lang.String,java.lang.String>- Overrides:
hashCodein classjava.lang.Object
-
clone
public Attribute clone()
- Overrides:
clonein classjava.lang.Object
-
-