KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlcleaner > TagNode


1 /* Copyright (c) 2006-2007, Vladimir Nikic
2     All rights reserved.
3     
4     Redistribution and use of this software in source and binary forms,
5     with or without modification, are permitted provided that the following
6     conditions are met:
7     
8     * Redistributions of source code must retain the above
9       copyright notice, this list of conditions and the
10       following disclaimer.
11     
12     * Redistributions in binary form must reproduce the above
13       copyright notice, this list of conditions and the
14       following disclaimer in the documentation and/or other
15       materials provided with the distribution.
16     
17     * The name of HtmlCleaner may not be used to endorse or promote
18       products derived from this software without specific prior
19       written permission.
20
21     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31     POSSIBILITY OF SUCH DAMAGE.
32     
33     You can contact Vladimir Nikic by sending e-mail to
34     nikic_vladimir@yahoo.com. Please include the word "HtmlCleaner" in the
35     subject line.
36 */

37
38 package org.htmlcleaner;
39
40 import java.io.IOException JavaDoc;
41 import java.util.*;
42
43 /**
44  * <p>XML node node tag - it is produced during cleaning process when all start and end
45  * tokens are removed and replaced by instances of TagNode.</p>
46  *
47  * Created by: Vladimir Nikic<br/>
48  * Date: November, 2006.
49  */

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 JavaDoc 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 JavaDoc attName, String JavaDoc attValue) {
79         if ( attName != null && !"".equals(attName.trim()) ) {
80             attributes.put( attName.toLowerCase(), attValue == null ? "" : attValue );
81         }
82     }
83     
84     public void addChild(Object JavaDoc 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 JavaDoc child = it.next();
97                 addChild(child);
98             }
99         }
100     }
101     
102     public void addItemForMoving(Object JavaDoc 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 JavaDoc {
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