1 package org.jdom; 2 3 import java.util.*; 4 5 12 public class UncheckedJDOMFactory implements JDOMFactory { 13 14 18 public Element element(String name, Namespace namespace) { 19 Element e = new Element(); 20 e.name = name; 21 if (namespace == null) { 22 namespace = Namespace.NO_NAMESPACE; 23 } 24 e.namespace = namespace; 25 return e; 26 } 27 28 public Element element(String name) { 29 Element e = new Element(); 30 e.name = name; 31 e.namespace = Namespace.NO_NAMESPACE; 32 return e; 33 } 34 35 public Element element(String name, String uri) { 36 return element(name, Namespace.getNamespace("", uri)); 37 } 38 39 public Element element(String name, String prefix, String uri) { 40 return element(name, Namespace.getNamespace(prefix, uri)); 41 } 42 43 47 public Attribute attribute(String name, String value, Namespace namespace) { 48 Attribute a = new Attribute(); 49 a.name = name; 50 a.value = value; 51 if (namespace == null) { 52 namespace = Namespace.NO_NAMESPACE; 53 } 54 a.namespace = namespace; 55 return a; 56 } 57 58 public Attribute attribute(String name, String value, int type, Namespace namespace) { 59 Attribute a = new Attribute(); 60 a.name = name; 61 a.type = type; 62 a.value = value; 63 if (namespace == null) { 64 namespace = Namespace.NO_NAMESPACE; 65 } 66 a.namespace = namespace; 67 return a; 68 } 69 70 public Attribute attribute(String name, String value) { 71 Attribute a = new Attribute(); 72 a.name = name; 73 a.value = value; 74 a.namespace = Namespace.NO_NAMESPACE; 75 return a; 76 } 77 78 public Attribute attribute(String name, String value, int type) { 79 Attribute a = new Attribute(); 80 a.name = name; 81 a.type = type; 82 a.value = value; 83 a.namespace = Namespace.NO_NAMESPACE; 84 return a; 85 } 86 87 91 public Text text(String str) { 92 Text t = new Text(); 93 t.value = str; 94 return t; 95 } 96 97 101 public CDATA cdata(String str) { 102 CDATA c = new CDATA(); 103 c.value = str; 104 return c; 105 } 106 107 111 public Comment comment(String str) { 112 Comment c = new Comment(); 113 c.text = str; 114 return c; 115 } 116 117 121 public ProcessingInstruction processingInstruction(String target, Map data) { 122 ProcessingInstruction p = new ProcessingInstruction(); 123 p.target = target; 124 p.setData(data); 125 return p; 126 } 127 128 public ProcessingInstruction processingInstruction(String target, String data) { 129 ProcessingInstruction p = new ProcessingInstruction(); 130 p.target = target; 131 p.setData(data); 132 return p; 133 } 134 135 139 public EntityRef entityRef(String name) { 140 EntityRef e = new org.jdom.EntityRef(); 141 e.name = name; 142 return e; 143 } 144 145 public EntityRef entityRef(String name, String systemID) { 146 EntityRef e = new EntityRef(); 147 e.name = name; 148 e.systemID = systemID; 149 return e; 150 } 151 152 public EntityRef entityRef(String name, String publicID, String systemID) { 153 EntityRef e = new EntityRef(); 154 e.name = name; 155 e.publicID = publicID; 156 e.systemID = systemID; 157 return e; 158 } 159 160 164 public DocType docType(String elementName, String publicID, String systemID) { 165 DocType d = new DocType(); 166 d.elementName = elementName; 167 d.publicID = publicID; 168 d.systemID = systemID; 169 return d; 170 } 171 172 public DocType docType(String elementName, String systemID) { 173 return docType(elementName, null, systemID); 174 } 175 176 public DocType docType(String elementName) { 177 return docType(elementName, null, null); 178 } 179 180 184 public Document document(Element rootElement, DocType docType, String baseURI) { 185 Document d = new Document(); 186 if (docType != null) { 187 addContent(d, docType); 188 } 189 if (rootElement != null) { 190 addContent(d, rootElement); 191 } 192 if (baseURI != null) { 193 d.baseURI = baseURI; 194 } 195 return d; 196 } 197 198 public Document document(Element rootElement, DocType docType) { 199 return document(rootElement, docType, null); 200 } 201 202 public Document document(Element rootElement) { 203 return document(rootElement, null, null); 204 } 205 206 210 public void addContent(Parent parent, Content child) { 211 if (parent instanceof Element) { 212 Element elt = (Element) parent; 213 elt.content.uncheckedAddContent(child); 214 } 215 else { 216 Document doc = (Document) parent; 217 doc.content.uncheckedAddContent(child); 218 } 219 } 220 221 public void setAttribute(Element parent, Attribute a) { 222 parent.attributes.uncheckedAddAttribute(a); 223 } 224 225 public void addNamespaceDeclaration(Element parent, Namespace additional) { 226 if (parent.additionalNamespaces == null) { 227 parent.additionalNamespaces = new ArrayList(5); } 229 parent.additionalNamespaces.add(additional); 230 } 231 } 232 | Popular Tags |