use of org.exist.dom.memtree.MemTreeBuilder in project exist by eXist-db.
the class Execute method createReport.
private ElementImpl createReport(int exitValue, List<String> output, List<String> cmdArgs) {
context.pushDocumentContext();
try {
MemTreeBuilder builder = context.getDocumentBuilder();
AttributesImpl attribs = new AttributesImpl();
attribs.addAttribute("", "exitCode", "exitCode", "CDATA", Integer.toString(exitValue));
builder.startDocument();
int nodeNr = builder.startElement(RESULT_QNAME, attribs);
// print command line
StringBuilder cmdLine = new StringBuilder();
for (String param : cmdArgs) {
cmdLine.append(param).append(' ');
}
builder.startElement(COMMAND_LINE_QNAME, null);
builder.characters(cmdLine.toString());
builder.endElement();
// print received output to <stdout>
builder.startElement(STDOUT_QNAME, null);
for (String line : output) {
builder.startElement(LINE_QNAME, null);
builder.characters(line);
builder.endElement();
}
builder.endElement();
builder.endElement();
return (ElementImpl) builder.getDocument().getNode(nodeNr);
} finally {
context.popDocumentContext();
}
}
use of org.exist.dom.memtree.MemTreeBuilder in project exist by eXist-db.
the class JSON method toxml.
private Sequence toxml(Sequence json, String handleDuplicates, JsonFactory factory) throws XPathException {
if (json.isEmpty()) {
return Sequence.EMPTY_SEQUENCE;
}
try (final JsonParser parser = factory.createParser(json.itemAt(0).getStringValue())) {
context.pushDocumentContext();
final MemTreeBuilder builder = context.getDocumentBuilder();
builder.startDocument();
factory.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, false);
jsonToXml(builder, parser);
return builder.getDocument() == null ? Sequence.EMPTY_SEQUENCE : builder.getDocument();
} catch (IOException e) {
throw new XPathException(this, ErrorCodes.FOJS0001, e.getMessage());
} catch (XPathException e) {
e.setLocation(getLine(), getColumn(), getSource());
throw e;
} finally {
context.popDocumentContext();
}
}
use of org.exist.dom.memtree.MemTreeBuilder in project exist by eXist-db.
the class ParsingFunctions method parse.
private Sequence parse(final String xmlContent, final Sequence[] args) throws XPathException {
final SAXAdapter adapter = new FragmentSAXAdapter(context, isCalledAs("parse-xml-fragment"));
final ValidationReport report = validate(xmlContent, adapter);
if (report.isValid()) {
return adapter.getDocument();
} else {
try {
context.pushDocumentContext();
final MemTreeBuilder builder = context.getDocumentBuilder();
final NodeImpl result = Shared.writeReport(report, builder);
throw new XPathException(this, ErrorCodes.FODC0006, ErrorCodes.FODC0006.getDescription() + ": " + report.toString(), result);
} finally {
context.popDocumentContext();
}
}
}
use of org.exist.dom.memtree.MemTreeBuilder in project exist by eXist-db.
the class InspectFunction method eval.
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
final FunctionReference ref = (FunctionReference) args[0].itemAt(0);
final FunctionSignature sig = ref.getSignature();
try {
context.pushDocumentContext();
final MemTreeBuilder builder = context.getDocumentBuilder();
final int nodeNr = InspectFunctionHelper.generateDocs(sig, null, builder);
return builder.getDocument().getNode(nodeNr);
} finally {
context.popDocumentContext();
}
}
use of org.exist.dom.memtree.MemTreeBuilder in project exist by eXist-db.
the class IntersectTest method createInMemoryDocument.
private Document createInMemoryDocument() {
final MemTreeBuilder memtree = new MemTreeBuilder();
memtree.startDocument();
memtree.startElement(new QName("m1", XMLConstants.NULL_NS_URI), null);
memtree.startElement(new QName("m2", XMLConstants.NULL_NS_URI), null);
memtree.characters("test data");
memtree.endElement();
memtree.endElement();
memtree.endDocument();
return memtree.getDocument();
}
Aggregations