Example usage for org.dom4j.jaxb JAXBWriter writeElement

List of usage examples for org.dom4j.jaxb JAXBWriter writeElement

Introduction

In this page you can find the example usage for org.dom4j.jaxb JAXBWriter writeElement.

Prototype

public void writeElement(Element element) throws IOException 

Source Link

Document

Writes the specified org.dom4j.Element to the document.

Usage

From source file:fr.cls.atoll.motu.library.misc.xml.XMLUtils.java

License:Open Source License

/**
 * Dom4j to intput stream.//from  ww  w . java 2 s  .com
 * 
 * @param document the document
 * @param contextPath the context path
 * 
 * @return the input stream
 * 
 * @throws MotuExceptionBase the motu exception base
 */
public static InputStream dom4jToIntputStream(org.dom4j.Document document, String contextPath)
        throws MotuExceptionBase {
    ByteArrayInputStream byteArrayInputStream = null;
    try {
        Element root = document.getRootElement();
        JAXBWriter jaxbWriter = new JAXBWriter(contextPath);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        jaxbWriter.setOutput(byteArrayOutputStream);

        jaxbWriter.startDocument();
        jaxbWriter.writeElement(root);
        jaxbWriter.endDocument();

        byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    } catch (IOException e) {
        throw new MotuException("ERROR in XMLUtils#dom4jToIntputStream", e);
    } catch (SAXException e) {
        throw new MotuException("ERROR in XMLUtils#dom4jToIntputStream", e);
    }
    return byteArrayInputStream;

}