Mercurial > dive4elements > framework
diff artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java @ 20:ff666592c1c3
Added factory listing '/factories' to web app.
artifacts/trunk@51 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 09 Sep 2009 14:33:25 +0000 |
parents | |
children | 00596a591a2f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java Wed Sep 09 14:33:25 2009 +0000 @@ -0,0 +1,62 @@ +package de.intevation.artifactdatabase; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Attr; + +import javax.xml.parsers.DocumentBuilderFactory; + +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.log4j.Logger; + +/** + * @author Sascha L. Teichmann + */ +public final class XMLUtils +{ + private static Logger logger = Logger.getLogger(XMLUtils.class); + + private XMLUtils() { + } + + public static class ElementCreator + { + protected Document document; + protected String ns; + protected String prefix; + + public ElementCreator(Document document, String ns, String prefix) { + this.document = document; + this.ns = ns; + this.prefix = prefix; + } + + public Element create(String name) { + Element element = document.createElementNS(ns, name); + element.setPrefix(prefix); + return element; + } + + public void addAttr(Element element, String name, String value) { + Attr attr = document.createAttributeNS(ns, name); + attr.setValue(value); + attr.setPrefix(prefix); + element.setAttributeNode(attr); + } + } // class ElementCreator + + public static final Document newDocument() { + try { + return DocumentBuilderFactory + .newInstance() + .newDocumentBuilder() + .newDocument(); + } + catch (ParserConfigurationException pce) { + logger.error(pce.getLocalizedMessage(), pce); + } + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: