use of org.dom4j.io.OutputFormat in project plugin-compat-tester by jenkinsci.
the class MavenPom method writeDocument.
private void writeDocument(final File target, final Document doc) throws IOException {
FileWriter w = new FileWriter(target);
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter(w, format);
try {
writer.write(doc);
} finally {
writer.close();
w.close();
}
}
use of org.dom4j.io.OutputFormat in project xresloader by xresloader.
the class DataDstXml method dumpConst.
/**
* 转储常量数据
* @return 常量数据,不支持的时候返回空
*/
public final byte[] dumpConst(HashMap<String, Object> data) {
// pretty print
OutputFormat of = null;
if (ProgramOptions.getInstance().prettyIndent <= 0) {
of = OutputFormat.createCompactFormat();
} else {
of = OutputFormat.createPrettyPrint();
of.setIndentSize(ProgramOptions.getInstance().prettyIndent);
}
// build xml tree
Document doc = DocumentHelper.createDocument();
String encoding = SchemeConf.getInstance().getKey().getEncoding();
if (null != encoding && false == encoding.isEmpty()) {
doc.setXMLEncoding(encoding);
of.setEncoding(encoding);
}
doc.setRootElement(DocumentHelper.createElement(ProgramOptions.getInstance().xmlRootName));
doc.getRootElement().addComment("this file is generated by xresloader, please don't edit it.");
writeData(doc.getRootElement(), data, "");
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(bos, of);
writer.write(doc);
return bos.toByteArray();
} catch (Exception e) {
ProgramOptions.getLoger().error("write xml failed, %s", e.getMessage());
return null;
}
}
use of org.dom4j.io.OutputFormat in project syndesis by syndesisio.
the class XmlSchemaHelper method serialize.
public static String serialize(final Document document) {
try (StringWriter out = new StringWriter()) {
final OutputFormat format = new OutputFormat(null, false, "UTF-8");
format.setExpandEmptyElements(false);
format.setIndent(false);
final XMLWriter writer = new XMLWriter(out, format);
writer.write(document);
writer.flush();
return out.toString();
} catch (final IOException e) {
throw new IllegalStateException("Unable to serialize given document to XML", e);
}
}
use of org.dom4j.io.OutputFormat in project ma-core-public by infiniteautomation.
the class DOM4JConverter method convertOutbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
*/
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
try {
// Using XSLT to convert to a stream. Setup the source
if (!(data instanceof Node)) {
throw new MarshallException(data.getClass());
}
Node node = (Node) data;
OutputFormat outformat = OutputFormat.createCompactFormat();
outformat.setEncoding("UTF-8");
// Setup the destination
StringWriter xml = new StringWriter();
XMLWriter writer = new XMLWriter(xml, outformat);
writer.write(node);
writer.flush();
xml.flush();
String script = EnginePrivate.xmlStringToJavascriptDom(xml.toString());
OutboundVariable ov = new SimpleOutboundVariable(script, outctx, false);
outctx.put(data, ov);
return ov;
} catch (MarshallException ex) {
throw ex;
} catch (Exception ex) {
throw new MarshallException(data.getClass(), ex);
}
}
use of org.dom4j.io.OutputFormat in project azure-tools-for-java by Microsoft.
the class XmlUtils method prettyPrintElementNoNamespace.
public static String prettyPrintElementNoNamespace(Element node) {
removeAllNamespaces(node);
try {
final StringWriter out = new StringWriter();
final OutputFormat format = OutputFormat.createPrettyPrint();
format.setSuppressDeclaration(true);
// 4 spaces
format.setIndent(" ");
format.setPadText(false);
final XMLWriter writer = new XMLWriter(out, format);
writer.write(node);
writer.flush();
return StringUtils.stripStart(out.toString(), null);
} catch (IOException e) {
throw new RuntimeException("IOException while generating " + "textual representation: " + e.getMessage());
}
}
Aggregations