1 37 38 package org.htmlcleaner; 39 40 import java.io.IOException ; 41 import java.util.*; 42 43 50 public class TagNode extends TagToken { 51 52 private TagNode parent = null; 53 private Map attributes = new TreeMap(); 54 private List children = new ArrayList(); 55 private List itemsToMove = null; 56 57 private transient boolean isFormed = false; 58 59 public TagNode() { 60 } 61 62 public TagNode(String name) { 63 super(name.toLowerCase()); 64 } 65 66 public Map getAttributes() { 67 return attributes; 68 } 69 70 public List getChildren() { 71 return children; 72 } 73 74 public TagNode getParent() { 75 return parent; 76 } 77 78 public void addAttribute(String attName, String attValue) { 79 if ( attName != null && !"".equals(attName.trim()) ) { 80 attributes.put( attName.toLowerCase(), attValue == null ? "" : attValue ); 81 } 82 } 83 84 public void addChild(Object child) { 85 children.add(child); 86 if (child instanceof TagNode) { 87 TagNode childTagNode = (TagNode)child; 88 childTagNode.parent = this; 89 } 90 } 91 92 public void addChildren(List children) { 93 if (children != null) { 94 Iterator it = children.iterator(); 95 while (it.hasNext()) { 96 Object child = it.next(); 97 addChild(child); 98 } 99 } 100 } 101 102 public void addItemForMoving(Object item) { 103 if (itemsToMove == null) { 104 itemsToMove = new ArrayList(); 105 } 106 107 itemsToMove.add(item); 108 } 109 110 public List getItemsToMove() { 111 return itemsToMove; 112 } 113 114 public void setItemsToMove(List itemsToMove) { 115 this.itemsToMove = itemsToMove; 116 } 117 118 public boolean isFormed() { 119 return isFormed; 120 } 121 122 public void setFormed() { 123 this.isFormed = true; 124 } 125 126 public void serialize(XmlSerializer xmlSerializer) throws IOException { 127 xmlSerializer.serialize(this); 128 } 129 130 public TagNode makeCopy() { 131 TagNode copy = new TagNode(this.name); 132 copy.attributes = this.attributes; 133 134 return copy; 135 } 136 137 } | Popular Tags |