X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Fnext%2FDomUtil.java;fp=src%2Fdolda%2Fjsvc%2Fnext%2FDomUtil.java;h=bedb99251dfe234d77af26f0c9e300eff786c386;hb=816cbb00faa568491d867a28b9570f8018e088b1;hp=0000000000000000000000000000000000000000;hpb=bce78e9e695e185501a05474b4862fe30a45863f;p=jsvc.git diff --git a/src/dolda/jsvc/next/DomUtil.java b/src/dolda/jsvc/next/DomUtil.java new file mode 100644 index 0000000..bedb992 --- /dev/null +++ b/src/dolda/jsvc/next/DomUtil.java @@ -0,0 +1,54 @@ +package dolda.jsvc.next; + +import org.w3c.dom.*; +import org.w3c.dom.bootstrap.*; + +public class DomUtil { + private static final DOMImplementation domimp; + + static { + DOMImplementationRegistry reg; + try { + reg = DOMImplementationRegistry.newInstance(); + } catch(Exception e) { + throw(new Error(e)); + } + DOMImplementation di = reg.getDOMImplementation(""); + if(di == null) + throw(new RuntimeException("Could not get a DOM implemenation")); + domimp = di; + } + + public static Document document(String ns, String root, String doctype, String pubid, String sysid) { + if(doctype == null) + return(domimp.createDocument(ns, root, null)); + else + return(domimp.createDocument(ns, root, domimp.createDocumentType(doctype, pubid, sysid))); + } + + public static Document document(String ns, String root) { + return(document(ns, root, null, null, null)); + } + + public static Element insertel(Node p, String nm) { + Document doc; + if(p instanceof Document) + doc = (Document)p; + else + doc = p.getOwnerDocument(); + Element el = doc.createElementNS(p.getNamespaceURI(), nm); + p.appendChild(el); + return(el); + } + + public static Text inserttext(Node p, String text) { + Document doc; + if(p instanceof Document) + doc = (Document)p; + else + doc = p.getOwnerDocument(); + Text t = doc.createTextNode(text); + p.appendChild(t); + return(t); + } +}