use of org.dom4j.io.OutputFormat in project core by craftercms.
the class CrafterXStreamMarshaller method marshalWriter.
/**
* Just as super(), but instead of a {@link com.thoughtworks.xstream.io.xml.CompactWriter} creates a {@link
* EscapingCompactWriter}.
* Also if the object graph is a Dom4j document, the document is written directly instead of using XStream.
*/
@Override
public void marshalWriter(Object graph, Writer writer, DataHolder dataHolder) throws XmlMappingException, IOException {
if (graph instanceof Document) {
OutputFormat outputFormat = OutputFormat.createCompactFormat();
outputFormat.setSuppressDeclaration(suppressXmlDeclaration);
XMLWriter xmlWriter = new XMLWriter(writer, outputFormat);
try {
xmlWriter.write((Document) graph);
} finally {
try {
xmlWriter.flush();
} catch (Exception ex) {
logger.debug("Could not flush XMLWriter", ex);
}
}
} else {
if (!suppressXmlDeclaration) {
writer.write(XML_DECLARATION);
}
HierarchicalStreamWriter streamWriter = new EscapingCompactWriter(writer);
try {
getXStream().marshal(graph, streamWriter, dataHolder);
} catch (Exception ex) {
throw convertXStreamException(ex, true);
} finally {
try {
streamWriter.flush();
} catch (Exception ex) {
logger.debug("Could not flush HierarchicalStreamWriter", ex);
}
}
}
}
use of org.dom4j.io.OutputFormat in project atlas by alibaba.
the class XmlHelper method saveDocument.
public static void saveDocument(Document document, File file) throws IOException {
file.getParentFile().mkdirs();
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
saveFile(document, format, file);
}
use of org.dom4j.io.OutputFormat in project zm-mailbox by Zimbra.
the class DavResource method getPropertiesAsText.
protected String getPropertiesAsText(DavContext ctxt) throws IOException {
Element e = org.dom4j.DocumentHelper.createElement(DavElements.E_PROP);
for (ResourceProperty rp : mProps.values()) rp.toElement(ctxt, e, false);
OutputFormat format = OutputFormat.createPrettyPrint();
format.setTrimText(false);
format.setOmitEncoding(false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(baos, format);
writer.write(e);
return new String(baos.toByteArray());
}
use of org.dom4j.io.OutputFormat in project zm-mailbox by Zimbra.
the class DomUtil method writeDocumentToStream.
public static void writeDocumentToStream(Document doc, OutputStream out) throws IOException {
OutputFormat format = OutputFormat.createPrettyPrint();
format.setTrimText(false);
format.setOmitEncoding(false);
XMLWriter writer = new XMLWriter(out, format);
writer.write(doc);
}
use of org.dom4j.io.OutputFormat in project zm-mailbox by Zimbra.
the class DomUtil method toString.
/**
* Convert an Element to a String.
*/
public static String toString(Element env, boolean prettyPrint) {
if (prettyPrint) {
StringWriter buff = new StringWriter();
try {
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter(buff, format);
writer.write(env);
writer.close();
} catch (IOException e) {
// ignore, since StringWriter doesn't throw IOExceptions
}
return buff.toString();
} else {
return env.asXML();
}
}
Aggregations