Question: Java public class TagElement extends java.lang.Object implements Element Represents an HTML tag element ( < , , etc.). Each tag has an id (ids start
Java public class TagElement extends java.lang.Object implements Element
Represents an HTML tag element (<
,
, etc.). Each tag has an id (ids start at 1). By default the start tag will have an id (e.g., <
) when the HTML for the tag is generated. This can be disabled by using enableId.
Author:
UMCP
Constructor Summary
| Constructor and Description |
|---|
| TagElement(java.lang.String tagName, boolean endTag, Element content, java.lang.String attributes) Initializes a tag element. |
Method Summary
| Modifier and Type | Method and Description |
|---|---|
| static void | enableId(boolean choice) Allow us to enable or disable the generation of ids for tags. |
| java.lang.String | genHTML(int indentation) Returns a string that represents the HTML associated with the element. |
| java.lang.String | getEndTag() |
| int | getId() |
| java.lang.String | getStartTag() Returns the start tag. |
| java.lang.String | getStringId() |
| static void | resetIds() Allow us to start assigning ids at 1 again. |
| void | setAttributes(java.lang.String attributes) Updates attributes field. |
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString,
----------------------------------------------------------------start here
Constructor Detail
TagElement
public TagElement(java.lang.String tagName, boolean endTag, Element content, java.lang.String attributes)
Initializes a tag element. We can have tag elements with only a start tag. Each time a new tag element is created it is assigned a unique id (starting at 1).
Parameters:
tagName -
endTag -
content -
attributes -
Method Detail
getId
public int getId()
Returns:
unique id
getStringId
public java.lang.String getStringId()
Returns:
tagname followed by the unique id
getStartTag
public java.lang.String getStartTag()
Returns the start tag. It will not include the id if inclusion has been disabled.
Returns:
string representing the start tag including attributes (if any).
getEndTag
public java.lang.String getEndTag()
Returns:
end tag or empty string (for tags with only start tag).
setAttributes
public void setAttributes(java.lang.String attributes)
Updates attributes field.
Parameters:
attributes -
resetIds
public static void resetIds()
Allow us to start assigning ids at 1 again.
enableId
public static void enableId(boolean choice)
Allow us to enable or disable the generation of ids for tags.
Parameters:
choice -
genHTML
public java.lang.String genHTML(int indentation)
{
Description copied from interface: Element
Returns a string that represents the HTML associated with the element. The string is indented based on the parameter value.
Specified by:
genHTML in interface Element
Returns:
HTML associated with the element.
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
