KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dom4j > samples > VisitorDemo


1 /*
2  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
3  *
4  * This software is open source.
5  * See the bottom of this file for the licence.
6  *
7  * $Id: VisitorDemo.java,v 1.4 2005/01/29 14:52:57 maartenc Exp $
8  */

9
10 package org.dom4j.samples;
11
12 import org.dom4j.Attribute;
13 import org.dom4j.CDATA;
14 import org.dom4j.Comment;
15 import org.dom4j.Document;
16 import org.dom4j.DocumentType;
17 import org.dom4j.Element;
18 import org.dom4j.Entity;
19 import org.dom4j.Namespace;
20 import org.dom4j.ProcessingInstruction;
21 import org.dom4j.Text;
22 import org.dom4j.Visitor;
23 import org.dom4j.VisitorSupport;
24
25 /**
26  * A sample program to demonstrate the use of the Visitor Pattern in DOM4J
27  *
28  * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan </a>
29  * @version $Revision: 1.4 $
30  */

31 public class VisitorDemo extends SAXDemo {
32
33     public static void main(String JavaDoc[] args) {
34         run(new VisitorDemo(), args);
35     }
36
37     public VisitorDemo() {
38     }
39
40     protected void process(Document document) throws Exception JavaDoc {
41         Visitor visitor = new VisitorSupport() {
42
43             public void visit(Document document) {
44                 println(document.toString());
45             }
46
47             public void visit(DocumentType documentType) {
48                 println(documentType.toString());
49             }
50
51             public void visit(Element node) {
52                 println(node.toString());
53             }
54
55             public void visit(Attribute node) {
56                 println(node.toString());
57             }
58
59             public void visit(CDATA node) {
60                 println(node.toString());
61             }
62
63             public void visit(Comment node) {
64                 println(node.toString());
65             }
66
67             public void visit(Entity node) {
68                 println(node.toString());
69             }
70
71             public void visit(Namespace node) {
72                 println(node.toString());
73             }
74
75             public void visit(ProcessingInstruction node) {
76                 println(node.toString());
77             }
78
79             public void visit(Text node) {
80                 println(node.toString());
81             }
82         };
83
84         document.accept(visitor);
85     }
86 }
87
88 /*
89  * Redistribution and use of this software and associated documentation
90  * ("Software"), with or without modification, are permitted provided that the
91  * following conditions are met:
92  *
93  * 1. Redistributions of source code must retain copyright statements and
94  * notices. Redistributions must also contain a copy of this document.
95  *
96  * 2. Redistributions in binary form must reproduce the above copyright notice,
97  * this list of conditions and the following disclaimer in the documentation
98  * and/or other materials provided with the distribution.
99  *
100  * 3. The name "DOM4J" must not be used to endorse or promote products derived
101  * from this Software without prior written permission of MetaStuff, Ltd. For
102  * written permission, please contact dom4j-info@metastuff.com.
103  *
104  * 4. Products derived from this Software may not be called "DOM4J" nor may
105  * "DOM4J" appear in their names without prior written permission of MetaStuff,
106  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
107  *
108  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
109  *
110  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
111  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
112  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
113  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
114  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
115  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
116  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
117  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
118  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
119  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
120  * POSSIBILITY OF SUCH DAMAGE.
121  *
122  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
123  *
124  * $Id: VisitorDemo.java,v 1.4 2005/01/29 14:52:57 maartenc Exp $
125  */

126
Popular Tags