package Commons.page; import java.util.ArrayList; import Java.util.HashMap; import java.util.List; import Java.util.Map; import Java.util.Set; import java.util.Map.Entry; Public class HtmlElement { Private String TagName; Private map<string, string> attributes = new hashmap<string, string> (); Private listNew arraylist Private String value = ""; Private String text = ""; Public HtmlElement (String tagName) { this. tagName = TagName; } Public void SetValue (String value) { this. Value = value; } Public List return children; } Public void AddChild (htmlelement Element) { this. Children.add (element); } Public void AddAttribute (string name, String value) { this. Attributes.put (name, value); } Public String Getattributevalue (string name) { return this. Attributes.get (name); } @Override Public String toString () { return this. toHtml (); } Public String toHtml () { StringBuffer sb = new stringbuffer (); Sb.append ("<"); Sb.append (this. tagName); Sb.append (this. getAttr ()); Sb.append (">"); Sb.append (this. value); for (HtmlElement e: this. Children) { Sb.append (e.tohtml ()); } Sb.append (this. text); Sb.append ("</"); Sb.append (this. tagName); Sb.append (">"); return sb.tostring (); } protected String getAttr () { StringBuffer sb = new stringbuffer (); set<entry<string, string>> attr = this. Attributes.entryset (); for (entry<string, string> entry:attr) { Sb.append (""); Sb.append (Entry.getkey ()); Sb.append ("=/"); Sb.append (Entry.getvalue ()); & |