KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dom4j > tree > AbstractEntity


1 /*
2  * Copyright 2001-2005 (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
8 package org.dom4j.tree;
9
10 import java.io.IOException JavaDoc;
11 import java.io.Writer JavaDoc;
12
13 import org.dom4j.Element;
14 import org.dom4j.Entity;
15 import org.dom4j.Visitor;
16
17 /**
18  * <p>
19  * <code>AbstractEntity</code> is an abstract base class for tree implementors
20  * to use for implementation inheritence.
21  * </p>
22  *
23  * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan </a>
24  * @version $Revision: 1.15 $
25  */

26 public abstract class AbstractEntity extends AbstractNode implements Entity {
27     public AbstractEntity() {
28     }
29
30     public short getNodeType() {
31         return ENTITY_REFERENCE_NODE;
32     }
33
34     public String JavaDoc getPath(Element context) {
35         // From XPaths perspective, entities are included in text
36
Element parent = getParent();
37
38         return ((parent != null) && (parent != context)) ? (parent
39                 .getPath(context) + "/text()") : "text()";
40     }
41
42     public String JavaDoc getUniquePath(Element context) {
43         // From XPaths perspective, entities are included in text
44
Element parent = getParent();
45
46         return ((parent != null) && (parent != context)) ? (parent
47                 .getUniquePath(context) + "/text()") : "text()";
48     }
49
50     public String JavaDoc toString() {
51         return super.toString() + " [Entity: &" + getName() + ";]";
52     }
53
54     public String JavaDoc getStringValue() {
55         return "&" + getName() + ";";
56     }
57
58     public String JavaDoc asXML() {
59         return "&" + getName() + ";";
60     }
61
62     public void write(Writer JavaDoc writer) throws IOException JavaDoc {
63         writer.write("&");
64         writer.write(getName());
65         writer.write(";");
66     }
67
68     public void accept(Visitor visitor) {
69         visitor.visit(this);
70     }
71 }
72
73 /*
74  * Redistribution and use of this software and associated documentation
75  * ("Software"), with or without modification, are permitted provided that the
76  * following conditions are met:
77  *
78  * 1. Redistributions of source code must retain copyright statements and
79  * notices. Redistributions must also contain a copy of this document.
80  *
81  * 2. Redistributions in binary form must reproduce the above copyright notice,
82  * this list of conditions and the following disclaimer in the documentation
83  * and/or other materials provided with the distribution.
84  *
85  * 3. The name "DOM4J" must not be used to endorse or promote products derived
86  * from this Software without prior written permission of MetaStuff, Ltd. For
87  * written permission, please contact dom4j-info@metastuff.com.
88  *
89  * 4. Products derived from this Software may not be called "DOM4J" nor may
90  * "DOM4J" appear in their names without prior written permission of MetaStuff,
91  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
92  *
93  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
94  *
95  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
96  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
97  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
98  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
99  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
100  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
101  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
102  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
103  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
104  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
105  * POSSIBILITY OF SUCH DAMAGE.
106  *
107  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
108  */

109
Popular Tags