KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > dom4j > o3impl > AbstractDocumentType


1 /*
2  * Copyright 2001 (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: AbstractDocumentType.java,v 1.2 2003/06/10 16:18:35 per_nyfelt Exp $
8  */

9
10 package org.ozoneDB.xml.dom4j.o3impl;
11
12 import org.dom4j.DocumentType;
13 import org.dom4j.Element;
14 import org.dom4j.Visitor;
15
16 import java.io.IOException JavaDoc;
17 import java.io.Writer JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20
21 /** <p><code>AbstractDocumentType</code> is an abstract base class for
22  * tree implementors to use for implementation inheritence.</p>
23  *
24  * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
25  * @version $Revision: 1.2 $
26  */

27 public abstract class AbstractDocumentType extends AbstractNode implements DocumentType {
28
29     public AbstractDocumentType() {
30     }
31
32     public short getNodeType() {
33         return DOCUMENT_TYPE_NODE;
34     }
35
36     public String JavaDoc getName() {
37         return getElementName();
38     }
39
40     public void setName(String JavaDoc name) {
41         setElementName(name);
42     }
43
44     public String JavaDoc getPath(Element context) {
45         // not available in XPath
46
return "";
47     }
48
49     public String JavaDoc getUniquePath(Element context) {
50         // not available in XPath
51
return "";
52     }
53
54     /** Returns the text format of the declarations if applicable, or the empty String */
55     public String JavaDoc getText() {
56         List JavaDoc list = getInternalDeclarations();
57         if (list != null && list.size() > 0) {
58             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
59             Iterator JavaDoc iter = list.iterator();
60             if (iter.hasNext()) {
61                 Object JavaDoc decl = iter.next();
62                 buffer.append(decl.toString());
63                 while (iter.hasNext()) {
64                     decl = iter.next();
65                     buffer.append("\n");
66                     buffer.append(decl.toString());
67                 }
68             }
69             return buffer.toString();
70         }
71         return "";
72     }
73
74     public String JavaDoc toString() {
75         return super.toString() + " [DocumentType: " + asXML() + "]";
76     }
77
78     public String JavaDoc asXML() {
79         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("<!DOCTYPE ");
80         buffer.append(getElementName());
81
82         boolean hasPublicID = false;
83         String JavaDoc publicID = getPublicID();
84
85         if (publicID != null && publicID.length() > 0) {
86             buffer.append(" PUBLIC \"");
87             buffer.append(publicID);
88             buffer.append("\"");
89             hasPublicID = true;
90         }
91
92         String JavaDoc systemID = getSystemID();
93         if (systemID != null && systemID.length() > 0) {
94             if (!hasPublicID) {
95                 buffer.append(" SYSTEM");
96             }
97             buffer.append(" \"");
98             buffer.append(systemID);
99             buffer.append("\"");
100         }
101         buffer.append(">");
102         return buffer.toString();
103     }
104
105     public void write(Writer JavaDoc writer) throws IOException JavaDoc {
106         writer.write("<!DOCTYPE ");
107         writer.write(getElementName());
108
109         boolean hasPublicID = false;
110         String JavaDoc publicID = getPublicID();
111
112         if (publicID != null && publicID.length() > 0) {
113             writer.write(" PUBLIC \"");
114             writer.write(publicID);
115             writer.write("\"");
116             hasPublicID = true;
117         }
118
119         String JavaDoc systemID = getSystemID();
120         if (systemID != null && systemID.length() > 0) {
121             if (!hasPublicID) {
122                 writer.write(" SYSTEM");
123             }
124             writer.write(" \"");
125             writer.write(systemID);
126             writer.write("\"");
127         }
128         List JavaDoc list = getInternalDeclarations();
129         if (list != null && list.size() > 0) {
130             writer.write(" [");
131             for (Iterator JavaDoc iter = list.iterator(); iter.hasNext();) {
132                 Object JavaDoc decl = iter.next();
133                 writer.write("\n ");
134                 writer.write(decl.toString());
135             }
136             writer.write("\n]");
137         }
138         writer.write(">");
139     }
140
141     public void accept(Visitor visitor) {
142         visitor.visit(this);
143     }
144 }
145
146
147 /*
148  * Redistribution and use of this software and associated documentation
149  * ("Software"), with or without modification, are permitted provided
150  * that the following conditions are met:
151  *
152  * 1. Redistributions of source code must retain copyright
153  * statements and notices. Redistributions must also contain a
154  * copy of this document.
155  *
156  * 2. Redistributions in binary form must reproduce the
157  * above copyright notice, this list of conditions and the
158  * following disclaimer in the documentation and/or other
159  * materials provided with the distribution.
160  *
161  * 3. The name "DOM4J" must not be used to endorse or promote
162  * products derived from this Software without prior written
163  * permission of MetaStuff, Ltd. For written permission,
164  * please contact dom4j-info@metastuff.com.
165  *
166  * 4. Products derived from this Software may not be called "DOM4J"
167  * nor may "DOM4J" appear in their names without prior written
168  * permission of MetaStuff, Ltd. DOM4J is a registered
169  * trademark of MetaStuff, Ltd.
170  *
171  * 5. Due credit should be given to the DOM4J Project
172  * (http://dom4j.org/).
173  *
174  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
175  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
176  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
177  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
178  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
179  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
180  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
181  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
182  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
183  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
184  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
185  * OF THE POSSIBILITY OF SUCH DAMAGE.
186  *
187  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
188  *
189  * $Id: AbstractDocumentType.java,v 1.2 2003/06/10 16:18:35 per_nyfelt Exp $
190  */

191
Popular Tags