use of javax.xml.transform.stream.StreamResult in project buck by facebook.
the class BuckXmlTestRunListener method addMainTestResult.
/**
* Adds one more XML element to the test_result.xml tracking the
* result of the whole process.
*/
private void addMainTestResult() {
try {
File resultFile = getResultFile(mReportDir);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(resultFile);
Node testsuite = doc.getElementsByTagName("testsuite").item(0);
if (mRunFailureMessage != null) {
Element failureNode = doc.createElement("failure");
failureNode.setTextContent(mRunFailureMessage);
testsuite.appendChild(failureNode);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(resultFile);
transformer.transform(source, result);
}
} catch (IOException | ParserConfigurationException | SAXException | TransformerException e) {
throw new RuntimeException(e);
}
}
use of javax.xml.transform.stream.StreamResult in project OpenAttestation by OpenAttestation.
the class ConverterUtil method formateXMLString.
public static String formateXMLString(String inputXML) {
StreamResult xmlOutput = null;
try {
Source xmlInput = new StreamSource(new StringReader(inputXML));
StringWriter stringWriter = new StringWriter();
xmlOutput = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(xmlInput, xmlOutput);
} catch (Exception e) {
// simple exception handling, please review it
throw new RuntimeException(e);
}
return xmlOutput.getWriter().toString();
}
use of javax.xml.transform.stream.StreamResult in project jersey by jersey.
the class ResourceExtendedFlagTest method printSource.
public static void printSource(Source source) {
try {
System.out.println("---------------------");
Transformer trans = TransformerFactory.newInstance().newTransformer();
Properties oprops = new Properties();
oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
oprops.put(OutputKeys.INDENT, "yes");
oprops.put(OutputKeys.METHOD, "xml");
trans.setOutputProperties(oprops);
trans.transform(source, new StreamResult(System.out));
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.xml.transform.stream.StreamResult in project jersey by jersey.
the class WadlBeanParamTest method nodeAsString.
private String nodeAsString(final Object resourceNode) throws TransformerException {
StringWriter writer = new StringWriter();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new DOMSource((Node) resourceNode), new StreamResult(writer));
return writer.toString();
}
use of javax.xml.transform.stream.StreamResult in project jersey by jersey.
the class SourceEntityProviderTest method extractContent.
private static String extractContent(Source source) throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException {
TransformerFactory transFactory = TransformerFactory.newInstance();
// identity transformation
Transformer transformer = transFactory.newTransformer();
StringWriter writer = new StringWriter();
Result result = new StreamResult(writer);
transformer.transform(source, result);
return writer.toString();
}
Aggregations