use of org.dom4j.io.OutputFormat in project xwiki-platform by xwiki.
the class XMLWriterTest method testBase64.
@Test
public void testBase64() throws Exception {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final OutputFormat of = new OutputFormat(" ", true, "UTF-8");
this.writer = new XMLWriter(baos, of);
this.writer.startDocument();
this.writer.writeOpen(new DOMElement("root"));
this.writer.writeOpen(new DOMElement("doc"));
this.writer.writeOpen(new DOMElement("obj"));
this.writer.writeBase64(new DOMElement("prop"), new ByteArrayInputStream(BASE64_INPUT.getBytes("UTF-8")));
this.writer.writeClose(new DOMElement("root"));
this.writer.endDocument();
Assert.assertEquals("Incorrect response from testBase64.", BASE64_TEST, new String(baos.toByteArray(), "UTF-8"));
}
use of org.dom4j.io.OutputFormat in project xwiki-platform by xwiki.
the class XMLWriterTest method testWriteClose.
/**
* Make sure writeClose closes internediet nodes.
*/
@Test
public void testWriteClose() throws Exception {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final OutputFormat of = new OutputFormat(" ", true, "UTF-8");
this.writer = new XMLWriter(baos, of);
this.writer.startDocument();
this.writer.writeOpen(new DOMElement("root"));
this.writer.writeOpen(new DOMElement("doc"));
this.writer.writeOpen(new DOMElement("obj"));
this.writer.writeOpen(new DOMElement("prop"));
this.writer.writeClose(new DOMElement("root"));
this.writer.endDocument();
Assert.assertEquals("WriteClose didn't write the correct response.", TEST_CONTENT, new String(baos.toByteArray(), "UTF-8"));
}
use of org.dom4j.io.OutputFormat in project my_curd by qinyou.
the class ToolFormatXml method formatXML.
public static String formatXML(String inputXML) {
String requestXML = null;
Document document = null;
try {
SAXReader reader = new SAXReader();
document = reader.read(new StringReader(inputXML));
} catch (DocumentException e1) {
e1.printStackTrace();
}
if (document != null) {
XMLWriter writer = null;
try {
StringWriter stringWriter = new StringWriter();
OutputFormat format = new OutputFormat(" ", true);
writer = new XMLWriter(stringWriter, format);
writer.write(document);
writer.flush();
requestXML = stringWriter.getBuffer().toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
}
}
}
}
return requestXML;
}
use of org.dom4j.io.OutputFormat in project archiva by apache.
the class XMLWriter method write.
/**
* Write the Document to the provided Writer, with an option to close the writer upon completion.
*
* @param doc the document to write.
* @param writer the writer to write to.
* @param close true to close the writer on completion.
* @throws XMLException if there was a problem writing the xml to the writer.
*/
public static void write(Document doc, Writer writer, boolean close) throws XMLException {
org.dom4j.io.XMLWriter xmlwriter = null;
try {
OutputFormat outputFormat = OutputFormat.createPrettyPrint();
xmlwriter = new org.dom4j.io.XMLWriter(writer, outputFormat);
xmlwriter.write(doc);
xmlwriter.flush();
} catch (IOException e) {
throw new XMLException("Unable to write xml contents to writer: " + e.getMessage(), e);
} finally {
if (close && (xmlwriter != null)) {
try {
xmlwriter.close();
} catch (IOException e) {
/* quietly ignore */
}
}
}
}
use of org.dom4j.io.OutputFormat in project tdq-studio-se by Talend.
the class AliasManager method saveAliases.
/**
* Saves all the Aliases to the users preferences
*/
public void saveAliases() throws ExplorerException {
DefaultElement root = new DefaultElement(Alias.ALIASES);
for (Alias alias : aliases.values()) {
root.add(alias.describeAsXml());
}
try {
FileWriter writer = new FileWriter(new File(ApplicationFiles.USER_ALIAS_FILE_NAME));
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter xmlWriter = new XMLWriter(writer, format);
xmlWriter.write(root);
writer.flush();
writer.close();
} catch (IOException e) {
throw new ExplorerException(e);
}
}
Aggregations