001package jmri.util.jdom; 002 003import org.jdom2.JDOMException; 004import org.jdom2.input.DOMBuilder; 005import org.jdom2.output.DOMOutputter; 006 007/** 008 * Utilities from converting between org.jdom2 objects and org.w3c.dom objects. 009 * 010 * Note that JMRI makes extensive use of org.jdom2 packages for XML DOM 011 * processing, while the JRE includes the org.w3c.dom package. 012 * 013 * @author Randall Wood 2015 014 */ 015public class JDOMUtil { 016 017 private DOMOutputter outputter = null; 018 private DOMBuilder builder = null; 019 020 private volatile static JDOMUtil defaultJDomUtil = null; 021 022 private JDOMUtil() { 023 024 } 025 026 private static JDOMUtil getDefault() { 027 if (defaultJDomUtil == null) { 028 defaultJDomUtil = new JDOMUtil(); 029 } 030 return defaultJDomUtil; 031 } 032 033 private DOMOutputter getDOMOutputter() { 034 if (this.outputter == null) { 035 this.outputter = new DOMOutputter(); 036 } 037 return this.outputter; 038 } 039 040 private DOMBuilder getDOMBuilder() { 041 if (this.builder == null) { 042 this.builder = new DOMBuilder(); 043 } 044 return this.builder; 045 } 046 047 public static final org.jdom2.Element toJDOMElement(org.w3c.dom.Element element) { 048 return getDefault().getDOMBuilder().build(element); 049 } 050 051 public static final org.w3c.dom.Element toW3CElement(org.jdom2.Element element) throws JDOMException { 052 return getDefault().getDOMOutputter().output(element); 053 } 054}