Class Attribute

  • All Implemented Interfaces:
    java.lang.Cloneable, java.util.Map.Entry<java.lang.String,​java.lang.String>
    Direct Known Subclasses:
    BooleanAttribute

    public class Attribute
    extends java.lang.Object
    implements java.util.Map.Entry<java.lang.String,​java.lang.String>, java.lang.Cloneable
    A single key + value attribute. (Only used for presentation.)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String[] booleanAttributes  
      private java.lang.String key  
      (package private) Attributes parent  
      private java.lang.String val  
    • 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.
    • Field Detail

      • booleanAttributes

        private static final java.lang.String[] booleanAttributes
      • key

        private java.lang.String key
      • val

        private java.lang.String val
    • Constructor Detail

      • Attribute

        public Attribute​(java.lang.String key,
                         java.lang.String value)
        Create a new attribute from unencoded (raw) key and value.
        Parameters:
        key - attribute key; case is preserved.
        value - attribute value
        See Also:
        createFromEncoded(java.lang.String, java.lang.String)
      • Attribute

        public Attribute​(java.lang.String key,
                         java.lang.String val,
                         Attributes parent)
        Create a new attribute from unencoded (raw) key and value.
        Parameters:
        key - attribute key; case is preserved.
        val - attribute value
        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:
        getKey in interface java.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.
        Specified by:
        getValue in interface java.util.Map.Entry<java.lang.String,​java.lang.String>
        Returns:
        the attribute value
      • setValue

        public java.lang.String setValue​(java.lang.String val)
        Set the attribute value.
        Specified by:
        setValue in interface java.util.Map.Entry<java.lang.String,​java.lang.String>
        Parameters:
        val - the new attribute value; must not be null
      • html

        public java.lang.String html()
        Get the HTML representation of this attribute; e.g. href="index.html".
        Returns:
        HTML
      • html

        protected static void html​(java.lang.String key,
                                   java.lang.String val,
                                   java.lang.Appendable accum,
                                   Document.OutputSettings out)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • html

        protected void html​(java.lang.Appendable accum,
                            Document.OutputSettings out)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Get the string representation of this attribute, implemented as html().
        Overrides:
        toString in class java.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,
                                                         java.lang.String val,
                                                         Document.OutputSettings out)
      • isBooleanAttribute

        protected boolean isBooleanAttribute()
        Deprecated.
      • isBooleanAttribute

        protected static boolean isBooleanAttribute​(java.lang.String key)
        Checks if this attribute name is defined as a boolean attribute in HTML5
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Map.Entry<java.lang.String,​java.lang.String>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map.Entry<java.lang.String,​java.lang.String>
        Overrides:
        hashCode in class java.lang.Object
      • clone

        public Attribute clone()
        Overrides:
        clone in class java.lang.Object