/** * Provides access to the XML answer of the call. * * @return the XML result of the call * @throws IOException in case of an IO error while receiving the result */ public XMLStructuredInput getInput() throws IOException { return new XMLStructuredInput(outcall.getInput(), true); } }
/** * Can be used to generate the XML request. * * @return the an input which can be used to generate an XML document which is sent to the URL * @throws IOException in case of an IO error while sending the XML document */ public XMLStructuredOutput getOutput() throws IOException { return new XMLStructuredOutput(outcall.getOutput()); }
/** * Creates a new XMLCall for the given url. * * @param url the target URL to call * @param contentType the Content-Type to use * @return a new instance to perform the xml call * @throws IOException in case of an IO error */ public static XMLCall to(URL url, String contentType) throws IOException { XMLCall result = new XMLCall(); result.outcall = new Outcall(url); result.outcall.setRequestProperty("Content-Type", contentType); return result; }
private void outputOwnerInfo(XMLStructuredOutput out, String name) { out.beginObject(name); out.property("ID", "initiatorId"); out.property(RESPONSE_DISPLAY_NAME, "initiatorName"); out.endObject(); }
@Override public StructuredOutput beginObject(String name, Attribute... attributes) { startObject(name, attributes); if (!nesting.isEmpty()) { nesting.get(0).setEmpty(false); } nesting.add(0, new Element(ElementType.OBJECT, name)); return this; }
private boolean nodeUp() { if (isComplete()) { nodeHandler.process(StructuredNode.of(root)); return true; } currentNode = currentNode.getParentNode(); return false; }
@Override public StructuredOutput beginArray(String name) { startArray(name); if (!nesting.isEmpty()) { nesting.get(0).setEmpty(false); } nesting.add(0, new Element(ElementType.ARRAY, name)); return this; }
@Override public StructuredOutput beginResult(String name) { return beginOutput(name); }
/** * Parses the given stream. * * @param stream the stream to parse * @throws IOException if parsing the XML fails either due to an IO error or due to an SAXException (when * processing a malformed XML). */ public void parse(InputStream stream) throws IOException { parse(stream, null); }
/** * Iterates through the sub-tree and invokes the given handler for each child node. * * @param nodeHandler the handler invoked for each child element */ public void visitNodes(Consumer<StructuredNode> nodeHandler) { visit(nodeHandler, null); }
/** * Writes the given XML document to the given writer. * * @param doc the XML document to write * @param writer the target to write the XML to * @param encoding the encoding used to write the XML * @throws javax.xml.transform.TransformerException if an exception during serialization occurs. */ public static void writeXML(Node doc, Writer writer, String encoding) throws TransformerException { writeXML(doc, writer, encoding, false); }
/** * Creates a new attribute with the given name and value. * * @param name the name of the attribute * @param value the value of the attribute * @return a new attribute with the given name and value */ public static Attribute set(String name, Object value) { return new Attribute(name, value); } }
@Override public void processingInstruction(String target, String data) throws SAXException { // Delegate to active handlers... for (SAX2DOMHandler handler : activeHandlers) { handler.processingInstruction(target, data); } }
/** * Creates a new XMLCall for the given url with Content-Type 'text/xml'. * * @param url the target URL to call * @return an <tt>XMLCall</tt> which can be used to send and receive XML * @throws IOException in case of an IO error */ public static XMLCall to(URL url) throws IOException { return to(url, "text/xml"); }
@Override public StructuredNode getNode(String xpath) throws XPathExpressionException { return node.queryNode(xpath); }
@Override public String toString() { return node == null ? "" : node.toString(); }
/** * Adds a custom header field to the call * * @param name name of the field * @param value value of the field * @return returns the XML call itself for fluent method calls */ public XMLCall addHeader(String name, String value) { outcall.setRequestProperty(name, value); return this; }
@Override public StructuredOutput beginObject(String name) { startObject(name, (Attribute[]) null); if (!nesting.isEmpty()) { nesting.get(0).setEmpty(false); } nesting.add(0, new Element(ElementType.OBJECT, name)); return this; }
@Override public StructuredOutput beginResult() { return beginOutput("result"); }
/** * Iterates through the sub-tree and invokes the given handler for each text node. * * @param textNodeHandler the handler invoked for each text node */ public void visitTexts(Consumer<Node> textNodeHandler) { visit(null, textNodeHandler); }