1 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 ; 17 import java.io.Writer ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 21 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 getName() { 37 return getElementName(); 38 } 39 40 public void setName(String name) { 41 setElementName(name); 42 } 43 44 public String getPath(Element context) { 45 return ""; 47 } 48 49 public String getUniquePath(Element context) { 50 return ""; 52 } 53 54 55 public String getText() { 56 List list = getInternalDeclarations(); 57 if (list != null && list.size() > 0) { 58 StringBuffer buffer = new StringBuffer (); 59 Iterator iter = list.iterator(); 60 if (iter.hasNext()) { 61 Object 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 toString() { 75 return super.toString() + " [DocumentType: " + asXML() + "]"; 76 } 77 78 public String asXML() { 79 StringBuffer buffer = new StringBuffer ("<!DOCTYPE "); 80 buffer.append(getElementName()); 81 82 boolean hasPublicID = false; 83 String 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 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 writer) throws IOException { 106 writer.write("<!DOCTYPE "); 107 writer.write(getElementName()); 108 109 boolean hasPublicID = false; 110 String 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 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 list = getInternalDeclarations(); 129 if (list != null && list.size() > 0) { 130 writer.write(" ["); 131 for (Iterator iter = list.iterator(); iter.hasNext();) { 132 Object 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 191 | Popular Tags |