final DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder;
try {
docBuilder = dbfac.newDocumentBuilder();
} catch (final ParserConfigurationException e) {
throw new JournalException(e.getMessage(), e);
}
final Document doc = docBuilder.newDocument();
final Branch rootBranch = getDaoFacade().getBranchDAO().read(ROOT_ID);
final Element rootElement = doc.createElement(TAG_JOURNAL);
doc.appendChild(rootElement);
getXmlHelper().convertNodeToXml(doc, rootElement, rootBranch);
try {
synchronized (lock) {
final TransformerFactory locTransFactory = getTransformFactory();
locTransFactory.setAttribute(INDENT_NO, INDENT_SIZE);
final Transformer trans = locTransFactory.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, NO);
trans.setOutputProperty(OutputKeys.INDENT, YES);
trans.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(targetStream, "UTF-8")));
}
} catch (final TransformerException e) {
throw new JournalException(e.getMessage(), e);
} catch (final UnsupportedEncodingException e) {
throw new JournalException(e.getMessage(), e);
}
}