1 23 24 package org.enhydra.xml.xmlc.dom; 25 26 import java.util.HashMap ; 27 28 import org.enhydra.xml.xmlc.XMLCError; 29 import org.w3c.dom.DocumentType ; 30 31 43 public class DocTypeBuilder { 44 47 private XMLCDomFactory domFactory; 48 49 52 private DocumentType docType; 53 54 57 private String docTypeName; private String docSystemId; 59 private String docPublicId; 60 61 64 private String internalSubsetStr; 65 66 71 private boolean createdDocType = false; 72 73 76 private HashMap elementIdAttrs = new HashMap (); 77 78 83 public DocTypeBuilder(XMLCDomFactory domFactory) { 84 this.domFactory = domFactory; 85 } 86 87 93 public DocumentType getCreateDocType() { 94 if ((docType == null) && (docTypeName != null)) { 95 docType = domFactory.createDocumentType(docTypeName, docPublicId, 96 docSystemId, internalSubsetStr); 97 } 98 createdDocType = true; 100 return docType; 101 } 102 103 107 private void checkIfAlreadyCreated() { 108 if (createdDocType) { 109 throw new XMLCError("XMLC bug: attempt to add document type data after DocumentType object has been created"); 110 } 111 } 112 113 118 public void setDocumentTypeName(String name) { 119 checkIfAlreadyCreated(); 120 docTypeName = name; 121 } 122 123 126 public String getDocumentTypeName() { 127 return docTypeName; 128 } 129 130 135 public void setPublicId(String publicId) { 136 checkIfAlreadyCreated(); 137 docPublicId = publicId; 138 } 139 140 143 public String getPublicId() { 144 return docPublicId; 145 } 146 147 152 public void setSystemId(String systemId) { 153 checkIfAlreadyCreated(); 154 docSystemId = systemId; 155 } 156 157 160 public String getSystemId() { 161 return docSystemId; 162 } 163 164 172 public void addIdAttribute(String elementName, 173 String attributeName, 174 boolean internalSubset) { 175 checkIfAlreadyCreated(); 176 177 boolean exists = elementIdAttrs.containsKey(elementName); 178 if ((!exists) || (exists && internalSubset)) { 179 elementIdAttrs.put(elementName, attributeName); 180 } 181 } 182 183 190 public String getIdAttribute(String elementName) { 191 return (String )elementIdAttrs.get(elementName); 192 } 193 194 201 public void addEntityReference(String name, 202 boolean internalSubset) { 203 checkIfAlreadyCreated(); 204 } 205 206 214 public void addElementDecl(String name, 215 String contentSpec, 216 boolean internalSubset) { 217 checkIfAlreadyCreated(); 218 } 219 220 234 public void addAttributeDecl(String elementName, 235 String attrName, 236 String attrType, 237 String attrEnum, 238 String defaultDecl, 239 boolean internalSubset) { 240 checkIfAlreadyCreated(); 241 } 242 243 252 public void addInternalEntityDecl(String name, 253 String entityValue, 254 boolean paramEntity, 255 boolean internalSubset) { 256 checkIfAlreadyCreated(); 257 } 258 259 269 public void addExternalEntityDecl(String name, 270 String systemId, 271 String publicId, 272 boolean paramEntity, 273 boolean internalSubset) { 274 checkIfAlreadyCreated(); 275 } 276 277 285 public void addUnparsedEntityDecl(String name, 286 String notationName, 287 boolean internalSubset) { 288 checkIfAlreadyCreated(); 289 } 290 291 300 public void addNotationDecl(String name, 301 String systemId, 302 String publicId, 303 boolean internalSubset) { 304 checkIfAlreadyCreated(); 305 } 306 307 310 public void setInternalSubset(String subsetStr) { 311 checkIfAlreadyCreated(); 312 internalSubsetStr = subsetStr; 313 } 314 315 318 public String getInternalSubset() { 319 return internalSubsetStr; 320 } 321 } 322 | Popular Tags |