package demo.transformers;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.output.DOMOutputter;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class XmlUtils {
	private static Log logger = LogFactory.getLog(XmlUtils.class);

	public static org.w3c.dom.Document convertJdomToDom(Document doc) {
		DOMOutputter domOut = new DOMOutputter();

		org.w3c.dom.Document domDoc = null;
		try {
			domDoc = domOut.output(doc);
			logger.info("XmlUtils: converted JDOM Document to DOM");
		} catch (JDOMException e) {
			logger.warn("caught exception converting to JDOM document to DOM", e);
		}
		
		return domDoc;
	}

	public static String convertJdomToString(Document doc) {
		XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
		return xmlOut.outputString(doc);
	}

}
