Package dev.amp.validator
Class ParsedHtmlTag
- java.lang.Object
-
- dev.amp.validator.ParsedHtmlTag
-
public class ParsedHtmlTag extends Object
The AMP HTML ParsedHtmlTag class.- Author:
- nhant01, GeorgeLuo
-
-
Constructor Summary
Constructors Constructor Description ParsedHtmlTag(String tagName, Attributes attributes)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Attributesattrs()Returns an array of attributes.HashMap<String,String>attrsByKey()Returns an object mapping attribute name to attribute value.voidcleanup()Method to nullify object values.StringgetAmpScriptPath()Returns the script tag path of the 'src' attribute.StringgetExtensionName()Returns the extension name.StringgetExtensionVersion()Returns the extension version.ExtensionsUtils.ScriptReleaseVersiongetScriptReleaseVersion()Returns the script release version, otherwise ScriptReleaseVersion.UNKNOWN.StringgetValue(String attrName, int index)Need to replace the value with an empty string if attr name is equal to the value.StringhasDuplicateAttrs()Returns a duplicate attribute name if the tag contains two attributes named the same, but with different attribute values.booleanhasValidAmpScriptPath()Tests if this tag is a script with a valid AMP script path.booleanisAmpCacheDomain(String src)Tests if this is an AMP Cache domain.booleanisAmpDomain()Tests if this tag is a script with a src of an AMP domain.booleanisAmpRuntimeScript()Tests if this is the AMP runtime script tag.booleanisEmpty()Returns true if tag name length is zero.booleanisExtensionScript()Tests if this is an extension script tag.StringlowerName()Lower-case tag name.StringupperName()Upper-case tag name.
-
-
-
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
-
-