use of org.dom4j.dom.DOMDocument in project gocd by gocd.
the class MaterialXmlRepresenter method toXml.
@Override
public Document toXml(XmlWriterContext ctx) {
DOMElement rootElement = new DOMElement("material");
ElementBuilder builder = new ElementBuilder(rootElement);
populateMaterial(ctx, materialRevision.getMaterial(), builder);
return new DOMDocument(rootElement);
}
use of org.dom4j.dom.DOMDocument in project openolat by klemens.
the class LocalizedXSLTransformer method render.
/**
* Render with a localized stylesheet. The localized stylesheet is addressed
* by its name with appended locale. E.g. mystyle.xsl in DE locale is
* addressed by mystyle_de.xsl
*
* @param node The node to render
* @param styleSheetName The stylesheet to use.
* @return Results of XSL transformation
*/
private String render(Element node) {
try {
Document doc = node.getDocument();
if (doc == null) {
doc = new DOMDocument();
doc.add(node);
}
DocumentSource xmlsource = new DocumentSource(node);
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
templates.newTransformer().transform(xmlsource, result);
return sw.toString();
} catch (Exception e) {
throw new OLATRuntimeException(LocalizedXSLTransformer.class, "Error transforming XML.", e);
}
}
use of org.dom4j.dom.DOMDocument in project OpenOLAT by OpenOLAT.
the class LocalizedXSLTransformer method render.
/**
* Render with a localized stylesheet. The localized stylesheet is addressed
* by its name with appended locale. E.g. mystyle.xsl in DE locale is
* addressed by mystyle_de.xsl
*
* @param node The node to render
* @param styleSheetName The stylesheet to use.
* @return Results of XSL transformation
*/
private String render(Element node) {
try {
Document doc = node.getDocument();
if (doc == null) {
doc = new DOMDocument();
doc.add(node);
}
DocumentSource xmlsource = new DocumentSource(node);
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
templates.newTransformer().transform(xmlsource, result);
return sw.toString();
} catch (Exception e) {
throw new OLATRuntimeException(LocalizedXSLTransformer.class, "Error transforming XML.", e);
}
}
use of org.dom4j.dom.DOMDocument in project xwiki-platform by xwiki.
the class XWikiDocument method toXMLDocument.
/**
* Serialize the document to an XML {@link DOMDocument}. You should prefer
* {@link #toXML(OutputStream, boolean, boolean, boolean, boolean, XWikiContext)} or
* {@link #toXML(com.xpn.xwiki.internal.xml.XMLWriter, boolean, boolean, boolean, boolean, XWikiContext)} when
* possible to reduce memory load.
*
* @param bWithObjects include XObjects
* @param bWithRendering include the rendered content
* @param bWithAttachmentContent include attachments content
* @param bWithVersions include archived versions
* @param context current XWikiContext
* @return a {@link DOMDocument} containing the serialized document.
* @throws XWikiException when an errors occurs during wiki operations
* @deprecated since 9.0RC1, use {@link #toXML(OutputTarget, boolean, boolean, boolean, boolean, boolean, String)}
* instead
*/
@Deprecated
public Document toXMLDocument(boolean bWithObjects, boolean bWithRendering, boolean bWithAttachmentContent, boolean bWithVersions, XWikiContext context) throws XWikiException {
Document doc = new DOMDocument();
DOMXMLWriter wr = new DOMXMLWriter(doc, new OutputFormat("", true, context.getWiki().getEncoding()));
try {
toXML(wr, bWithObjects, bWithRendering, bWithAttachmentContent, bWithVersions, context);
return doc;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.dom4j.dom.DOMDocument in project narayana by jbosstm.
the class XMLResultsServlet method doStatus.
public void doStatus(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
HttpSession session = request.getSession();
final FullTestResult testResult = (FullTestResult) session.getAttribute(TestConstants.ATTRIBUTE_TEST_RESULT);
DOMDocument report = new DOMDocument();
DOMElement testsuite = new DOMElement("testsuite");
report.setRootElement(testsuite);
if (testResult == null) {
// No JUnit test results generated.
} else {
List passedTests = testResult.getPassedTests();
List failedTests = testResult.getFailedTests();
List errorTests = testResult.getErrorTests();
final int runCount = testResult.runCount();
final int errorCount = testResult.errorCount();
final int failureCount = testResult.failureCount();
testsuite.addAttribute("name", "com.jboss.transaction.wstf.interop.InteropTestSuite");
testsuite.addAttribute("errors", Integer.toString(errorCount));
testsuite.addAttribute("failures", Integer.toString(failureCount));
testsuite.addAttribute("hostname", request.getServerName());
testsuite.addAttribute("tests", Integer.toString(runCount));
testsuite.addAttribute("timestamp", new Date().toString());
DOMElement properties = new DOMElement("properties");
testsuite.add(properties);
DOMElement status = newPropertyDOMElement("status");
properties.add(status);
status.addAttribute("value", "finished");
long totalDuration = 0;
if (!passedTests.isEmpty()) {
Iterator passedTestsIterator = passedTests.iterator();
while (passedTestsIterator.hasNext()) {
FullTestResult.PassedTest passedTest = (FullTestResult.PassedTest) passedTestsIterator.next();
totalDuration += passedTest.duration;
final String name = passedTest.test.toString();
final String description = (String) TestConstants.DESCRIPTIONS.get(name);
testsuite.add(newTestcase(passedTest.test.getClass().getName(), name + ": " + description, passedTest.duration));
}
}
if (!failedTests.isEmpty()) {
Iterator failedTestsIterator = failedTests.iterator();
while (failedTestsIterator.hasNext()) {
FullTestResult.FailedTest failedTest = (FullTestResult.FailedTest) failedTestsIterator.next();
totalDuration += failedTest.duration;
final String name = failedTest.test.toString();
final String description = (String) TestConstants.DESCRIPTIONS.get(name);
CharArrayWriter charArrayWriter = new CharArrayWriter();
PrintWriter printWriter = new PrintWriter(charArrayWriter, true);
failedTest.assertionFailedError.printStackTrace(printWriter);
printWriter.close();
charArrayWriter.close();
testsuite.add(newFailedTestcase(failedTest.test.getClass().getName(), name + ": " + description, failedTest.duration, failedTest.assertionFailedError.getMessage(), charArrayWriter.toString()));
}
}
if (!errorTests.isEmpty()) {
Iterator errorTestsIterator = errorTests.iterator();
while (errorTestsIterator.hasNext()) {
FullTestResult.ErrorTest errorTest = (FullTestResult.ErrorTest) errorTestsIterator.next();
totalDuration += errorTest.duration;
final String name = errorTest.test.toString();
final String description = (String) TestConstants.DESCRIPTIONS.get(name);
CharArrayWriter charArrayWriter = new CharArrayWriter();
PrintWriter printWriter = new PrintWriter(charArrayWriter, true);
errorTest.throwable.printStackTrace(printWriter);
printWriter.close();
charArrayWriter.close();
System.out.println("charArrayWriter.toString()=" + charArrayWriter.toString());
testsuite.add(newErrorTestcase(errorTest.test.getClass().getName(), name + ": " + description, errorTest.duration, errorTest.throwable.getMessage(), charArrayWriter.toString()));
}
}
// total time of all tests
testsuite.addAttribute("time", Float.toString(totalDuration / 1000f));
}
String logContent = null;
final String logName = (String) session.getAttribute(TestConstants.ATTRIBUTE_LOG_NAME);
if (logName != null) {
try {
logContent = TestLogController.readLog(logName);
} catch (final Throwable th) {
log("Error reading log file", th);
}
}
testsuite.add(new DOMElement("system-out").addCDATA((logContent != null) ? logContent : ""));
testsuite.add(new DOMElement("system-err").addCDATA(""));
XMLWriter outputter = new XMLWriter(response.getWriter(), OutputFormat.createPrettyPrint());
try {
outputter.write(testsuite);
outputter.close();
} catch (IOException e) {
throw new ServletException(e);
}
}
Aggregations