use of nu.xom.Document in project tetrad by cmu-phil.
the class GraphUtils method graphToXml.
public static String graphToXml(Graph graph) {
Document document = new Document(convertToXml(graph));
OutputStream out = new ByteArrayOutputStream();
Serializer serializer = new Serializer(out);
serializer.setLineSeparator("\n");
serializer.setIndent(2);
try {
serializer.write(document);
} catch (IOException e) {
throw new RuntimeException(e);
}
return out.toString();
}
use of nu.xom.Document in project ma-core-public by infiniteautomation.
the class XOMConverter method convertInbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
*/
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
String value = LocalUtil.decode(iv.getValue());
try {
Builder builder = new Builder();
Document doc = builder.build(new StringReader(value));
if (paramType == Document.class) {
return doc;
} else if (paramType == Element.class) {
return doc.getRootElement();
}
throw new MarshallException(paramType);
} catch (MarshallException ex) {
throw ex;
} catch (Exception ex) {
throw new MarshallException(paramType, ex);
}
}
use of nu.xom.Document in project CoreNLP by stanfordnlp.
the class CoreNLPServlet method outputPretty.
public void outputPretty(PrintWriter out, Annotation annotation) throws ServletException {
try {
Document input = XMLOutputter.annotationToDoc(annotation, pipeline);
Nodes output = corenlpTransformer.transform(input);
for (int i = 0; i < output.size(); i++) {
out.print(output.get(i).toXML());
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new ServletException(e);
}
}
use of nu.xom.Document in project timbuctoo by HuygensING.
the class ResponseCommand method verify.
@Override
public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder) {
ValidationResult validationResult;
if (!StringUtils.isBlank(verificationMethod)) {
evaluator.setVariable("#nl_knaw_huygens_httpcommand_result", requestCommand.getActualResult());
evaluator.setVariable("#nl_knaw_huygens_httpcommand_expectation", expectation);
validationResult = (ValidationResult) evaluator.evaluate(verificationMethod + "(#nl_knaw_huygens_httpcommand_expectation, #nl_knaw_huygens_httpcommand_result)");
evaluator.setVariable("#nl_knaw_huygens_httpcommand_result", null);
evaluator.setVariable("#nl_knaw_huygens_httpcommand_expectation", null);
} else {
validationResult = defaultValidator.validate(expectation, requestCommand.getActualResult());
}
Element caption = null;
if (addCaptions) {
caption = new Element("div").addAttribute("class", "responseCaption").appendText("Response:");
}
Element resultElement = replaceWithEmptyElement(commandCall.getElement(), name, namespace, caption);
addClass(resultElement, "responseContent");
try {
Builder builder = new Builder();
Document document = builder.build(new StringReader(validationResult.getMessage()));
// new Element() creates a deepcopy not attached to the doc
nu.xom.Element rootElement = new nu.xom.Element(document.getRootElement());
resultElement.appendChild(new Element(rootElement));
resultRecorder.record(validationResult.isSucceeded() ? Result.SUCCESS : Result.FAILURE);
} catch (ParsingException | IOException e) {
resultRecorder.record(Result.FAILURE);
if (e instanceof ParsingException) {
resultElement.appendText("Error at line " + ((ParsingException) e).getLineNumber() + ", column: " + ((ParsingException) e).getColumnNumber());
resultElement.appendText(validationResult.getMessage());
}
}
}
Aggregations