Search in sources :

Example 11 with Document

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(nu.xom.Document) Serializer(nu.xom.Serializer)

Example 12 with Document

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);
    }
}
Also used : MarshallException(org.directwebremoting.extend.MarshallException) Builder(nu.xom.Builder) Element(nu.xom.Element) StringReader(java.io.StringReader) Document(nu.xom.Document) MarshallException(org.directwebremoting.extend.MarshallException)

Example 13 with Document

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) Document(nu.xom.Document) Nodes(nu.xom.Nodes) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RuntimeIOException(edu.stanford.nlp.io.RuntimeIOException)

Example 14 with Document

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());
        }
    }
}
Also used : Element(org.concordion.api.Element) Utils.replaceWithEmptyElement(nl.knaw.huygens.concordion.extensions.Utils.replaceWithEmptyElement) Builder(nu.xom.Builder) ParsingException(nu.xom.ParsingException) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(nu.xom.Document)

Aggregations

Document (nu.xom.Document)14 IOException (java.io.IOException)9 Builder (nu.xom.Builder)7 Element (nu.xom.Element)7 File (java.io.File)4 ParsingException (nu.xom.ParsingException)4 BayesIm (edu.cmu.tetrad.bayes.BayesIm)3 Nodes (nu.xom.Nodes)3 Serializer (nu.xom.Serializer)3 RuntimeIOException (edu.stanford.nlp.io.RuntimeIOException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 StringReader (java.io.StringReader)2 ServletException (javax.servlet.ServletException)2 Attribute (nu.xom.Attribute)2 ParentNode (nu.xom.ParentNode)2 BayesXmlParser (edu.cmu.tetrad.bayes.BayesXmlParser)1 XdslXmlParser (edu.cmu.tetrad.search.XdslXmlParser)1 StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)1