Class ParsedHtmlTag


  • public class ParsedHtmlTag
    extends Object
    The AMP HTML ParsedHtmlTag class.
    Author:
    nhant01, GeorgeLuo
    • Constructor Detail

      • ParsedHtmlTag

        public ParsedHtmlTag​(@Nonnull
                             String tagName,
                             @Nonnull
                             Attributes attributes)
        Constructor.
        Parameters:
        tagName - the name of the underlying tag in html document.
        attributes - the attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
    • Method Detail

      • lowerName

        public String lowerName()
        Lower-case tag name.
        Returns:
        returns a lower case tag name.
      • attrs

        public Attributes attrs()
        Returns an array of attributes. Each attribute has two fields: name and value. Name is always lower-case, value is the case from the original document. Values are unescaped.
        Returns:
        returns the attributes.
      • attrsByKey

        public HashMap<String,​String> attrsByKey()
        Returns an object mapping attribute name to attribute value. This is populated lazily, as it's not used for most tags.
        Returns:
        a HashMap of attribute name to attribute value
      • hasDuplicateAttrs

        public String hasDuplicateAttrs()
        Returns a duplicate attribute name if the tag contains two attributes named the same, but with different attribute values. Same attribute name AND value is OK. Returns null if there are no such duplicate attributes.
        Returns:
        returns a duplicate attribute name if the tag contains two attributes named the same.
      • getValue

        public String getValue​(@Nonnull
                               String attrName,
                               int index)
        Need to replace the value with an empty string if attr name is equal to the value.
        Parameters:
        attrName - attr name.
        index - index to the Attributes.
        Returns:
        returns the value.
      • isExtensionScript

        public boolean isExtensionScript()
        Tests if this is an extension script tag.
        Returns:
        if is extension script
      • isAmpCacheDomain

        public boolean isAmpCacheDomain​(@Nonnull
                                        String src)
        Tests if this is an AMP Cache domain.
        Parameters:
        src - the source to check
        Returns:
        true iff is an amp cache domain
      • isAmpDomain

        public boolean isAmpDomain()
        Tests if this tag is a script with a src of an AMP domain.
        Returns:
        {boolean}
      • isAmpRuntimeScript

        public boolean isAmpRuntimeScript()
        Tests if this is the AMP runtime script tag.
        Returns:
        true iff is AMP runtime script tag
      • cleanup

        public void cleanup()
        Method to nullify object values.
      • upperName

        public String upperName()
        Upper-case tag name.
        Returns:
        an upper case tag name.
      • isEmpty

        public boolean isEmpty()
        Returns true if tag name length is zero.
        Returns:
        true if tag name length is zero.
      • getExtensionName

        public String getExtensionName()
        Returns the extension name.
        Returns:
        the extension name
      • getExtensionVersion

        public String getExtensionVersion()
        Returns the extension version.
        Returns:
        the extension version
      • hasValidAmpScriptPath

        public boolean hasValidAmpScriptPath()
        Tests if this tag is a script with a valid AMP script path.
        Returns:
        true iff this tag is a script with a valid AMP script path.
      • getAmpScriptPath

        public String getAmpScriptPath()
        Returns the script tag path of the 'src' attribute.
        Returns:
        the script tag path of the 'src' attribute.
      • getScriptReleaseVersion

        public ExtensionsUtils.ScriptReleaseVersion getScriptReleaseVersion()
        Returns the script release version, otherwise ScriptReleaseVersion.UNKNOWN.
        Returns:
        the script release version